springboot中,用JsonFormat对json类型的转换
·
后台info对象的属性值在数据库中存放的是integer,java实体bean的类型也是integer
期望后台返回前端的json数据如下:
"info": {
"id": "123"
}
实际上,对象自动转换成json时,默认会
"info": {
"id": 123
}
用@JsonFormat注解可以实现上述需求,在java实体bean对应属性上加注解@JsonFormat。
/**
* 获取:分配ID
*/
@JsonFormat(shape=Shape.STRING)
public Long getId() {
return id;
}
更多推荐
所有评论(0)