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基础者观看* 前置讲解 我现在写一个查询全部的 ...
随机推荐
- NO12——快速幂取模
long long quickmod(long long a,long long b,long long m) { ; while(b)//用一个循环从右到左便利b的所有二进制位 { )//判断此时b ...
- linux 命令小结(随时更新)
代码备份命令: tar cvf 备份文件名 要备份的目录名 查看Linux服务器内存使用情况: 1.free命令 free -m [root@localhost ~]# free -m ...
- 利用calibre抓取新闻
Adding your favorite news website calibre has a powerful, flexible and easy-to-use framework for dow ...
- jetty maven插件
<plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifact ...
- Linux杂技
挂载光盘 mkdir /mnt/cdrom #建立挂载点 mount /dev/cdrom /mnt/cdrom/ #挂载光盘 更换YUM源: cd /etc/yum.repos.d/ 使网络yum源 ...
- java生成唯一的id编号
GUID是一个128位长的数字,一般用16进制表示.算法的核心思想是结合机器的网卡.当地时间.一个随即数来生成GUID.从理论上讲,如果一台机器每秒产生10000000个GUID,则可以保证(概率意义 ...
- WebSocket添加事件监听器(6)
WebSocket编程遵循异步编程模型;打开socket后,只需要等待事件发生,而不需要主动向服务器轮询,所以需要在WebSocket对象中添加回调函数来监听事件. WebSocket对象有三个事件: ...
- PyQt5学习--基本窗口控件--QMainWindow
QMainWindow主窗口为用户提供一个应用程序框架,它有自己的布局,可以在布局中添加控件.比如将工具栏.菜单栏和状态栏等添加到布局管理器中. 窗口类型介绍 QMainWindow.QWidget和 ...
- D. Relatively Prime Graph
Let's call an undirected graph G=(V,E)G=(V,E) relatively prime if and only if for each edge (v,u)∈E( ...
- wyh的天鹅~vector的使用
链接:https://www.nowcoder.com/acm/contest/93/L来源:牛客网 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 262144K,其他语言52428 ...