SSM框架中写sql在dao文件中以注解的方式
1以注解方式

//两个参数其中一个是对象需写,对象.属性
@Update("update delivery_address set consignee = #{address.consignee},country = #{address.country},city = #{address.city},address = #{address.address},phone_number = #{address.phoneNumber},telnumber = #{address.telNumber},zipcode = #{address.zipcode},update_time = UNIX_TIMESTAMP(NOW())*1000 where id = #{id}")
void update(@Param("address") Address address, @Param("id") Long id);
OrderProvider.class

另外一种写法
@Select("<script>" +
"SELECT COUNT(*) FROM excel_template " +
" where create_uid = ${sqlMap.create_uid} and is_delete = 0 " +
"<if test=\"sqlMap.end_time != null and sqlMap.end_time != '' \"> and UNIX_TIMESTAMP(create_date) ${sqlMap.end_time} </if>" +
"<if test=\"sqlMap.start_time != null and sqlMap.start_time != ''\"> and UNIX_TIMESTAMP(create_date) >= ${sqlMap.start_time} </if>" +
"<if test=\"sqlMap.keyword != null and sqlMap.keyword != ''\"> and (file_name like CONCAT('%',#{sqlMap.keyword},'%') )</if>" +
"</script>")
int countList(PageBean<ExcelTemplate> pageBean);
在上一篇中提到查询中in()语句用foreach查询
现在用另外一种方式自定义注解方式
public List<TaskChildFinished> findListByIds(String ids) {
List<Long> idList = StringUtils.stringToLongList(ids);
List<TaskChildFinished> taskChildFinisheds = endProductDao.findListByIds(idList);
return this.format(taskChildFinisheds);
}
public static List<Long> stringToLongList(String string){
return Arrays.asList(string.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
}
@Select("select * from task_child_finished where id in (#{idList})")
@Lang(SimpleSelectInLangDriver.class)
List<TaskChildFinished> findListByIds(@Param("idList")List<Long> ids);
public class SimpleSelectInLangDriver extends XMLLanguageDriver implements LanguageDriver {
private static final Pattern inPattern = Pattern.compile("\\(#\\{(\\w+)\\}\\)");
@Override
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
Matcher matcher = inPattern.matcher(script);
if (matcher.find()) {
script = matcher.replaceAll("<foreach collection=\"$1\" item=\"_item\" open=\"(\" "
+ "separator=\",\" close=\")\" >#{_item}</foreach>");
}
script = "<script>" + script + "</script>";
return super.createSqlSource(configuration, script, parameterType);
}
}
SSM框架中写sql在dao文件中以注解的方式的更多相关文章
- SSM框架中写sql在xml文件中
第一种(用Mapper.xml映射文件中定义了操作数据库sql) 注意点: 1.#{}与${} #{}表示一个占位符,使用占位符可以防止sql注入, ${}通过${}可以将parameterType传 ...
- 在mybatis中写sql语句的一些体会
本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...
- Excel VBA中写SQL,这些问题的方法你一定要牢记
小爬之前的文章 [Excel VBA中写SQL,这些问题你一定为此头痛过]中详细讲诉了一些常见的VBA 中使用SQL遇到的问题,这里再补充两个常见的问题场景及对应的解决方案,希望你们看了后能够思路开阔 ...
- C#程序中:如何删除xml文件中的节点、元素。
C#中动态的清理xml文件中的垃圾信息是程序员必会的哦.这就像数据库一样,不会清理数据怎么可以呢?其实xml文件就可以用作一个小的数据库,存储一些简单的信息.所以,用C#程序实现xml文件的增.删.改 ...
- C# 将List中的数据导入csv文件中
//http://www.cnblogs.com/mingmingruyuedlut/archive/2013/01/20/2849906.html C# 将List中的数据导入csv文件中 将数 ...
- Linux shell 中提取zip或jar文件中的某个文件
Linux shell 中提取zip或jar文件中的某个文件 假如有个压缩包 abc.jar, 里面文件如下 (可以用unzip -l abc.jar 查看): data/1.txt data/2.t ...
- CockroachDB学习笔记——[译]CockroachDB中的SQL:映射表中数据到键值存储
CockroachDB学习笔记--[译]CockroachDB中的SQL:映射表中数据到键值存储 原文标题:SQL in CockroachDB: Mapping Table Data to Key- ...
- (转)MyBatis框架的学习(四)——Mapper.xml文件中的输入和输出映射以及动态sql
http://blog.csdn.net/yerenyuan_pku/article/details/71893689 前面对MyBatis框架的学习中,我们对Mapper.xml映射文件多少有些了解 ...
- Zoey.Dapper--Dapper扩展之把SQL语句放到文件中
介绍 不知道大家在用Dapper的时候SQL语句是写到哪的,目前看网上的例子都是写到类里面的. 此项目的目的是把SQL语句放到文件(xml)中 目前只是初步版本,只是说明了意图,后面会持续完善和优化 ...
随机推荐
- 快速排序-python
- 使用TCP取样器测试Socket接口
1 JMeter下载安装 下载地址:JMeter,选择Binaries下面的zip包. 检查java环境,是否安装了jdk或者jre. 解压zip包->找到bin目录下jmeter.bat文件- ...
- Oracle字符串行拆分成列的三种方式
Oracle字符串行拆分成列的三种方式 --muphy 开发过程中经常会遇到将前台多个值用逗号连接一同传递到后台查询,这个用逗号连接的字符串分隔的每个字符串分别对应Oracle数据库表的不同行. 如下 ...
- Vim内直接使用p粘贴系统剪切板
解决方法 set clipboard=unnamed
- 关于ajax 进行post提交 json数据到controller
首选需要参考的两个博客: www.cnblogs.com/Benjamin/archive/2013/09/11/3314576.html http://www.cnblogs.com/quanyon ...
- Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array(动态规划.递推)
传送门 题意: 给你一个包含 n 个元素的序列 a[]: 定义序列 a[] 的 beauty 为序列 a[] 的连续区间的加和最大值,如果全为负数,则 beauty = 0: 例如: a[] = {1 ...
- HBase LSM树存储引擎详解
1.前提 讲LSM树之前,需要提下三种基本的存储引擎,这样才能清楚LSM树的由来: 哈希存储引擎. B树存储引擎. LSM树(Log-Structured Merge Tree)存储引擎. 2. 哈希 ...
- MySQL学习13 - 索引
一.索引的介绍 二 .索引的作用 三.常见的几种索引: 3.1 普通索引 3.2 唯一索引 3.3 主键索引 3.4 组合索引 四.索引名词 五.正确使用索引的情况 什么是最左前缀呢? 六.索引的注意 ...
- Object Detection / Human Action Recognition 项目
https://towardsdatascience.com/real-time-and-video-processing-object-detection-using-tensorflow-open ...
- 模块--random
random模块 1 random.random() print(random.random()) 0-1 之间随机小数 不包含1 2 random.uniform(a,b) ...