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)中 目前只是初步版本,只是说明了意图,后面会持续完善和优化 ...
随机推荐
- ajax参数传递与后台接收
目录 ajax参数传递与后台接收 Servlet中读取http参数的方法 使用默认contentType,参数追加到url后传递 使用默认contentType,参数放到data中传递 使用默认con ...
- ZJOI 2019 游记
一轮 现在才知道大家都写了2333,现在补上不晚吧. Day 0 跟Crossing打了一路的王者,丝毫没有困意.颁奖仪式看到rank 1 又是xj的zyz,QWQ.被冯缘的热情四射的演讲给吓到了.然 ...
- (链表 importance) leetcode 2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...
- JAVA之锁-volatile
锁是JAVA多线程关键,也是面试中必问的, 在此好好总结一下. (先要从进程和线程说起,此处先欠下,回头专门说一下操作系统是怎么管理进程和线程的) 说到多线程就要说说JAVA的内存模型:图片来自于网络 ...
- C# 01 Primitive Types and Expressions
Class Data or Attributes state of the application Methods or Functions have behavior Namespace is a ...
- matlab 常用函数
Matlab常用函数 Matlab的内部常数 eps 浮点相对精度 pi 圆周率 exp 自然对数的底数e i 或j 虚数单位 Inf或 inf 无穷大 Matlab概率密度函数 ...
- windows service创建使用整合
C#创建Windows Service(Windows 服务)基础教程 C#winform windows服务程序创建与安装 C#实现WinForm随WINDOWS服务一起启动
- 20164305 徐广皓 Exp5 MSF基础应用
一.知识点总结 二.攻击实例 主动攻击的实践 ms08_067(win7) payload/generic/shell_reverse_tcp(失败) payload/windows/meterpre ...
- JavaScript的数组和循环
1. 数组: a) 声明数组:var 数组名 = new Array(数组大小); Var emp=new Array(“AA”,“BB”,“CC”): b) 添加 ...
- 查询sql 索引
SELECT indexname = a.name , tablename = c. name , indexcolumns = d .name , a .indidFROM sysindexes a ...