MyBatis多表关联查询
来源:互联网 发布:网络电影比较大尺度的 编辑:程序博客网 时间:2024/05/17 22:27
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>
3:一对一
basic实体类里面的list改成单个对象
xml文件里<collection...>改成
<association property="对象名称" javaType="com.cybernaut.core.model.ChangeRecords" column="basic_info_id" select="change_records.selectSupervisor"/>
另外一种方式<association property="对象名称" javaType="com.cybernaut.core.model.ChangeRecords"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>
0 0
- mybatis多表关联查询
- mybatis多表关联查询
- MyBatis多表关联查询
- Mybatis多表关联查询
- mybatis表关联查询
- Mybatis关联表查询
- MyBatis-一对多关联表查询 -06
- 243,mybatis 多表关联查询
- Mybatis一对多关联表查询
- mybatis多表关联查询的问题
- Mybatis实现关联表查询(一对多关联)
- Mybatis一对多关联查询
- mybatis一对多关联查询
- Mybatis一对多关联查询
- mybatis一对多关联查询
- MyBatis实现关联表查询
- Mybatis实现关联表查询
- MyBatis实现关联表查询
- 数据预处理之标准化
- POJ 1979 3669 DFS BFS
- linux安装遇到的问题
- 151. Reverse Words in a String(unsolved)
- java接口操作HBase
- MyBatis多表关联查询
- django下载安装
- 有理数类
- 斯坦福机器学习6-7
- Centos6.5使用yum安装mysql——快速上手必备
- 指针部分
- JS入门学习笔记——函数入门
- ℃江让您从精通到入门:写诗APP的制作诠析
- 【4412开发板使用经验分享】迅为4412开发板I2C驱动问题