业务需要,需要遍历一个实体对象去实现sql的查询,实体对象中包括list对象。
下面看一下entity实体对象结构:
入参对象QueryParam ,里面包含list集合对象OwnerInfoParam
@Data
@AllArgsConstructor//生成一个全参数的构造方法
@NoArgsConstructor//生成一个无参数的构造方法
@Accessors(chain = true)
public class QueryParam {
//人员信息
private List<OwnerInfoParam> owners;
//证号
private String zh;
//区县 qxdm='all' 时为全市县查询,其他区县正常查询
private String qxdm;
}
@Data
@AllArgsConstructor//生成一个全参数的构造方法
@NoArgsConstructor//生成一个无参数的构造方法
@Accessors(chain = true)
public class OwnerInfoParam {
//姓名
private String ownername;
//身份证
private String ownercode;
//身份证 ownercode 15转18 或者 18转15的结果
private String idCard;
}
dao层代码:
List<Map<String, Object>> query(@Param("param") QueryParam param);
xml代码:
使用foreach获取到QueryParam的owners集合对象,然后遍历取值,使用实体的方式比map方式看起来会清晰一些
<select id="query" parameterType="QueryParam" resultType="map">
SELECT
fdzl as zl,
fwsuoyqlr as qlr,
qlrzjbh as qlrzjhm,
(select sd.value from sysdic sd where sd.class='19' and sd.main!=0 and sd.keyno=ghyt) as fwyt,
(select sd.value from sysdic sd where sd.class='3' and sd.main!=0 and sd.keyno=qllx) as qllx,
(select sd.value from sysdic sd where sd.class='4' and sd.main!=0 and sd.keyno=qlxz) as qlxz,
gyqk,
'' as szfe,
to_char(djsj,'yyyy-mm-dd hh24:mi:ss') as blsj,
trim(slid) as slid
FROM
regn_fwsyq
WHERE djbzt='0' and
<foreach collection="param.owners" open="(" close=")" separator="and" item="item" >
fwsuoyqlr like '%'||#{item.ownername}||'%' and (qlrzjbh like '%'||#{item.ownercode}||'%'
<if test="item.idCard != null and item.idCard != ''">
or qlrzjbh like '%'||#{item.idCard}||'%'
</if>
)
</foreach>
<if test="param.zh!=null and param.zh!=''">
AND zh = #{param.zh}
</if>
<if test="param.qxdm!=null and param.qxdm!='' and param.qxdm!='all'">
and qxdm = #{param.qxdm}
</if>
</select>
好了,分享就到这里,每天记录一点,学习更进一步!