有一个实体类:
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>