b980d59d
 
  孙向锦
 
修改模板
 | 
1
2 
 | 
  package com.fh.controller.api;
  
 
 | 
ce70231e
 
  孙向锦
 
增加接口
 | 
3
4
5
6
7 
 | 
  import java.lang.reflect.ParameterizedType;
  import java.lang.reflect.Type;
  import java.util.List;
  
  import com.fh.bean.Point;
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
8 
 | 
  import com.google.gson.Gson;
 
 | 
ce70231e
 
  孙向锦
 
增加接口
 | 
9
10 
 | 
  import com.google.gson.GsonBuilder;
  import com.google.gson.reflect.TypeToken;
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
11
12
13
14
15
16
17 
 | 
  
  public class ResponseGson<T> {
  
  	private String code = "0";
  
  	private String message = "success";
  
 
 | 
ce70231e
 
  孙向锦
 
增加接口
 | 
18 
 | 
  	private T data;
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 
 | 
  
  	public String getCode() {
  		return code;
  	}
  
  	public void setCode(String code) {
  		this.code = code;
  	}
  
  	public String getMessage() {
  		return message;
  	}
  
  	public void setMessage(String message) {
  		this.message = message;
  	}
  
 
 | 
ce70231e
 
  孙向锦
 
增加接口
 | 
36 
 | 
  	public T getData() {
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
37
38
39
40
41
42
43
44 
 | 
  		return data;
  	}
  
  	public void setData(T data) {
  		this.data = data;
  	}
  	
  	public String toJson(){
 
 | 
ce70231e
 
  孙向锦
 
增加接口
 | 
45 
 | 
  		Gson gson =  new GsonBuilder().serializeNulls().create(); 
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
46 
 | 
  		return gson.toJson(this);
 
 | 
2ad7ca45
 
  孙向锦
 
试卷bug修改
 | 
47
48
49
50
51 
 | 
  	}
  	
  	public String toBrifJson(){
  		Gson gson =  new Gson(); 
  		return gson.toJson(this);
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
52
53
54
55
56
57
58
59 
 | 
  	}
  
  	@Override
  	public String toString() {
  		return "ResponseGson [code=" + code + ", message=" + message
  				+ ", data=" + data + "]";
  	}
  	
 
 | 
ce70231e
 
  孙向锦
 
增加接口
 | 
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 
 | 
  	public static <T> ResponseGson<T> parse(String json) {
  		Gson gson = new Gson();
  		Type objectType = new TypeToken<ResponseGson<T>>() {}.getType();  
  		return gson.fromJson(json, objectType);
  	}
  	
  	public static <T> ResponseGson<T> parse(String json,Class clazz) {
  		Gson gson = new Gson();
  		if(clazz == Point.class){
  			Type objectType = new TypeToken<ResponseGson<List<Point>>>() {}.getType();  
  			return gson.fromJson(json, objectType);
  		}
  		return null;
  	}
  	
  	
  	
  	 static ParameterizedType type(final Class raw, final Type... args) {
  	        return new ParameterizedType() {
  	            public Type getRawType() {
  	                return raw;
  	            }
  
  	            public Type[] getActualTypeArguments() {
  	                return args;
  	            }
  
  	            public Type getOwnerType() {
  	                return null;
  	            }
  	        };
  	    }
  	
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
93
94
95
96
97
98
99
100
101
102
103 
 | 
  	
  	public void setSuccess(){
  		code = "0" ;
  		message = "success" ;
  	}
  	
  	public void setNetError(){
  		code = "-1" ;
  		message = "net error" ;
  	}
  	
 
 | 
7db3ebeb
 
  孙向锦
 
添加一些模块
 | 
104 
 | 
  	public void setPathError(){
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
105 
 | 
  		code = "-2" ;
 
 | 
7db3ebeb
 
  孙向锦
 
添加一些模块
 | 
106
107
108
109
110 
 | 
  		message = "Path error" ;
  	}
  	
  	public void setDataError(){
  		code = "-3" ;
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
111
112 
 | 
  		message = "Data error" ;
  	}
 
 | 
7db3ebeb
 
  孙向锦
 
添加一些模块
 | 
113
114
115
116
117
118
119
120
121 
 | 
  	public void setParmError(){
  		code = "-4" ;
  		message = "Parm error" ;
  	}
  	public void setError(){
  		code = "-5" ;
  		message = "server error" ;
  	}
  	
 
 | 
bed6e1fc
 
  孙向锦
 
添加其他功能
 | 
122
123
124
125
126 
 | 
  	public void setOtherError(){
  		code = "-6" ;
  		message = "未定义,需补充" ;
  	}
  	
 
 | 
7db3ebeb
 
  孙向锦
 
添加一些模块
 | 
127
128 
 | 
  	public void set1Error(){
  		code = "1" ;
 
 | 
bed6e1fc
 
  孙向锦
 
添加其他功能
 | 
129 
 | 
  		message = "登录失败,用户名或者密码错误" ;
 
 | 
7db3ebeb
 
  孙向锦
 
添加一些模块
 | 
130
131
132
133 
 | 
  	}
  	
  	public void set2Error(){
  		code = "2" ;
 
 | 
bed6e1fc
 
  孙向锦
 
添加其他功能
 | 
134 
 | 
  		message = "没有找到对应的班级信息" ;
 
 | 
7db3ebeb
 
  孙向锦
 
添加一些模块
 | 
135
136
137
138
139
140
141
142
143
144
145
146 
 | 
  	}
  	
  	public void set3Error(){
  		code = "3" ;
  		message = "分别对错误进行描述,1 具体到某个参数值问题的描述" ;
  	}
  	
  	public void set4Error(){
  		code = "4" ;
  		message = "分别对错误进行描述,1 具体到某个参数值问题的描述" ;
  	}
  	
 
 | 
ed19bdb6
 
  孙向锦
 
修改密码逻辑
 | 
147
148
149
150 
 | 
  	public void set5Error(){
  		code = "5" ;
  		message = "原密码输入错误!";
  	}
 
 | 
7db3ebeb
 
  孙向锦
 
添加一些模块
 | 
151 
 | 
  	
 
 | 
b980d59d
 
  孙向锦
 
修改模板
 | 
152 
 | 
  }
 
 |