mybatis sql mapper 用map的写法
来源:互联网 发布:2选1数据选择器原理图 编辑:程序博客网 时间:2024/05/22 01:32
CHAR_LENGTH(str)
返回值为字符串str 的长度,长度的单位为字符。一个多字节字符算作一个单字符。对于一个包含五个二字节字符集, LENGTH()返回值为 10,而CHAR_LENGTH()的返回值为5。
CHARACTER_LENGTH(str)
CHARACTER_LENGTH()是CHAR_LENGTH()的同义词。
BIT_LENGTH(str)
返回2进制长度.
简单的总结来说,mysql中获取字符串长度的有两个函数:
length:返回字符串所占的字节数,是计算字段的长度一个汉字是算三个字符,一个数字或字母算一个字符
char_length:返回字符串所占的字符数,不管汉字还是数字或者是字母都算是一个字符
有时候写mapper的时候用到map类型的传参,写法如下
// 获取方法查询入参 public Map<String, Object> getCommonParams(CaseRecordsInfoModel caseRecordsInfoModel, Pageable pageable) { Map<String, Object> params = new HashMap<String, Object>(); if (caseRecordsInfoModel.getRecord() != null) { if (StringUtils.isNotBlank(caseRecordsInfoModel.getRecord().getUserId())) { params.put("userId", caseRecordsInfoModel.getRecord().getUserId()); } if (pageable != null) { params.put("offset", pageable.getOffset()); params.put("pageSize", pageable.getPageSize()); } return params; }
service 层
@Override public int selectPageByParamsCount(Map<String, Object> params, Pageable pageable) { return caseRecordsInfoRepo.selectPageByParamsCount(params); }
mapper层
<select id="selectPageByParams" resultMap="BaseResultMap" parameterType="Map"> select <include refid="Base_Column_Lists" /> from case_records_info a , case_records record where record.if_out=0 <if test="_parameter.containsKey('userId')" > and record.user_id not in <foreach item="item" index="index" collection="items" open="(" separator="," close=")"> #{item} </foreach> </if> <if test="_parameter.containsKey('ifAboveM7') and ifAboveM7 =='false'.toString()" > and record.collection_type in <foreach item="item" index="index" collection="types" open="(" separator="," close=")"> #{item} </foreach> </if> <if test="_parameter.containsKey('ifAboveM7') and ifAboveM7=='true'.toString()" > and (record.collection_type > 'M7' or LENGTH(record.collection_type)>2 or record.collection_type in <foreach item="item" index="index" collection="types" open="(" separator="," close=")"> #{item} </foreach>) </if> <if test="_parameter.containsKey('sendAreaName') and ifNoAdr=='true'.toString()"> and a.send_area_name = '' </if> <if test="_parameter.containsKey('sendAreaName') and ifNoAdr=='false'.toString()"> and a.send_area_name like CONCAT(#{sendAreaName},'%' ) </if> and a.case_id=record.id and a.is_deleted=0 and record.is_deleted=0 ORDER BY record.user_id ASC <if test="_parameter.containsKey('offset')"> limit #{offset},#{pageSize} </if> </select>
mapper 还有多条件判断
比如<if test="_parameter.containsKey('sendAreaName') and ifNoAdr=='false'.toString()">
这里就是判断某个变量字符串是不是“true”再进行sql语句的编写。
总体mapper 使用map参数的用法就讲到这。
1 0
- mybatis sql mapper 用map的写法
- mybatis的mapper配置文件的一般写法。
- mybatis 模糊查询 mapper.xml的写法
- mybatis映射文件mapper.xml的写法。
- mybatis批量insert的mapper xml写法
- mybatis的mapper配置文件配置oracle的判断是否成年的sql简洁写法。
- 列表上移下移的SQL语句(mybatis mapper.xml写法)
- mybatis的mapper返回map结果集
- mybatis的mapper返回map结果集
- mybatis sql in 查询 mapper与service层写法
- Mybatis Mapper配置文件sql中的 List Array Map 的foreach 、in
- mybatis一对多和多对一种mapper的写法
- Mybatis mapper获取sql
- mybatis 的mapper映射文件返回一个map
- mapper.xml中SQL语句in的写法
- Mybatis增删改查mapper文件写法
- mybatis中mapper传集合写法
- Mybatis mapper.xml 判断条件写法注意
- 「添加购物」功能交互演示
- lintcode binary-tree-paths 二叉树的所有路径
- HTML引入文件有无下划线的区别
- ListView 里面getView()的参数final来修饰的原因
- JAVA比较器排序及对比自然排序
- mybatis sql mapper 用map的写法
- iOS 中常用的第三方开源库
- 代码重构技巧
- 获取非客户区消息
- 关于APK瘦身值得分享的一些经验
- 如何将PDF转为可编辑的Word文档
- 把EXCEL用程序导入到ORACLE中(SpringMVC+MyBatis)
- poj 2251 Dungeon Master 简单队列与BFS
- 聚类 - 1 - 聚类介绍