当前位置:网站首页>Json.tojsonstring cannot pass Boolean
Json.tojsonstring cannot pass Boolean
2022-07-25 04:49:00 【Shuaida's structural road】
JSON.toJSONString Can't pass boolean
In the use of JSON.toJSONString turn json Format time , The back end is springboot, The front is vue, Each return User Objects are always one field short state
User Entity class :
public class User {
private int id;
private String username;
private String password;
private String email;
private String role;
private Boolean state;
Interface :
@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;
}
At first, it was written above , Find out state The field cannot be transferred to the front end , I found a lot of ways on the Internet , Finally, it still couldn't be solved , I heard later that springboot Send data to vue There is no need to turn json, Direct return can also receive , It's changed to the following
@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;
}
Go straight back to Map, All fields can be received at the front end
front end :
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
}
}
Cannot be state Fields are passed back , The specific reason has not been found , Whether it's change get、set, still JSON.toJSONString When adding those parameters , Doesn't work ~
边栏推荐
- 自然的状态最好
- Thinking of reading
- GBase 8a 关于No Suitable Driver 问题
- When the development of the meta universe begins to show more and more the style of the Internet, we need to be vigilant
- Perspective
- [analysis of GPIO register (crl/crh) configuration of STM32]
- IT自媒体高调炫富,被黑客组织盯上,铁定要吃牢饭了…
- Millet 100W fast charging, 50W wireless charging technology exposure! Oppo Shen Yiren responded: boring!
- Ffmpeg download and installation
- 1. If function of Excel
猜你喜欢

Idea2021 installation

Summary of UPR optimization suggestions of unity

Web: compiling big refactoring from 10 to 1

# 1. Excel的IF函数
![[sht30 temperature and humidity display based on STM32F103]](/img/43/bbc66ab2d56cfa9dc05d795e8fe456.jpg)
[sht30 temperature and humidity display based on STM32F103]

After watching the latest interview with big manufacturers, these six JVM interview questions were asked

实战|记一次攻防演练打点

Open source summer interview | "after 00" PMC member Bai Zeping

How to ensure data consistency between MySQL and redis?
![[golang from introduction to practice] stone scissors paper game](/img/bb/5a5cdb9228949d263dc7bf62e34d97.png)
[golang from introduction to practice] stone scissors paper game
随机推荐
ThreadLocal Kills 11 consecutive questions
LVGL Switch & Table
Source code | opencv DNN + yolov7 target detection
PHP Baidu qianqianhua installment API
Data link layer protocol -- Ethernet protocol
教你如何定位不合理的SQL?并优化之
Tiny-emitter.js: a small event subscription and Publishing Library
1. If function of Excel
推荐系统-协同过滤在Spark中的实现
AUTOSAR from getting started to mastering 100 lectures (105) - protection mechanism of AUTOSAR timing for functional safety
小说抓取实战
看问题的角度
@Summary of ResponseBody annotation
In depth understanding of service
GBase 8a 关于No Suitable Driver 问题
When developing or debugging the IP direct scheme, it should be noted that the host value should be consistent with the direct IP
In the Internet of things market, Bosch sensor has launched a number of new solutions
01 create project warehouse
How to get the database creation time?
If you don't know these 20 classic redis interview questions, don't go to the interview!