//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` >= #{startDate}
</if>
<if test="endDate !=null" >
AND t3.`create_date` <= #{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` >= #{startDate}
</if>
<if test="endDate !=null" >
AND t3.`create_date` <= #{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>
<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` >= #{startDate}
</if>
<if test="endDate !=null" >
AND t3.`create_date` <= #{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` >= #{startDate}
</if>
<if test="endDate !=null" >
AND t3.`create_date` <= #{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>