项目场景:
在使用SpringBoot整合Mybatis时报错
问题描述
查询结果中a_id内容为空
mapper:
@Select("select * from t_comment where id = #{id}")
Comment findById(Integer id);
test:
@Autowired
private CommentMapper cm;
@Test
public void selectComment(){
Comment comment = cm.findById(6);
System.out.println(comment);
}
报错:
原因分析:
在编写实体类时使用了驼峰规则将a_id字段设计成了aId属性,所以无法正确映射查询结果。
解决方案:
在全局配置文件中添加开启驼峰命名匹配映射配置
#开启驼峰命名匹配映射
mybatis.configuration.map-underscore-to-camel-case=true
问题解决: