1:最简单粗暴的笨办法就是自定义一个智能的实体类,把多表查询需要的字段列出属性,注意实体类的属性名和数据库字段名保持一致
2:两个表一对多关联
实体类
public class BasicInfo{ private Integer basicInfoId; private Integer projectId;//项目ID private String keyNo;//公司内部关联主键 private String name;//企业名称 private String no;//注册号 private String belongOrg;//登记机关 private String operName;//法定代表人 private String startDate;//成立日期 private String endDate;//注销/吊销日期 private String status;//登记状态(存续、在业、注销、迁入、吊销、迁出、停业、清算) private String province;//所在省份缩写 private String updateDate;//更新日期 private String creditCode;//统一社会信用代码 private String registCapi;//注册资本 private String econKind;//类型 private String address;//住所 private String scope;//经营范围 private String termStart;//营业期限自 private String teamEnd;//营业期限至 private String checkDate;//核准日期 private String sysTime;// private List<ChangeRecords> changeRecordsList; //变更记录 .....
public class ChangeRecords { private Integer changeRecordsId; private Integer basicInfoId; private String projectName; private String beforeContent; private String afterContent; private String changeDate; public Integer getChangeRecordsId() { return changeRecordsId; } public void setChangeRecordsId(Integer changeRecordsId) { this.changeRecordsId = changeRecordsId; } public String getProjectName() { return projectName; } public void setProjectName(String projectName) { this.projectName = projectName; } public String getBeforeContent() { return beforeContent; } public void setBeforeContent(String beforeContent) { this.beforeContent = beforeContent; } public String getAfterContent() { return afterContent; } public void setAfterContent(String afterContent) { this.afterContent = afterContent; } public String getChangeDate() { return changeDate; } public void setChangeDate(String changeDate) { this.changeDate = changeDate; } public Integer getBasicInfoId() { return basicInfoId; } public void setBasicInfoId(Integer basicInfoId) { this.basicInfoId = basicInfoId; } }
xml文件
<resultMap id="BaseResultMap" type="com.cybernaut.core.model.BasicInfo" > <id column="basic_info_id" property="basicInfoId" jdbcType="INTEGER" /> <result column="project_id" property="projectId" jdbcType="INTEGER" /> <result column="key_no" property="keyNo" jdbcType="VARCHAR" /> <result column="name" property="name" jdbcType="VARCHAR" /> <result column="no" property="no" jdbcType="VARCHAR" /> <result column="belong_org" property="belongOrg" jdbcType="VARCHAR" /> <result column="oper_name" property="operName" jdbcType="VARCHAR" /> <result column="start_date" property="startDate" jdbcType="VARCHAR" /> <result column="end_date" property="endDate" jdbcType="VARCHAR" /> <result column="status" property="status" jdbcType="VARCHAR" /> <result column="province" property="province" jdbcType="VARCHAR" /> <result column="update_date" property="updateDate" jdbcType="VARCHAR" /> <result column="credit_code" property="creditCode" jdbcType="VARCHAR" /> <result column="regist_capi" property="registCapi" jdbcType="VARCHAR" /> <result column="econ_kind" property="econKind" jdbcType="VARCHAR" /> <result column="address" property="address" jdbcType="VARCHAR" /> <result column="scope" property="scope" jdbcType="VARCHAR" /> <result column="term_start" property="termStart" jdbcType="VARCHAR" /> <result column="team_end" property="teamEnd" jdbcType="VARCHAR" /> <result column="check_date" property="checkDate" jdbcType="VARCHAR" /> <result column="sys_time" property="sysTime" jdbcType="VARCHAR" /> <!-- 变更记录 --> <collection property="changeRecordsList" ofType="com.cybernaut.core.model.ChangeRecords" column="basic_info_id" select="change_records.selectByChangeRecordsId"></collection> </resultMap> <sql id="Base_Column_List" > basic_info_id, project_id, key_no, name, no, belong_org, oper_name, start_date, end_date, status, province, update_date, credit_code, regist_capi, econ_kind, address, scope, term_start, team_end, check_date, sys_time </sql>
basic实体类里面的list改成单个对象
xml文件里<collection...>改成
<association property="对象名称" javaType="
" column="basic_info_id" select="change_records.selectSupervisor"/>com.cybernaut.core.model.ChangeRecords
另外一种方式<association property="对象名称" javaType="
resultMap="changeRecordsResultMap"/></resultMap><!--教师实体映射--><resultMap id="changeRecordsResultMap" type="com.cybernaut.core.model.ChangeRecords"><id property="id" column="t_id"/><result property="name" column="t_name"/><result property="gender" column="t_gender"/><result property="researchArea" column="t_research_area"/><result property="title" column="t_title"/></resultMap>com.cybernaut.core.model.ChangeRecords"
联系客服