您的位置:首页 > 数据库 > MySQL

mysql分页_日期转换_模糊查询_if语句等常用语法

2017-12-25 10:55 603 查看
mysql分页_日期转换_模糊查询_if语句等常用语法
这三种是sql语句中使用最广泛的,无需解释,直接抄代码就行

<!-- 获取会员sum -->
<select id="getUserSum" resultType="string">
<![CDATA[
SELECT COUNT(T.USER_ID)
FROM T_USER_INFO T
]]>
<where>
T.DELFLAG="0"
<if test="nickname != '' and nickname != null">
AND T.NICKNAME LIKE CONCAT('%',#{nickname},'%')
</if>
<if test="userPhone != '' and userPhone != null">
AND T.USER_PHONE LIKE CONCAT('%',#{userPhone},'%')
</if>
<if test="regType != '' and regType != null">
AND T.REG_TYPE = #{regType}
</if>
</where>
</select>

<!-- 获取会员list -->
<select id="getUserList" resultMap="UserRVO">
SELECT T.USER_ID as userId,
T.USER_NAME as userName,
T.NICKNAME as nickname,
T.USER_PHONE as userPhone,
T.QQ_ID as qqId,
T.UNION_ID as unionId,
T.HANDEL_IMG as handelImg,
T.USER_LEVAL as userLeval,
T.USER_SEX as userSex,
T.REG_TYPE as regType,
date_format(T.CREATETIME, '%Y-%m-%d %H:%i:%s') as createTime
FROM T_USER_INFO T
<where>
T.DELFLAG="0"
<if test="nickname != '' and nickname != null">
AND T.NICKNAME LIKE CONCAT('%',#{nickname},'%')
</if>
<if test="userPhone != '' and userPhone != null">
AND T.USER_PHONE LIKE CONCAT('%',#{userPhone},'%')
</if>
<if test="regType != '' and regType != null">
AND T.REG_TYPE = #{regType}
</if>
</where>
ORDER BY T.CREATETIME DESC
LIMIT #{begin},#{count}
</select>

附件PagesVO
package com.car.trip.vo;

/**
* 分页VO
*/
public class PagesVO {

/** 当前页数 */
private int pages;
/** 查询数量 */
private int count;
/** 开始row数 */
private int begin;

public PagesVO() {
}

/**
* 计算开始与结束行数
* @param pages 当前页数
* @param count 查询数量
*/
public PagesVO(String pages, String count) {
this.pages = Integer.parseInt(pages);
this.count = Integer.parseInt(count);;
this.getBeginEnd();
}

/**
* 返回 开始row数
* @param pages 当前页数
* @param count 查询数量
* @return
* @author czt
* @since 2017年12月21日 上午9:17:18
*/
public static String getBegin(String pages, String count) {
return "" + new PagesVO(pages, count).getBegin();
}

/**
* 计算开始与结束行数
* @author czt
* @time 2015年5月21日 下午5:27:10
*/
public void getBeginEnd() {
this.begin = (this.pages - 1) * this.count;
}
public int getBegin() {
return begin;
}
public void setBegin(int begin) {
this.begin = begin;
}
public int getPages() {
return pages;
}
public void setPages(int pages) {
this.pages = pages;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: