mybatis dao参数个数,和后面的xml的取值问题

如果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("")


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值