业务:通常主表从表 查询,一对多关系,通常是先查主表,然后拿主表的 关联字段与从表关联。在代码中 通常用for 循环等方法给 从表的数据赋值,很麻烦,,,很麻烦。。。。
用mybatis的一对多完全解决上面这个鸡肋操作
1.接口
/**
* TODO 集合测试
*/
@ApiOperationSupport(order = 100)
@ApiOperation(value = "集合测试列表")
@GetMapping("/listtest")
public TableDataInfo listtest(CmrxRpmProject cmrxRpmProject) {
startPage();
List<CmrxRpmProject> list = cmrxRpmProjectService.listtest(cmrxRpmProject);
return getDataTable(list);
}
2.实体类
3.mybatis
3.1 对象关系映射
<resultMap type="CmrxRpmProject" id="CmrxRpmProjectResult">
<id property="id" column="id" />
<result property="id" column="id" />
<result property="sbdw" column="sbdw" />
<result property="xmmc" column="xmmc" />
<result property="lxr" column="lxr" />
<!--TODO 集合测试-->
<collection property="cmrxRpmProjectresultsList" ofType="CmrxRpmProjectresults">
<id property="id" column="bid"/>
<result property="ctCgxsname" column="ct_cgxsname" />
<result property="cgxs" column="cgxs" />
</collection>
</resultMap>
3.2 数据查询
<select id="listtest" resultMap="CmrxRpmProjectResult">
select
a.id, a.sbdw, a.xmmc, a.lxr, a.lxdh, a.ksn, a.ksy, a.jsn, a.jsy, a.xmry, a.ptjf, a.zdzz, a.zczj, a.ztr, a.xmbj, a.yjnr,
a.yjyy, a.jsgj, a.xyjc, a.khzb, a.cxd,
a.sblb, a.lxzt, a.yszt, a.yswd, a.lrbm, a.uid, a.lrsj, a.gdzt, a.yssq,
b.ct_cgxsname, b.cgmc, b.cgxs,b.id as bid
from psms.cmrx_rpm_project as a left join psms.cmrx_rpm_projectresults as b on a.id = b.idp
</select>
4.数据返回结构