mybatis注解动态sql
@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的更多相关文章
- MyBatis注解-动态SQL 一个 SqlProvider的demo
Provider动态语言注解 MyBatis提供了多个注解如:@InsertProvider,@UpdateProvider,@DeleteProvider和@SelectProvider,这些都是建 ...
- 4.Spring注解+SpringMVC注解+MyBatis注解(动态sql)
1.创建如图所示项目结构 2.在项目的
- Mybatis解析动态sql原理分析
前言 废话不多说,直接进入文章. 我们在使用mybatis的时候,会在xml中编写sql语句. 比如这段动态sql代码: <update id="update" parame ...
- Java-MyBatis:MyBatis 3 动态 SQL
ylbtech-Java-MyBatis:MyBatis 3 动态 SQL 1.返回顶部 1. 动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架 ...
- 一分钟带你了解下MyBatis的动态SQL!
MyBatis的强大特性之一便是它的动态SQL,以前拼接的时候需要注意的空格.列表最后的逗号等,现在都可以不用手动处理了,MyBatis采用功能强大的基于OGNL的表达式来实现,下面主要介绍下. 一. ...
- MyBatis的动态SQL详解
MyBatis的动态SQL是基于OGNL表达式的,它可以帮助我们方便的在SQL语句中实现某些逻辑,本文详解mybatis的动态sql,需要的朋友可以参考下 MyBatis 的一个强大的特性之一通常是它 ...
- mybatis 使用动态SQL
RoleMapper.java public interface RoleMapper { public void add(Role role); public void update(Role ro ...
- MyBatis框架——动态SQL、缓存机制、逆向工程
MyBatis框架--动态SQL.缓存机制.逆向工程 一.Dynamic SQL 为什么需要动态SQL?有时候需要根据实际传入的参数来动态的拼接SQL语句.最常用的就是:where和if标签 1.参考 ...
- 使用Mybatis实现动态SQL(一)
使用Mybatis实现动态SQL 作者 : Stanley 罗昊 [转载请注明出处和署名,谢谢!] 写在前面: *本章节适合有Mybatis基础者观看* 前置讲解 我现在写一个查询全部的 ...
随机推荐
- Window.open()方法参数详解总结(转)
1, 最基本的弹出窗口代码 window.open('page.html'); 2, 经过设置后的弹出窗口 window.open('page.html', 'newwindow', 'hei ...
- HDU 4717 The Moving Points(三分法)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)
Description There are N points in total. Every point moves in certain direction and certain speed. W ...
- Mac下安装OpenCV问题
最近看了纹理特征方面的paper,看了一些资料之后,想要实际动手实现一下其中LBP算法,果然OpenCV中已经实现. 问题 No module named "cv2" 当我在我们项 ...
- scrapy学习-爬取天天基金网基金列表
目录 描述 环境描述 步骤记录 创建scrapy项目 设置在pycharm下运行scrapy项目 分析如何获取数据 编写代码 step 1:设置item step 2:编写spider step 3: ...
- incorrect integer value for column 问题解决
最近在用zend框架,然后装了一个项目,发现注册的时候出现 General error: 1366 Incorrect integer value: '' for column 'user_id' a ...
- css如何选择相同class下的第一个class元素和最后一个元素?
如图,如果像选择类名为 class="exerciseInfo" 中的第一个和最后一个div,做法如下: 选择第一个类名: .exerciseInfo: nth-of-type ...
- URL大小写敏感之谜
URL其实就是我们浏览器地址栏的地址,一般由三部分组成: 协议名称,一般就是http 域名,也就是主机名 资源路径 如链接:http://www.w3school.com.cn/js/js_obj_r ...
- JSP动作标识
jsp中include有两种形式: include指令:<%@ include file=""%> include动作:<jsp:include page=&qu ...
- hdu 6057 Kanade's convolution(子集卷积)
题解: 然后就是接下来如何fwt 也就是如何处理bit(x) - bit(y) = bit(k)这个条件. 其实就是子集卷积. 把bit(x)和bit(y)划分成两个集合,然后就是子集卷积的形式. 这 ...
- (补漏)Springboot2.0 集成shiro权限管理
原文Springboot2.0 集成shiro权限管理 一.关于停止使用外键. 原本集成shiro建立用户.角色.权限表的时候使用了外键,系统自动创建其中两个关联表,用@JoinTable.看起来省事 ...