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基础者观看* 前置讲解 我现在写一个查询全部的 ...
随机推荐
- 线段树简单入门 (含普通线段树, zkw线段树, 主席树)
线段树简单入门 递归版线段树 线段树的定义 线段树, 顾名思义, 就是每个节点表示一个区间. 线段树通常维护一些区间的值, 例如区间和. 比如, 上图 \([2, 5]\) 区间的和, 为以下区间的和 ...
- 一个关于sql更新的小笔记
一直在sqlserver下写东西,突然用mysql有些语法发生了改变,有点折腾 (MS SQL Server)语句:update A set a.Name = b.Name from A ...
- Selenium 启动无头浏览器,只有chrome 和 firefox的,没有IE
使用无头浏览器,可以避免掉不确定的弹出框对脚本稳定性的影响,还能在脚本执行过程中省略掉了css 加载的时间. 以下是Selenium 启动无头浏览器的方法,只有chrome 和 firefox的. p ...
- CSP201503-1:图像旋转
引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...
- CSP201412-1:门禁系统
引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的“计算机职业资格认证”考试,针对计算机软件开发. ...
- GraphSAGE 代码解析(四) - models.py
原创文章-转载请注明出处哦.其他部分内容参见以下链接- GraphSAGE 代码解析(一) - unsupervised_train.py GraphSAGE 代码解析(二) - layers.py ...
- 【CodeForces】9B-Running Student
目录 Question Description Input Output Solution 解法1 Question Description 小明在公交车始发站上车,他应该在哪个站点下车才能最快到达学 ...
- 制作一个简易计算器——基于Android Studio实现
一个计算器Android程序的源码部分分为主干和细节两部分. 一.主干 1. 主干的构成 计算器的布局 事件(即计算器上的按钮.文本框)监听 实现计算 2. 详细解释 假设我们的项目名为Calcula ...
- 【Python】- 如何使用Visual Studio 2013编写python?
安装Visual Studio 2013 1.VS2013下载安装略 安装python2.7 1.从官网下载python2.7,下载地址:https://www.python.org/getit/ ...
- 文件系统中 atime,lazytime,relatime 详聊
atime,ctime,mtime是文件inode的三个时间戳,分别表示文件最近一次的访问时间:inode本身的更改(changed)时间:文件数据的更改(modify)时间:这几个概念还是很好区分. ...