mapper文件常遇到的问题汇总

//mapprer文件的namespace写接口的全路径
<mapper namespace="com.shengya.service.dao.EpersonRecordDao" >



//时间范围查询处理办法
1、获取表单时间串,startTime,endTime
2、将时间串转换成日期对象:Date startDate,Date endDate
3、将时间范围传递到dao层
4、编写sql语句:
                <if test="startDate != null "  >
                    AND t3.`create_date` &gt;= #{startDate}
                </if>
                <if test="endDate !=null"  >
                    AND t3.`create_date` &lt;= #{endDate}
                </if>
                
                
                
//使用foreach查集合(id in (1,2,3,4))
1、创建集合ids
2、编写sql语句
        collection 集合名称
        item 每次循环的变量
        open 开始符号
        close 结束符号
        separator 分割符
        
        <if test="ids!=null">
        <foreach collection="ids" item="item" open="(" close=")" separator=",">
            ${item}
        </foreach>
        </if>
        
//使用包装类Po处理多表查询
1、建议继承
    public class CooperationPo extends EpersonRecord {
    private Integer ep_Id;//企业人才id
    private  String full_name;//企业人才名称
    private String telephone;//电话
    private Date ep_create_date;//生成时间
    private String username;
    private String passKeyWord;
    
 <resultMap id="CoResultMap" type="com.shengya.service.vo.CooperationPo" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="uid" property="uid" jdbcType="INTEGER" />
        <result column="create_user" property="createUser" jdbcType="INTEGER" />
        <result column="create_name" property="createName" jdbcType="VARCHAR" />
        <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
        <result column="is_delete" property="isDelete" jdbcType="INTEGER" />
        <result column="status" property="status" jdbcType="INTEGER" />
        <result column="remark" property="remark" jdbcType="VARCHAR" />

        <result column="ep_Id" property="ep_Id" jdbcType="INTEGER"/>
        <result column="full_name" property="full_name" jdbcType="VARCHAR" />
        <result column="telephone" property="telephone" jdbcType="VARCHAR" />
        <result column="ep_create_date" property="ep_create_date" jdbcType="TIMESTAMP" />
        <result column="username" property="username" jdbcType="TIMESTAMP" />
        <result column="passKeyWord" property="passKeyWord" jdbcType="TIMESTAMP" />
    </resultMap>
    
    
    
    
    
//连接查询使用or 和 and
1、如果使用or连接条件,必须使用“()”将or条件包起来
<select id="getEnterpriceCooperation" resultMap="CoResultMap">
        SELECT  t1.`uid` ep_Id,t1.`full_name` full_name,t1.`telephone` telephone,t1.`create_date` ep_create_date,t3.`id` id,t3.`uid` uid,t3.`create_user` create_user,t3.`create_name` create_name,t3.`create_date` create_date,t3.`is_delete` is_delete,t3.`status` STATUS,t3.`remark` remark,
        t2.username username,t2.password passKeyWord
        FROM enterprise_info t1
        LEFT JOIN USER t2 ON t1.uid=t2.`id`
        LEFT JOIN eperson_record t3 ON t1.uid=t3.uid
        <where>
            <trim suffixOverrides="and">
                <if test="createUserId != null">
                    AND (t3.`create_user`= #{createUserId}  OR t3.`create_user` IS NULL)
                </if>
                <if test="approveStatus != null">
                    AND t3.status = #{approveStatus}
                </if>
                <if test="admin != null">
                    AND t3.`create_name` LIKE '%${admin}%'
                </if>
                <if test="startDate != null "  >
                    AND t3.`create_date` &gt;= #{startDate}
                </if>
                <if test="endDate !=null"  >
                    AND t3.`create_date` &lt;= #{endDate}
                </if>

            </trim>
            AND  t1.approve_status=1
            AND t1.is_delete=0
        </where>
        GROUP BY t1.uid
        ORDER BY t3.`create_date` DESC
        <if test="pageInfo!=null">
            limit ${pageInfo.startIndex} ,${pageInfo.pagesize}
        </if>
    </select>

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值