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文件中以注解的方式的更多相关文章

  1. SSM框架中写sql在xml文件中

    第一种(用Mapper.xml映射文件中定义了操作数据库sql) 注意点: 1.#{}与${} #{}表示一个占位符,使用占位符可以防止sql注入, ${}通过${}可以将parameterType传 ...

  2. 在mybatis中写sql语句的一些体会

    本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...

  3. Excel VBA中写SQL,这些问题的方法你一定要牢记

    小爬之前的文章 [Excel VBA中写SQL,这些问题你一定为此头痛过]中详细讲诉了一些常见的VBA 中使用SQL遇到的问题,这里再补充两个常见的问题场景及对应的解决方案,希望你们看了后能够思路开阔 ...

  4. C#程序中:如何删除xml文件中的节点、元素。

    C#中动态的清理xml文件中的垃圾信息是程序员必会的哦.这就像数据库一样,不会清理数据怎么可以呢?其实xml文件就可以用作一个小的数据库,存储一些简单的信息.所以,用C#程序实现xml文件的增.删.改 ...

  5. C# 将List中的数据导入csv文件中

    //http://www.cnblogs.com/mingmingruyuedlut/archive/2013/01/20/2849906.html C# 将List中的数据导入csv文件中   将数 ...

  6. Linux shell 中提取zip或jar文件中的某个文件

    Linux shell 中提取zip或jar文件中的某个文件 假如有个压缩包 abc.jar, 里面文件如下 (可以用unzip -l abc.jar 查看): data/1.txt data/2.t ...

  7. CockroachDB学习笔记——[译]CockroachDB中的SQL:映射表中数据到键值存储

    CockroachDB学习笔记--[译]CockroachDB中的SQL:映射表中数据到键值存储 原文标题:SQL in CockroachDB: Mapping Table Data to Key- ...

  8. (转)MyBatis框架的学习(四)——Mapper.xml文件中的输入和输出映射以及动态sql

    http://blog.csdn.net/yerenyuan_pku/article/details/71893689 前面对MyBatis框架的学习中,我们对Mapper.xml映射文件多少有些了解 ...

  9. Zoey.Dapper--Dapper扩展之把SQL语句放到文件中

    介绍 不知道大家在用Dapper的时候SQL语句是写到哪的,目前看网上的例子都是写到类里面的. 此项目的目的是把SQL语句放到文件(xml)中 目前只是初步版本,只是说明了意图,后面会持续完善和优化 ...

随机推荐

  1. [Luogu 4245] 任意模数NTT

    Description 给定 \(2\) 个多项式 \(F(x), G(x)\),请求出 \(F(x) * G(x)\). 系数对 \(p\) 取模,且不保证 \(p\) 可以分解成 \(p = a ...

  2. yii2 使用指定数据库执行createCommand

    Yii::$app->dbName->createCommand($sql)->queryAll(); 指定dbName数据库配置

  3. (十四)QFile操作,QByteArray,文件流操作,QTextStream,QDataStream,QFileInfo, QIODevice

    QFile f 1.readall #include "widget.h" #include "ui_widget.h" #include <QFileD ...

  4. freetype 字形解析

    目录 freetype 字形解析 字体管理 数据结构 字体抽象 title: freetype 字形解析 date: 2019/3/7 20:17:46 toc: true --- freetype ...

  5. 常见的数据扩充(data augmentation)方法

    G~L~M~R~S 一.data augmentation 常见的数据扩充(data augmentation)方法:文中图片均来自吴恩达教授的deeplearning.ai课程 1.Mirrorin ...

  6. Rancher2.1安装部署

    基础环境配置 1.操作系统选择 Ubuntu 16.04(64位 Server版) Centos/RedHat Linux 7.5+(64位) 2.Docker版本选择 1.12.6 1.13.1 1 ...

  7. flask websocker

    WebSocket 是一种网络通信协议.RFC6455 定义了它的通信标准. HTTP 协议是一种无状态的.无连接的.单向的应用层协议.它采用了请求/响应模型.通信请求只能由客户端发起,服务端对请求做 ...

  8. Hadoop集群管理

    1.简介 Hadoop是大数据通用处理平台,提供了分布式文件存储以及分布式离线并行计算,由于Hadoop的高拓展性,在使用Hadoop时通常以集群的方式运行,集群中的节点可达上千个,能够处理PB级的数 ...

  9. python接收axios的post请求,并处理后返回数据

    公司的python工程师不会js和python数据交互,所以我就去试了一下. 首先安装python,django框架和django-cors-headers. python官网下载,按提示操作,记住最 ...

  10. shell 批量修改较长字符串 字符串内容之间更换位置

    cat 1.txt src='http://img2.tgbusdata.cn/v2/thumb/jpg/MkY5Myw2NTUsMzAzLDksMywxLC0xLDAscms1MCwxOTIuMTY ...