Mybatis操作 三张表:一对多对多:
1、domain类:
package com.zhecre.jx.business.model.cases.request;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 描述:新增请求数据
*
* @CreateTime: 2022/11/24 16:29:56
* @Version: 1.0
*/
@Data
public class SchemeAddition {
private String type; //类型:新增时默认 1:当量指标 2:质量指标
private String status; //方案状态:方案状态(1:未提交|2:已提交|3:已驳回|4:已审核)
private String onoff; //状态(0:停用 | 1:启用)
private String casename; //方案名称
private String caseid; //方案编号、方案ID
private String casetype; //翻案类型
private String remark; //方案说明 备注
private Date createdate;//方案创建时间
private Date modifydate;//修改方案时间
private String isdelete; //删除方案:不要真删除 Y|N
//PAS_CAS_HOSPITAL 表
private List<Mechanism> mechdata;
//PAS_CAS_INDEX 表
private List<IndicatorData> catordata;
}
package com.zhecre.jx.business.model.cases.request;
import lombok.Data;
/**
* 描述: PAS_CAS_HOSPITAL 表
*
*
*/
@Data
public class Mechanism {
private String hosname;//机构
private String orgid;//机构id
private String caseid; //方案编号、方案ID
}
package com.zhecre.jx.business.model.cases.request;
import lombok.Data;
/**
* 描述:PAS_CAS_INDEX 表
*
* @CreateTime: 2022/11/24 16:31:02
* @Version: 1.0
*/
@Data
public class IndicatorData {
private String indexid; //指标ID
private String indexname; //指标名称
private String unit; //计量 值单位
private Double coef; //标化当量 权重
private Double discount; //折算当量
private String caseid; //方案编号、方案ID
}
2、controller 层:
@GetMapping("/getecho/{caseid}")
public SchemeAddition getCompensation(@PathVariable("caseid")String caseid){
return pasCaseService.getCompensation(caseid);
}
3、service层接口方法:
SchemeAddition getCompensation(String caseid);
4、service层接口实现方法:
@Override
public SchemeAddition getCompensation(String caseid) {
return pasCaseMapper.getCompensation(caseid);
}
5、Mapper接口:
SchemeAddition getCompensation(String caseid);
6、Mapper XML文件:
注意:
<!-- property: 指的是集合属性的值,对应类中的属性名 ofType:指的是集合中元素的类型 -->
<!-- property: 指的是属性名称, javaType:指的是属性的类型 -->
即:JavaType和ofType都是用来指定对象类型的,但是JavaType是用来指定pojo中属性的类型,而ofType指定的是映射到list集合属性中pojo的类型
<resultMap id="getCompensationMapper" type="com.zhecre.jx.business.model.cases.request.SchemeAddition">
<id column="caseid" property="caseid"/>
<result column="casename" property="casename"/>
<result column="casetype" property="casetype"/>
<result column="remark" property="remark"/>
<collection property="mechdata" ofType="com.zhecre.jx.business.model.cases.request.Mechanism">
<id column="caseid" property="caseid"/>
<result column="orgid" property="orgid"/>
<result column="hosname" property="hosname"/>
</collection>
<collection property="catordata" ofType="com.zhecre.jx.business.model.cases.request.IndicatorData">
<id column="caseid" property="caseid"/>
<result column="indexid" property="indexid"/>
<result column="unit" property="unit"/>
<result column="coef" property="coef"/>
<result column="discount" property="discount"/>
<result column="caseid" property="caseid"/>
</collection>
</resultMap>
<select id="getCompensation" resultType="com.zhecre.jx.business.model.cases.request.SchemeAddition" resultMap="getCompensationMapper">
SELECT c.casename,c.caseid,c.casetype,c.remark,
x.indexid,x.indexname,x.caseid,x.unit,x.coef,x.discount,
h.caseid,h.hosname,h.orgid
FROM PAS_CASE c,PAS_CASE_INDEX x,PAS_CASE_HOSPITAL h
WHERE c.CASEID=x.CASEID
and h.CASEID=c.CASEID
and c.CASEID=#{caseid}
</select>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/188582.html