Mybatis动态sql
来源:互联网 发布:好吃的零食知乎 编辑:程序博客网 时间:2024/06/02 02:13
动态SQL
MyBatis的动态SQL,解决了SQL字符串拼接的痛苦。
1.if
3.set
优化后:
MyBatis的动态SQL,解决了SQL字符串拼接的痛苦。
1.if
<select id="findActiveBlogWithTitleLike"parameterType="Blog" resultType="Blog">SELECT * FROM BLOGWHERE state = 'ACTIVE'<if test="title != null">AND title like #{title}</if></select>
<span style="font-family: Arial; font-size: 14px; line-height: 26px;">这条语句会提供一个可选的文本查找功能。如果没有传递title,那么所有激活的博客都会被返回。</span><br style="font-family: Arial; font-size: 14px; line-height: 26px;" /><span style="font-family: Arial; font-size: 14px; line-height: 26px;">如果传递了title,那么就会查找相近的title。</span><br style="font-family: Arial; font-size: 14px; line-height: 26px;" />
<span style="font-family: Arial; font-size: 14px; line-height: 26px;">.choose,when,otherwise</span><br style="font-family: Arial; font-size: 14px; line-height: 26px;" /><pre name="code" class="html" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);">
<select id="findActiveBlogLike"parameterType="BLOG" resultType="BLOG">SELECT * FROM BLOGWHERE<trim prefix="WHERE" prefixOverrides="AND |OR "><choose><when test="title != null">AND title like #{title}</when><when test="author != null and author.name != null">AND title like #{author.name}</when><otherwise>AND featured = 1</otherwise></choose></trim></select>
3.set
<update id="updateAuthorIfNecessary"parameterType="Author">update Author<set><if test="username != null">username=#{username},</if><if test="password != null">password=#{password},</if><if test="email != null">email=#{email}</if></set>where id=#{id}</update>
优化后:
<update id="updateAuthorIfNecessary"parameterType="Author">update Author<trim prefix="where" prefixOverrides=","> <set><if test="username != null">username=#{username},</if><if test="password != null">password=#{password},</if><if test="email != null">email=#{email}</if></set>where id=#{id}</trim></update>
0 0
- mybatis动态SQL语句
- MyBatis动态SQL
- MyBatis 动态SQL
- Mybatis 动态SQL
- MyBatis动态SQL
- MyBatis动态SQL完整版
- mybatis动态sql
- mybatis动态SQL语句
- mybatis动态SQL语句
- MyBatis的动态SQL
- MyBatis动态SQL
- MyBatis动态SQL
- MyBatis 动态SQL语句
- MyBatis动态SQL
- Mybatis组建动态SQL
- MyBatis 动态sql
- mybatis 动态SQL语句
- MyBatis动态SQL详解
- MVC + EF + Bootstrap 2 权限管理系统入门级(附源码)
- 我是一wi么?然后前,非
- 暑期)用为什的挂钩相是把瘴
- 【详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!】【一】
- 很好的Linux命令
- Mybatis动态sql
- 浅谈Cisco静态路由配置实验
- socketexception.errorcode 解释
- MFC 一个类访问另一个类成员对象的成员变量值
- 算法竞赛入门 5.3.1 6174问题
- 电子商店策划实训
- 基于PCA的人脸识别
- Ubuntu下QToolButton下正常显示,但是arm下却会有点击残留问题,解决
- windows Qt编程之wchar_t * to QString格式转化