Skip to content

Commit 7035bd5

Browse files
committed
axios added for Http methods
1 parent fcafe91 commit 7035bd5

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.github.jeemv.springboot.vuejs.beans;
2+
3+
public class RawObject {
4+
private Object value;
5+
6+
public RawObject(Object value) {
7+
this.value = value;
8+
}
9+
10+
@Override
11+
public String toString() {
12+
return value+"";
13+
}
14+
15+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.github.jeemv.springboot.vuejs.serializers;
2+
3+
import java.io.IOException;
4+
5+
import com.fasterxml.jackson.core.JsonGenerator;
6+
import com.fasterxml.jackson.databind.SerializerProvider;
7+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
8+
9+
import io.github.jeemv.springboot.vuejs.beans.RawObject;
10+
11+
public class RawObjectSerializer extends StdSerializer<RawObject> {
12+
13+
/**
14+
*
15+
*/
16+
private static final long serialVersionUID = 1L;
17+
18+
public RawObjectSerializer() {
19+
this(null);
20+
}
21+
22+
protected RawObjectSerializer(Class<RawObject> t) {
23+
super(t);
24+
}
25+
26+
@Override
27+
public void serialize(RawObject value, JsonGenerator gen, SerializerProvider provider) throws IOException {
28+
gen.writeRawValue(value+"");
29+
}
30+
31+
32+
}

src/main/java/io/github/jeemv/springboot/vuejs/utilities/Http.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@
55
/**
66
* Http class for Http requests
77
* @author jcheron
8-
* @version 1.0.1
8+
* @version 1.0.2
99
*/
1010
public class Http {
1111

12+
private static boolean useAxios=false;
13+
14+
public static void useAxios() {
15+
useAxios=true;
16+
}
17+
18+
private static String getJsCode() {
19+
if(useAxios) {
20+
useAxios=false;
21+
return "Vue.prototype.$http = axios;";
22+
}
23+
return "";
24+
}
1225
public static String submitForm(String formRef,String action,String successCallback,String errorCallback) {
13-
String result= "let form=this.$refs['"+formRef+"'];"+
26+
String result= getJsCode()+"let form=this.$refs['"+formRef+"'];"+
1427
"let formData=form.model;"+request("form.$vnode.data.attrs.method.toLowerCase()", action, "formData", successCallback,errorCallback);
1528
return result;
1629
}
@@ -44,7 +57,7 @@ public static String request(String method,String url,Object data,String success
4457
if(!"".equals(errorCallback) && errorCallback!=null) {
4558
error=",function(response) {"+errorCallback+"}";
4659
}
47-
String result= "this.$http["+method+"]("+url+", "+data+")" +
60+
String result=getJsCode()+"this.$http["+method+"]("+url+", "+data+")" +
4861
".then(function(response){"+successCallback+"}"+error+");";
4962
return result;
5063
}

src/main/java/io/github/jeemv/springboot/vuejs/utilities/JsUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import io.github.jeemv.springboot.vuejs.VueConfig;
1515
import io.github.jeemv.springboot.vuejs.VueJS;
16+
import io.github.jeemv.springboot.vuejs.beans.RawObject;
1617
import io.github.jeemv.springboot.vuejs.components.VueComponent;
1718
import io.github.jeemv.springboot.vuejs.components.VueProp;
1819
import io.github.jeemv.springboot.vuejs.parts.VueComputed;
@@ -28,6 +29,7 @@
2829
import io.github.jeemv.springboot.vuejs.serializers.MethodsSerializer;
2930
import io.github.jeemv.springboot.vuejs.serializers.PropSerializer;
3031
import io.github.jeemv.springboot.vuejs.serializers.PropsSerializer;
32+
import io.github.jeemv.springboot.vuejs.serializers.RawObjectSerializer;
3133
import io.github.jeemv.springboot.vuejs.serializers.VueComponentSerializer;
3234
import io.github.jeemv.springboot.vuejs.serializers.VueJSSerializer;
3335
import io.github.jeemv.springboot.vuejs.serializers.WatcherSerializer;
@@ -36,6 +38,7 @@
3638
public class JsUtils {
3739
public static String objectToJSON(Object o) throws JsonProcessingException {
3840
ObjectMapper objectMapper = new ObjectMapper();
41+
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
3942
SimpleModule module = new SimpleModule();
4043
module.addSerializer(VueJS.class, new VueJSSerializer());
4144
module.addSerializer(VueComponent.class, new VueComponentSerializer());
@@ -47,6 +50,7 @@ public static String objectToJSON(Object o) throws JsonProcessingException {
4750
module.addSerializer(VueWatcher.class, new WatcherSerializer());
4851
module.addSerializer(VueProp.class, new PropSerializer());
4952
module.addSerializer(VueProps.class, new PropsSerializer());
53+
module.addSerializer(RawObject.class, new RawObjectSerializer());
5054
objectMapper.registerModule(module);
5155
if(VueConfig.debug) {
5256
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);

0 commit comments

Comments
 (0)