一如果dao一个参数既可以不写@param,xml中条件中取值可以直接取他的属性实体
/** * 任务小组人员 */ public class RwXzry extends DataEntity<RwXzry>{ private static final long serialVersionUID = 1L; private String xzryId; private String zz; //是否是组长 private String postion; private DrRw drRw; private DrJh drJh; private DrSx drSx; private DrRwXz drRwXz; //小组 private User user; private String beginDate; private String endDate;
/** * 分页查询 * */ List<RwXzry> findList(RwXzry rwXzry);
<select id="findList" resultType="com.hcht.modules.xydj.entity.RwXzry"> select a.create_date as "createDate" ,b.rw_mc as "drRw.rwMc" ,a.jh_id as "drJh.id" ,a.sx_id as "drSx.id" ,a.rw_id as "drRw.id" ,c.jh_mc as "drJh.jhMc" ,d.sx_mc as "drSx.sxMc" ,e.remarks as "remarks", CASE WHEN e.xz_index='1' THEN '组长' ELSE '组员' END AS "postion" from DR_RW_XZYR a inner join dr_rw b on a.rw_id = b.id and b.rw_flag in ('00','01','02') left outer join dr_jh c on c.id = a.jh_id left outer join dr_sx d on d.id = a.sx_id left outer join dr_rw_xz e on e.id = a.xz_id where a.userid =#{user.id} <if test="beginDate !=null and beginDate !='' and endDate !=null and endDate !=''"> and <![CDATA[ to_date(#{beginDate} , 'yyyy/mm/dd hh24:mi:ss') <= a.create_date and a.create_date< to_date(#{endDate} , 'yyyy/mm/dd hh24:mi:ss')]]> </if> <choose> <when test="page !=null and page.orderBy != null and page.orderBy != ''"> ORDER BY ${page.orderBy} </when> <otherwise> ORDER BY a.update_date DESC </otherwise> </choose> </select>
二如果dao一个参数可以写@param,xml中条件中取值必须先加上实体
@MyBatisDao public interface CxDao { List<CxEntity> list(@Param("cxEntity") CxEntity cxEntity); }
<select id="list" resultType="com.hcht.modules.zfdxcx.entity.CxEntity"> select a.id AS "id" ,a.xz_id AS "drRwXz.id" ,a.rw_id AS "drRw.id" ,a.jh_id AS "drJh.id" ,a.sx_id AS "drSx.id" ,a.dx_id AS "drZfdxk.id" ,b.col1 AS "drZfdxk.col1" ,c.sx_mc AS "drSx.sxMc" ,c.sx_flag AS "drSx.sxFlag" ,c.sx_fdsx AS "drSx.sxFdsx" ,d.rw_mc AS "drRw.rwMc" ,d.rw_flag AS "drRw.rwFlag" ,F_GET_XZRY_NAME(a.xz_id) AS "rynames" ,d.create_date AS "drRw.createDate" from dr_xz_rw a inner join dr_zfdxk b on b.id=a.dx_id and b.del_flag='0' inner join dr_sx c on c.id = a.sx_id and c.del_flag='0' inner join dr_rw d on d.id = a.rw_id and d.rw_flag in ('00','01','02') and d.del_flag='0' where a.del_flag='0' <if test=" cxEntity !=null and cxEntity.drZfdxk !=null and cxEntity.drZfdxk.col1 !=null and cxEntity.drZfdxk.col1 !=''"> and b.col1 LIKE CONCAT(CONCAT('%', #{cxEntity.drZfdxk.col1}), '%') </if> <if test=" cxEntity !=null and cxEntity.drSx !=null and cxEntity.drSx.sxMc !=null and cxEntity.drSx.sxMc !=''"> and c.sx_mc LIKE CONCAT(CONCAT('%',#{cxEntity.drSx.sxMc}), '%') </if> <if test="cxEntity !=null and cxEntity.drSx !=null and cxEntity.drSx.sxFlag !=null and cxEntity.drSx.sxFlag !=''"> and c.sx_flag =#{cxEntity.drSx.sxFlag} </if> <if test="cxEntity !=null and cxEntity.drRw !=null and cxEntity.drRw.rwFlag !=null and cxEntity.drRw.rwFlag !=''"> and d.rw_flag =#{cxEntity.drRw.rwFlag} </if> <if test="cxEntity !=null and cxEntity.endDate !=null and cxEntity.endDate !=''"> and <![CDATA[ d.create_date< to_date(#{cxEntity.endDate} , 'yyyy/mm/dd hh24:mi:ss')]]> </if> <if test="cxEntity !=null and cxEntity.beginDate !=null and cxEntity.beginDate !=''"> and <![CDATA[ to_date(#{cxEntity.beginDate} , 'yyyy/mm/dd hh24:mi:ss') <= d.create_date ]]> </if> </select>
三如果dao多个参数既必须写@param,xml中条件中取值必须先写参数
* 查询双随机问题数量 * @param * @param * @return */ List<Map<String,String>> wtslTj(@Param("beginDate") String beginDate, @Param("endDate") String endDate, @Param("rwzdbm") String rwzdbm, @Param("sxflag") String sxflag, @Param("itemType") String itemType );
<select id="wtslTj" resultType="java.util.Map"> select m.JG_WTSL ,m.JG_WTQYSL ,n.Name from sys_office n, (select sum(a.JG_WTSL) as JG_WTSL ,sum(a.JG_WTQYSL) as JG_WTQYSL ,b.rw_zdbm as ZDBM from dr_jg a inner join dr_rw b on b.id=a.rw_id inner join dr_sx c on c.id=a.sx_id where a.flag='01' and c.sx_flag=#{sxflag} <if test="beginDate !=null and beginDate !='' and endDate !=null and endDate !=''"> and <![CDATA[ to_date(#{beginDate} , 'yyyy/mm/dd hh24:mi:ss') <= a.create_date and a.create_date< to_date(#{endDate} , 'yyyy/mm/dd hh24:mi:ss')]]> </if> <if test="itemType !=null and itemType !=''"> and b.rw_zdbm in (${itemType}) </if> group by b.rw_zdbm)m where m.ZDBM=n.id </select>
统一:都加@Param("")