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基础者观看* 前置讲解 我现在写一个查询全部的 ...
随机推荐
- vue路由文档笔记
引入router this.$router 和 router 使用起来完全一样.我们使用 this.$router 的原因是我们并不想在每个独立需要封装路由的组件中都导入路由 可以在任何组件内通过 t ...
- 问题 A: Least Common Multiple
题目描述 The least common multiple (LCM) of a set of positive integers is the smallest positive integer ...
- 1013 Battle Over Cities (25 分)(图的遍历or并查集)
这题用并查集或者dfs都可以做 dfs #include<bits/stdc++.h> using namespace std; ; bool mp[N][N]; int n,m,k; b ...
- ubuntu中 VI 方向键、删除键问题
这两天重新装的ubuntu系统,发觉使用VI时,方向键按下去后变成ABCD,删除键无效.网上搜寻一番,应该是VI软件本身的问题,顾卸载重装即可,步骤如下: 1.执行命令 sudo apt-get re ...
- static 关键字解析(转)
static关键字解析 Java中的static关键字解析 static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大公司的面试官喜欢在面试时问到的知识点之一.下面 ...
- JQuery实现的智能表单提示
实现一个类似如此效果的表单验证:
- PAT 甲级 1036 Boys vs Girls(20)
https://pintia.cn/problem-sets/994805342720868352/problems/994805453203030016 This time you are aske ...
- 偶遇RandomAccessFile
一.前言 本来在研究NIO,别人举的栗子里面,看到一个RandomAccessFile类,之前没见过,就去看了一下,现将相关内容记录如下 二.正文 RandomAccessFile直接继承自Objec ...
- BZOJ2437 NOI2011兔兔与蛋蛋(二分图匹配+博弈)
首先将棋盘黑白染色,不妨令空格处为黑色.那么移动奇数次后空格一定处于白色格子,偶数次后空格一定处于黑色格子.所以若有某个格子的棋子颜色与棋盘颜色不同,这个棋子就是没有用的.并且空格与某棋子交换后,棋子 ...
- Codeforces 662C(快速沃尔什变换 FWT)
感觉快速沃尔什变换和快速傅里叶变换有很大的区别啊orz 不是很明白为什么位运算也可以叫做卷积(或许不应该叫卷积吧) 我是看 http://blog.csdn.net/liangzhaoyang1/ar ...