spring boot的属性设置有没有采用驼峰命名法我不知道,但属性的开头必须要小写
如果你的属性值像下面
@TableId("id") //映射主键 private Integer id; //自动增长id @TableField("studentId") //映射字段 private String studentId; //学生的学号 @TableField("studentName") private String studentName; //学生的姓名 @TableField("password") private String password; //学生的密码 @TableField("Email") private String Email; //学生的邮箱
其中private String Email; 的Email是大写,spring boot就会自动转成小写email
如果你用postman进行访问这个url接口测试post请求
{
"studentId": "123",
"Email": "3xxxxxxxx7@qq.com"
}
那么得到的结果将Email是空的,尽管你的测试属性和实体类或者接收的方法属性是一致的但springboot就会接收不到
如果你的测试是
{
"studentId": "123",
"email": "3xxxxxxxx7@qq.com"
}
那么springboot就会接收到这个email的值3xxxxxxxx7@qq.com。另外好像springboot属性设置没有强制说一定要驼峰命名法,因为这个实现是非常难的,假设你有一个字段stduentid,按道理如果springboot他强制说要驼峰命名法,那么这个studentid应该变成studentId对不对?可是这个如何实现呢?很难对不对?所以springboot他约定采用驼峰命名法,但是他只对属性开头必须是小写的,后面的大写不做强制要求。而且这我也是测试过的,后端属性是studentid,前端测试也是studentid,也同样可以接收到数据,而不是前端一定要studentId才能传过去。
最后关于讲一下
@TableField("studentId") //映射字段
private String studentId; //学生的学号
------------------------------------------------------------------
如果你不用注解@TableField("studentId") 映射这个字段,而只是写了这个属性
private String studentId; //学生的学号
那么springboot去数据库查的字段就变成了这个student_Id,例如他的执行语句
按道理应该是select studentId from 表名;
可是springboot会强制转换字段去执行 select student_Id from 表名;造成查不到
如果你映射了数据库的字段就会根据你的映射去执行就会变成这个select studentId from 表名;
其他映射字段关键字也是如此类推。