在使用Mybatis的springboot项目中实体类命名与数据库不一样时解决办法
-
方法1:
在application.yml配置文件中加上如下配置
mybatis: configuration: map-underscore-to-camel-case: true #将下划线命名方式转换为驼峰命名
-
方法2:
在mapper映射文件中加上如下配置
<select id="findAll" resultType="com.shanghuo.bean.AdminUser" resultMap="adminMap"> <!--注意在标签中加上resultMap--> select * from t_admin </select> <!--property对应实体类中名称,column对应数据库中名称--> <resultMap id="adminMap" type="com.shanghuo.bean.AdminUser"> <!--主键字段的对应--> <id property="adminId" column="admin_id"/> <!--非主键字段的对应--> <result property="adminName" column="admin_name"/> <result property="adminPassword" column="admin_password"/> </resultMap>