核心配置:spring.jackson.property-naming-strategy= CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
配置写在apllication.yml中
如 TO:
public class Person {
private String id;
private String name;
private Integer count;
private String smalData;
//get set 省略。。。
}
controller:
@RequestMapping(value="listbyName2",method=RequestMethod.GET)
public List<Person> listPersonbyName(@RequestBody Person p){
JSONObject jo =new JSONObject();
if(dbtype!=null){
RoutingDataSourceContext.setThreadLocalDataSourceKey(dbtype);//切换数据源
}
List<Person> list = personService.list(p);
for(Person p:list){
System.out.println("id="+p.getId()+"-------name="+p.getName());
}
return list;
}
请求参数:
{id:1,name:'aa',smal_data:'444' } //使用下划线规范
//RequestBody 接受时使用java的驼峰规范,smal_data自动转为驼峰smalData
输出时List<Person> 里面的smalData又转成请求时的下划线规范 smal_data
访问controller,
输出如下:
[{"id":"1","name":"ooo","count":null,"smal_data":"ssmm"},{"id":"2","name":"rrr","count":null,"smal_data":"ssmm"}]
注意:Person里面的属性smalData自动转成下划线smal_data给客户端了
好了,以上就是spring.jackson.property-naming-strategy= CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
的作用,用于自动将controller接受的json的下划线属性转成驼峰,将controller输出的的json中的驼峰属性转成下划线属性
网友评论