mybatis实体类和数据库字段不同处理方法

有一个实体类:

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
public class MeetingType{

    private String department;

    private String section;

    private String mm;

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        System.out.println("正在注入department*********************");
        this.department = department;
    }

    public String getSection() {
        return section;
    }

    public void setSection(String section) {
        System.out.println("正在注入section*********************");
        this.section = section;
    }

    public String getMm() {
        return mm;
    }

    public void setMm(String mm) {
        System.out.println("正在注入mm*********************");
        this.mm = mm;
    }
}

数据库有一个表:DM_TBL_MEETING_TYPE
在这里插入图片描述
发现实体类的mm和数据库的MEETING_TYPE字段不一致,如果使用select查询时,直接resultType返不回实体类会导致返回的值不全,解决如下:

方法1:
将实体类的mm改成meetingType或meetingtype,sql使用resultType返回实体类

方法2:
自定义

<resultMap id="BaseResultMap" type="com.bs.it.epds.others.entity.MeetingType">
	<result column="DEPARTMENT" property="department" />
	<result column="SECTION" property="section" />
	<result column="MEETING_TYPE" property="mm" />
	</resultMap>

sql使用resultMap返回BaseResultMap

方法3:
在sql中使用as:

<select id="getMeetingTypeList" resultType="com.bs.it.epds.others.entity.MeetingType">
		select t.DEPARTMENT,t.SECTION,t.MEETING_TYPE as mm
		from DM_TBL_MEETING_TYPE t
		where
		t.department=#{depart}
		order by t.section
	</select>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值