MyBatis中当实体类的属性名和表名的字段名不一样,怎么办?

解决方案:

1、写sql语句时起别名。

select id,last_name lastName,email,salary,dept_id deptId from employees

 

2、在配置文件开启Mybatis的驼峰命名规则(MybatisPlus默认开启)

mybatis:
  configuration:
    map-underscore-to-camel-case: true

3、在mapper.xml映射文件中使用resultMap来自定义映射规则

 

扩展。MybatisPlus中可以使用@tablefiled注解指定数据库字段

posted @ 2022-03-28 15:36  星期三q  阅读(430)  评论(0)    收藏  举报