目录
解决方法3:使用@Results注解(可以解决结果只有单个数据的情况,不能解决多条数据的情况)
原因1:数据库命名与实体类不一致
如:数据库中为user_name,User类中为userName
解决方法1:开启驼峰命名转换
在application.properties中加入
mybatis.configuration.map-underscore-to-camel-case=true
如果你的是application.yml,则为
mybatis:
configuration:
map-underscore-to-camel-case: true
解决方法2:引入jpa注解@Table、@Column
@Entity @Table(name = "user_info") public class User { @Id @Column(name="user_id") private String userId;
}
但是我用了没用,如果失效的话可以看看这篇(这篇的方法我用了也不行):
spring boot jpa 使用@Entity 的时候 @Column 注解失效,找不到对应的列。MySQLSyntaxErrorException
解决方法3:使用@Results注解(可以解决结果只有单个数据的情况,不能解决多条数据的情况)
@Results({
@Result(property = "实体类属性1",column = "数据库表字段名1"),
@Result(property = "实体类属性3",column = "数据库表字段名"),
@Result(property = "实体类属性4",column = "数据库表字段名"),
@Result(property = "实体类属性5",column = "数据库表字段名")
})
具体用法看这篇