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. Spring框架的@Valid注解

    上一篇文章介绍了springmvc的get请求参数可以是一个自定的对象.那么如何限制这个对象里的参数是否必传呢? 方法一:在代码逻辑里取出对象里的这个值,手动进行判断 方法二:使用@Valid注解,在 ...

  2. DRF 商城项目 - 购物( 购物车, 订单, 支付 )逻辑梳理

    购物车 购物车模型 购物车中的数据不应该重复. 即对相同商品的增加应该是对购买数量的处理而不是增加一条记录 因此对此进行联合唯一索引, 但是也因此存在一些问题 class ShoppingCart(m ...

  3. CF1153 F. Serval and Bonus Problem(dp)

    题意 一个长为 \(l\) 的线段,每次等概率选择线段上两个点,共选出 \(n\) 条线段,求至少被 \(k\) 条线段覆盖的长度期望. 数据范围 \(1 \le k \le n \le 2000, ...

  4. vscode常用插件

    vscode写JS/html/css是比较适合的,因为轻量级. 只是需要一些插件来完善VSCODE功能,感觉VSCODE就是要靠插件的,不然的话,只是一个高级的代码编辑器.可能比editplus&qu ...

  5. 【dp】友好城市

    题目一: [题目描述] Palmia国有一条横贯东西的大河,河有笔直的南北两岸,岸上各有位置各不相同的N个城市.北岸的每个城市有且仅有一个友好城市在南岸,而且不同城市的友好城市不相同. 每对友好城市都 ...

  6. [HNOI2009]最小圈(分数规划+SPFA判负环)

    题解:求环长比环边个数的最小值,即求min{Σw[i]/|S|},其中i∈S.这题一眼二分,然后可以把边的个数进行转化,假设存在Σw[i]/|S|<=k,则Σw[i]-k|S|<=0,即Σ ...

  7. lumen 支持多文件上传

    1.webform (注意:name后面一定要加[]号) <form method="post" enctype="multipart/form-data" ...

  8. SaltStack配置管理和YAML

    配置管理和YAML 配置管理 所谓的配置管理,也称为状态管理,就是可以通过编写文件,文件的内容为安装什么功能.开启什么服务,执行什么任务等信息,然后通过salt的配置管理,指定minion来执行这些操 ...

  9. (N叉树 递归) leetcode 590. N-ary Tree Postorder Traversal

    Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary ...

  10. pthread 线程立即取消的两种方法

    1.相关函数介绍 a. int pthread_cancel(pthread_t thread) 1发送终止信号给thread线程,如果成功则返回0,否则为非0值.发送成功并不意味着thread会终止 ...