Skip to content

Commit c56c30a

Browse files
committed
替换默认的jackson为fastjson
1 parent 6c1cde0 commit c56c30a

File tree

3 files changed

+33
-50
lines changed

3 files changed

+33
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package seed.config;
2+
3+
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.http.converter.HttpMessageConverter;
7+
8+
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
9+
10+
/**
11+
* 配置fastjson替换jackson
12+
*
13+
* @author 马兆永
14+
*/
15+
@Configuration
16+
public class FastJSONConfig {
17+
18+
@Bean
19+
public HttpMessageConverters customConverters() {
20+
HttpMessageConverter<?> additional = new FastJsonHttpMessageConverter();
21+
return new HttpMessageConverters(additional);
22+
}
23+
24+
}

src/main/java/seed/core/model/BaseModel.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package seed.core.model;
22

3-
import com.fasterxml.jackson.annotation.JsonFormat;
4-
import org.springframework.format.annotation.DateTimeFormat;
3+
import java.util.Date;
54

65
import javax.persistence.Id;
76
import javax.persistence.MappedSuperclass;
8-
import java.util.Date;
7+
8+
import com.alibaba.fastjson.annotation.JSONField;
99

1010
/**
1111
* 模型的基础类
@@ -26,8 +26,7 @@ public abstract class BaseModel implements IBaseModel{
2626
/**
2727
* 时间戳
2828
*/
29-
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
30-
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
29+
@JSONField(format="yyyy-MM-dd HH:mm:ss")
3130
private Date ts;
3231
/**
3332
*

src/main/java/seed/demo/models/User.java

+5-45
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
package seed.demo.models;
22

3-
import java.util.Date;
4-
53
import javax.persistence.Entity;
6-
import javax.persistence.Id;
74
import javax.persistence.Table;
85

9-
import org.springframework.format.annotation.DateTimeFormat;
10-
11-
import com.fasterxml.jackson.annotation.JsonFormat;
12-
13-
import seed.core.model.IBaseModel;
6+
import seed.core.model.BaseModel;
147

158
/**
169
* 用户数据模型
@@ -20,11 +13,11 @@
2013
**/
2114
@Entity
2215
@Table(name="sm_user")
23-
public class User implements IBaseModel {
24-
@Id
25-
private String id;
16+
public class User extends BaseModel {
17+
18+
private static final long serialVersionUID = 1657158559598921654L;
2619

27-
private String code;
20+
private String code;
2821

2922
private String name;
3023

@@ -44,25 +37,11 @@ public class User implements IBaseModel {
4437

4538
private String memo;
4639

47-
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
48-
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
49-
private Date ts;
50-
51-
private Short dr;
5240

5341
public User() {
5442

5543
}
5644

57-
@Override
58-
public String getId() {
59-
return id;
60-
}
61-
62-
public void setId(String id) {
63-
this.id = id;
64-
}
65-
6645
public String getCode() {
6746
return code;
6847
}
@@ -143,23 +122,4 @@ public void setMemo(String memo) {
143122
this.memo = memo;
144123
}
145124

146-
@Override
147-
public Date getTs() {
148-
return ts;
149-
}
150-
151-
@Override
152-
public void setTs(Date ts) {
153-
this.ts = ts;
154-
}
155-
156-
@Override
157-
public Short getDr() {
158-
return dr;
159-
}
160-
161-
@Override
162-
public void setDr(Short dr) {
163-
this.dr = dr;
164-
}
165125
}

0 commit comments

Comments
 (0)