@Insert("INSERT INTO user (name, age, gender, experience) VALUES (<a href="http://www.oschina.net/tweet-topic/%7Bname%7D%2C" target="_blank">#{name},#</a>{age}, <a href="http://www.oschina.net/tweet-topic/%7Bgender%7D%2C" target="_blank">#{gender},#</a>{experience})")
@Options(useGeneratedKeys = true, keyProperty = "id")
int createUser(User user); @Insert("INSERT INTO user_interest (user_id, interest_id) VALUES (<a href="http://www.oschina.net/tweet-topic/%7BuserId%7D%2C" target="_blank">#{userId},#</a>{interestId})")
int createUserInterest(@Param("userId") int userId, @Param("interestId") int interestId); @Delete("DELETE FROM user WHERE id = #{id}")
int deleteUser(int id); @Delete("DELETE FROM user_interest WHERE user_id = #{userId}")
int deleteUserInterest(int userId); // findUsers(String, int) 的执行策略定义在 UserMapper.xml 中
List<User> findUsers(@Param("name") String name, @Param("experience") int experience); @Select("SELECT interest_id FROM user_interest WHERE user_id = #{userId} ORDER BY id")
List<Integer> findUserInterests(int userId); // queryInterest(int, int) 的执行策略定义在 UserMapper.xml 中
List<User> queryInterest(@Param("gender") int gender, @Param("experience") int experience);   
这样定制性更大,实现起来也方便,记住这样做的话注解中的sql语句必须全都在<script>标签中
  @Select("<script>select * from user where <if test=\"username !=null \">username = #{username} </if> <if test=\"phone !=null \">phone = #{phone} </if> <if test=\"usermail !=null \">usermail = #{usermail } </if></script>")

mybatis注解动态sql的更多相关文章

  1. MyBatis注解-动态SQL 一个 SqlProvider的demo

    Provider动态语言注解 MyBatis提供了多个注解如:@InsertProvider,@UpdateProvider,@DeleteProvider和@SelectProvider,这些都是建 ...

  2. 4.Spring注解+SpringMVC注解+MyBatis注解(动态sql)

    1.创建如图所示项目结构 2.在项目的

  3. Mybatis解析动态sql原理分析

    前言 废话不多说,直接进入文章. 我们在使用mybatis的时候,会在xml中编写sql语句. 比如这段动态sql代码: <update id="update" parame ...

  4. Java-MyBatis:MyBatis 3 动态 SQL

    ylbtech-Java-MyBatis:MyBatis 3 动态 SQL 1.返回顶部 1. 动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架 ...

  5. 一分钟带你了解下MyBatis的动态SQL!

    MyBatis的强大特性之一便是它的动态SQL,以前拼接的时候需要注意的空格.列表最后的逗号等,现在都可以不用手动处理了,MyBatis采用功能强大的基于OGNL的表达式来实现,下面主要介绍下. 一. ...

  6. MyBatis的动态SQL详解

    MyBatis的动态SQL是基于OGNL表达式的,它可以帮助我们方便的在SQL语句中实现某些逻辑,本文详解mybatis的动态sql,需要的朋友可以参考下 MyBatis 的一个强大的特性之一通常是它 ...

  7. mybatis 使用动态SQL

    RoleMapper.java public interface RoleMapper { public void add(Role role); public void update(Role ro ...

  8. MyBatis框架——动态SQL、缓存机制、逆向工程

    MyBatis框架--动态SQL.缓存机制.逆向工程 一.Dynamic SQL 为什么需要动态SQL?有时候需要根据实际传入的参数来动态的拼接SQL语句.最常用的就是:where和if标签 1.参考 ...

  9. 使用Mybatis实现动态SQL(一)

    使用Mybatis实现动态SQL 作者 : Stanley 罗昊 [转载请注明出处和署名,谢谢!] 写在前面:        *本章节适合有Mybatis基础者观看* 前置讲解 我现在写一个查询全部的 ...

随机推荐

  1. Java笔试题-线程编程方面

      Ja 线程编程方面 60.java中有几种方法可以实现一个线程?用什么关键字修饰同步方法?stop()和suspend()方法为何不推荐使用? 答:有两种实现方法,分别是继承Thread类与实现R ...

  2. 27、理解js的继承机制(转载自阮一峰)

    Javascript继承机制的设计思想   作者: 阮一峰 日期: 2011年6月 5日 我一直很难理解Javascript语言的继承机制. 它没有"子类"和"父类&qu ...

  3. The Erdös-Straus Conjecture 题解

    题面 Description The Brocard Erdös-Straus conjecture is that for any integern > 2 , there are posit ...

  4. kubernetes(k8s) 集群

    开启和重启命令: sudo systemctl stop etcdsudo systemctl stop dockersudo systemctl stop kube-apiserversudo sy ...

  5. 前端开发神器Sublime Text2/3之安装使用(windows7/Mac)

    一,到官方网站下载神器 地址:http://www.sublimetext.com/3 Sublime Text 3 配置解释(默认){// 设置主题文件“color_scheme”: “Packag ...

  6. lintcode-45-最大子数组差

    45-最大子数组差 给定一个整数数组,找出两个不重叠的子数组A和B,使两个子数组和的差的绝对值|SUM(A) - SUM(B)|最大. 返回这个最大的差值. 注意事项 子数组最少包含一个数 样例 给出 ...

  7. 个人作业Week3-案例分析(201521123103 吴雅娟)

    根据博客要求,写一篇个人随笔 参考来自: http://www.cnblogs.com/xinz/archive/2012/03/26/2417699.html: http://www.cnblogs ...

  8. winspool.drv

    public partial class Form1 : Form{ [System.Runtime.InteropServices.DllImportAttribute("winspool ...

  9. Java中的输入输出流

    FileInputStream和FileOutputStream 创建含磁盘文件的输入 输出流对象. FileInputStream继承自InputStream,用于读取本地文件中的字节数据,由于所有 ...

  10. JavaScript五种继承方式详解

    本文抄袭仅供学习http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html 一. 构造函数绑定 ...