Skip to content

Commit 64b62e9

Browse files
committed
Java:APIJSONBoot 和 APIJSONFinal 登录接口兼容 MySQL 5.6 及以下等不支持 json 类型的数据库
1 parent 8b8c589 commit 64b62e9

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoController.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,12 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
596596

597597
response = new JSONResponse(
598598
new DemoParser(GETS, false).parseResponse(
599-
new JSONRequest(new User(userId)).setFormat(true)
599+
new JSONRequest( // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库
600+
USER_, // User 里在 setContactIdList(List<Long>) 后加 setContactIdList(String) 没用
601+
new apijson.JSONObject( // fastjson 查到一个就不继续了,所以只能加到前面或者只有这一个,但这样反过来不兼容 5.7+
602+
new User(userId) // 所以就用 @json 来强制转为 JSONArray,保证有效
603+
).setJson("contactIdList,pictureList")
604+
).setFormat(true)
600605
)
601606
);
602607
User user = response.getObject(User.class);

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/demo/model/User.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.List;
2121

22-
import apijson.JSON;
2322
import apijson.MethodAccess;
2423
import apijson.framework.BaseModel;
2524
import apijson.orm.Visitor;
@@ -63,31 +62,30 @@ public User setSex(Integer sex) {
6362
this.sex = sex;
6463
return this;
6564
}
65+
6666
public String getHead() {
6767
return head;
6868
}
6969
public User setHead(String head) {
7070
this.head = head;
7171
return this;
7272
}
73+
7374
public String getName() {
7475
return name;
7576
}
7677
public User setName(String name) {
7778
this.name = name;
7879
return this;
7980
}
81+
8082
public List<String> getPictureList() {
8183
return pictureList;
8284
}
8385
public User setPictureList(List<String> pictureList) {
8486
this.pictureList = pictureList;
8587
return this;
8688
}
87-
public User setPictureList(String pictureList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库
88-
this.pictureList = JSON.parseArray(pictureList, String.class);
89-
return this;
90-
}
9189

9290
public String getTag() {
9391
return tag;
@@ -104,10 +102,5 @@ public User setContactIdList(List<Long> contactIdList) {
104102
this.contactIdList = contactIdList;
105103
return this;
106104
}
107-
public User setContactIdList(String contactIdList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库
108-
this.contactIdList = JSON.parseArray(contactIdList, Long.class);
109-
return this;
110-
}
111-
112105

113106
}

APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/model/User.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.List;
2121

22-
import apijson.JSON;
2322
import apijson.MethodAccess;
2423
import apijson.framework.BaseModel;
2524
import apijson.orm.Visitor;
@@ -63,31 +62,30 @@ public User setSex(Integer sex) {
6362
this.sex = sex;
6463
return this;
6564
}
65+
6666
public String getHead() {
6767
return head;
6868
}
6969
public User setHead(String head) {
7070
this.head = head;
7171
return this;
7272
}
73+
7374
public String getName() {
7475
return name;
7576
}
7677
public User setName(String name) {
7778
this.name = name;
7879
return this;
7980
}
81+
8082
public List<String> getPictureList() {
8183
return pictureList;
8284
}
8385
public User setPictureList(List<String> pictureList) {
8486
this.pictureList = pictureList;
8587
return this;
8688
}
87-
public User setPictureList(String pictureList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库
88-
this.pictureList = JSON.parseArray(pictureList, String.class);
89-
return this;
90-
}
9189

9290
public String getTag() {
9391
return tag;
@@ -104,10 +102,5 @@ public User setContactIdList(List<Long> contactIdList) {
104102
this.contactIdList = contactIdList;
105103
return this;
106104
}
107-
public User setContactIdList(String contactIdList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库
108-
this.contactIdList = JSON.parseArray(contactIdList, Long.class);
109-
return this;
110-
}
111-
112105

113106
}

APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/jfinal/DemoController.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,12 @@ public void login() {
549549

550550
response = new JSONResponse(
551551
new DemoParser(GETS, false).parseResponse(
552-
new JSONRequest(new User(userId)).setFormat(true)
552+
new JSONRequest( // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库
553+
USER_, // User 里在 setContactIdList(List<Long>) 后加 setContactIdList(String) 没用
554+
new apijson.JSONObject( // fastjson 查到一个就不继续了,所以只能加到前面或者只有这一个,但这样反过来不兼容 5.7+
555+
new User(userId) // 所以就用 @json 来强制转为 JSONArray,保证有效
556+
).setJson("contactIdList,pictureList")
557+
).setFormat(true)
553558
)
554559
);
555560
User user = response.getObject(User.class);

0 commit comments

Comments
 (0)