当前位置:网站首页>JSON.toJSONString无法传递boolean
JSON.toJSONString无法传递boolean
2022-07-19 18:59:00 【帅大大的架构之路】
JSON.toJSONString无法传递boolean
在使用JSON.toJSONString转json格式的时候,后端是springboot,前端是vue,每次返回的User对象总是少一个字段state
User实体类:
public class User {
private int id;
private String username;
private String password;
private String email;
private String role;
private Boolean state;
接口:
@RequestMapping("/alluser")
@ResponseBody
public String getUserList(QueryInfo queryInfo) {
int numbers = userDao.getUserCount("%" + queryInfo.getQuery() + "%");
int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
List<User> users = userDao.getAllUser("%" + queryInfo.getQuery() + "%",pageStart,queryInfo.getPageSize());
HashMap<String, Object> res = new HashMap<>();
res.put("numbers",numbers);
res.put("data",users);
String s = JSON.toJSONString(res);
return s;
}
开始是按上面写的,发现state字段一直传不到前端,在网上找了很多方法,最后还是没能解决,后面听说springboot传数据给vue不需要转json,直接返回也可以接收,就改成下面这样了
@RequestMapping("/alluser")
@ResponseBody
public Map getUserList(QueryInfo queryInfo) {
int numbers = userDao.getUserCount("%" + queryInfo.getQuery() + "%");
int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
List<User> users = userDao.getAllUser("%" + queryInfo.getQuery() + "%",pageStart,queryInfo.getPageSize());
HashMap<String, Object> res = new HashMap<>();
res.put("numbers",numbers);
res.put("data",users);
return res;
}
直接返回Map,在前端就可以接收到全部字段了
前端:
data() {
return {
queryInfo: {
query: "",
pageNum: 1,
pageSize: 10,
},
userList: [],
total: null,
},
methods: {
async getUserList() {
const {
data:res} = await this.$http.get("/alluser",{
params: this.queryInfo});
this.userList = res.data;
this.total = res.numbers
}
}
无法将state字段传递回去,具体原因还没找到,不管是改get、set,还是JSON.toJSONString
的时候加那些参数,都不管用~
边栏推荐
猜你喜欢
The last technical problem baffles me: how to avoid the risk of production environment performance testing?
TZC 1283: simple sort - insert sort
iNFTnews | 音樂在Web3中的未來
力扣经典二叉树题目
uniapp 使用本地存储实现页面间的传值
AutoCAD - Custom special Linetype
GEE(7):GEE插件Open Earth Engine extension提高效率
Programming examples of stm32f1 and stm32subeide -bh1750 ambient light intensity sensor drive
【全局唯一id】分库分表之后,id 主键如何处理?
银行业数据安全建设专题分析
随机推荐
Codeforces Round #809 (Div. 2)
38行PHP代码免导入数据库分析Linux访问日志
OpenCV 学习资料分享:中文、图文、代码注释并茂,建议收藏
STM32开发笔记121:我理解的卡尔曼滤波
STM32F1与STM32CubeIDE编程实例-BH1750环境光强度传感器驱动
After 10 years of summary and sharing with test engineers, an article will teach you how to quickly find bugs and write test cases
2022-7-13总结
[liunx] wait function and waitpid function
【无标题】
103.(cesium篇)cesium蜂巢图(正方形)
Literature reading Xi - openattack: an open source textual advantageous attack Toolkit
纯国产!紫光SSD开始批量出货!
Directeur des tests Soft: « après cinq ans de travail, vous ne savez même pas comment tester l'interface serveur? »
Samsung exynos 9820 core photo exposure: large area increase under 8nm process, integrated dual core NPU!
揭开,字节跳动全链路压测的实践之路
洛谷P3398 仓鼠找 sugar 题解
华为5.2亿、新华三4.4亿、浪潮2.4亿、联想2.3亿、深信服2亿、戴尔1.7亿、SmartX 0.7亿、曙光0.6亿
服务器自动抢占GPU运行程序
OPPO宣布推出全新Reno系列:定位高端,对标华为Mate/P系列!
STM32F1与STM32CubeIDE编程实例-HMC5883电子罗盘驱动