postman传输Boolean类型注意事项
·
先来看看自动生成字段的区别:
这是idea自动生成的getter/setter方法:
private Boolean isTest;
public Boolean getTest() {
return isTest;
}
public void setTest(Boolean test) {
isTest = test;
}
//----------------------------------------------
private boolean good;
public boolean isGood() {
return good;
}
public void setGood(boolean good) {
this.good = good;
}
这是通过lombok的@Data注解生成的结构:
](https://i-blog.csdnimg.cn/blog_migrate/313bc060c211c18c2b18d83c268b20bf.png)
可以很明显看出来两种方法生成的Boolean类型的getter/setter方法不同,但是boolean类型是相同的,但也和普通的setter/getter不太一样
而controller层通过@requestBody接收前台返回的表单或json数据,通过set方法注入数据到DTO中,此时就需要注意自己项目中Boolean类型的结构
Boolean : getTest/setTest
"isTest":true //正确
"test":false //错误
Boolean : getIsTest/setIsTest
"isTest":false //错误
"test":true //正确
boolean:
"good":true //正确
"isGood":false //错误
写错的话后台字段是为空的哦
更多推荐
所有评论(0)