mybatisplus默认开启驼峰命名,在进行数据段映射时容易出错。
例如下面这个类
public class Department {
private Integer id;
private String departmentName;
public setId(Integer id) {
this.id = id;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public Integer getId() {
return id;
}
public String getDepartmentName() {
return departmentName;
}
}
当数据表字段如下时
进行查询时会出现以下错误
即找不到last_name字段,可我们明明没有last_name这个数据段,数据表和实体类都是以lastName命名,为何会出现这种错误?
这是因为mybatis默认开启驼峰命名法,按规则数据表中的lastName字段应对应实体类中的last_name属性,而实体类中的lastName属性应对应数据表中的last_name字段。
要解决这个问题,只需在配置文件中添加以下代码即关闭驼峰命名就行了。
mybatis-plus.configuration.map-underscore-to-camel-case=false