GeezerVison is showing github.com — Java:APIJSONBoot 和 APIJSONFinal 登录接口兼容 MySQL 5.6 及以下等不支持 json 类型的数据库 · ljxpall/APIJSON-Demo@64b62e9
File treeExpand file treeCollapse file tree Open diff view settings APIJSONBoot/src/main/java/apijson APIJSONFinal/src/main/java/apijson
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoController.java +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -596,7 +596,12 @@ public JSONObject login(@RequestBody String request, HttpSession session) { | 596 | 596 |
| 597 | 597 | response = new JSONResponse( | 598 | 598 | 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) | 600 | 605 | ) | 601 | 606 | ); | 602 | 607 | User user = response.getObject(User.class); | |
Collapse file Copy file name to clipboardExpand all lines: APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/demo/model/User.java +3-10Lines changed: 3 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 |
| 20 | 20 | import java.util.List; | 21 | 21 |
| 22 | | -import apijson.JSON; | 23 | 22 | import apijson.MethodAccess; | 24 | 23 | import apijson.framework.BaseModel; | 25 | 24 | import apijson.orm.Visitor; | @@ -63,31 +62,30 @@ public User setSex(Integer sex) { | 63 | 62 | this.sex = sex; | 64 | 63 | return this; | 65 | 64 | } | | 65 | + | 66 | 66 | public String getHead() { | 67 | 67 | return head; | 68 | 68 | } | 69 | 69 | public User setHead(String head) { | 70 | 70 | this.head = head; | 71 | 71 | return this; | 72 | 72 | } | | 73 | + | 73 | 74 | public String getName() { | 74 | 75 | return name; | 75 | 76 | } | 76 | 77 | public User setName(String name) { | 77 | 78 | this.name = name; | 78 | 79 | return this; | 79 | 80 | } | | 81 | + | 80 | 82 | public List<String> getPictureList() { | 81 | 83 | return pictureList; | 82 | 84 | } | 83 | 85 | public User setPictureList(List<String> pictureList) { | 84 | 86 | this.pictureList = pictureList; | 85 | 87 | return this; | 86 | 88 | } | 87 | | - public User setPictureList(String pictureList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库 | 88 | | - this.pictureList = JSON.parseArray(pictureList, String.class); | 89 | | - return this; | 90 | | - } | 91 | 89 |
| 92 | 90 | public String getTag() { | 93 | 91 | return tag; | @@ -104,10 +102,5 @@ public User setContactIdList(List<Long> contactIdList) { | 104 | 102 | this.contactIdList = contactIdList; | 105 | 103 | return this; | 106 | 104 | } | 107 | | - public User setContactIdList(String contactIdList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库 | 108 | | - this.contactIdList = JSON.parseArray(contactIdList, Long.class); | 109 | | - return this; | 110 | | - } | 111 | | - | 112 | 105 |
| 113 | 106 | } |
Collapse file Copy file name to clipboardExpand all lines: APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/model/User.java +3-10Lines changed: 3 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 |
| 20 | 20 | import java.util.List; | 21 | 21 |
| 22 | | -import apijson.JSON; | 23 | 22 | import apijson.MethodAccess; | 24 | 23 | import apijson.framework.BaseModel; | 25 | 24 | import apijson.orm.Visitor; | @@ -63,31 +62,30 @@ public User setSex(Integer sex) { | 63 | 62 | this.sex = sex; | 64 | 63 | return this; | 65 | 64 | } | | 65 | + | 66 | 66 | public String getHead() { | 67 | 67 | return head; | 68 | 68 | } | 69 | 69 | public User setHead(String head) { | 70 | 70 | this.head = head; | 71 | 71 | return this; | 72 | 72 | } | | 73 | + | 73 | 74 | public String getName() { | 74 | 75 | return name; | 75 | 76 | } | 76 | 77 | public User setName(String name) { | 77 | 78 | this.name = name; | 78 | 79 | return this; | 79 | 80 | } | | 81 | + | 80 | 82 | public List<String> getPictureList() { | 81 | 83 | return pictureList; | 82 | 84 | } | 83 | 85 | public User setPictureList(List<String> pictureList) { | 84 | 86 | this.pictureList = pictureList; | 85 | 87 | return this; | 86 | 88 | } | 87 | | - public User setPictureList(String pictureList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库 | 88 | | - this.pictureList = JSON.parseArray(pictureList, String.class); | 89 | | - return this; | 90 | | - } | 91 | 89 |
| 92 | 90 | public String getTag() { | 93 | 91 | return tag; | @@ -104,10 +102,5 @@ public User setContactIdList(List<Long> contactIdList) { | 104 | 102 | this.contactIdList = contactIdList; | 105 | 103 | return this; | 106 | 104 | } | 107 | | - public User setContactIdList(String contactIdList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库 | 108 | | - this.contactIdList = JSON.parseArray(contactIdList, Long.class); | 109 | | - return this; | 110 | | - } | 111 | | - | 112 | 105 |
| 113 | 106 | } |
Collapse file Copy file name to clipboardExpand all lines: APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/jfinal/DemoController.java +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -549,7 +549,12 @@ public void login() { | 549 | 549 |
| 550 | 550 | response = new JSONResponse( | 551 | 551 | 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) | 553 | 558 | ) | 554 | 559 | ); | 555 | 560 | User user = response.getObject(User.class); | |
|