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;
}
}
这三种是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;
}
}
相关文章推荐
- MySQL中根据if标签实现多条件模糊查询(动态SQL语句)
- Oracle 时间字段的时区转换的一些常用查询语句
- 浅谈MySQL中优化sql语句查询常用的30种方法
- SQL查询时常用,但不熟悉的相关语句-----邮标,行号,临时表,类型转换,字符串函数,sql 判断语句,检查是不是数字,变量,sql split 函数
- mysql常用基础操作语法(六)--对数据排序和限制结果数量的条件查询【命令行模式】
- 常用MySql查询语句
- mysql分页原理和高效率的mysql分页查询语句
- sql server日期比较、日期查询常用语句(转)
- 23个MySQL常用查询语句
- MySQL常用查询语句总结(转)
- Mysql常用查询语句
- mysql分页原理和高效率的mysql分页查询语句
- MySQL常用查询语句
- 23个MySQL常用查询语句
- 关于mysql 简单的查询语句 以及常用函数的 总结
- mysql分页原理和高效率的mysql分页查询语句(转)
- 23个MySQL常用查询语句
- 浅谈MySQL中优化sql语句查询常用的30种方法
- mysql 查询正在执行的事务以及等待锁 常用的sql语句
- 数据库MySQL、Oracle、SQLServer、db2分页查询语句