色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

mybatis的使用-Mapper文件各種語法介紹

瀏覽:133日期:2023-10-21 10:51:04

一、查詢

mybatis自定義查詢條件,queryString、queryMap、limit,Mapper文件寫法如下:

<select parameterType='com.systom.base.BaseDaoQueryParam' resultMap='BaseResultMap'> SELECT * FROM user WHERE 1 = 1 <if test='paramString != null'> and ${paramString} </if> <foreach collection='paramMap.keys' item='k' separator=''> <if test='null != paramMap[k]'> and ${k} = #{paramMap.${k}} </if> </foreach> <if test='paramInt1 != null and paramInt1 > 0 and paramInt2 != null and paramInt2 > 0'> limit #{paramInt1,jdbcType=INTEGER}, #{paramInt2,jdbcType=INTEGER} </if> </select>

以及傳入參入的bean類:

package com.systom.base; import java.io.Serializable;import java.util.HashMap;import java.util.Map; public class BaseDaoQueryParam implements Serializable { private static final long serialVersionUID = -8917191044499296040L; private String paramString; private Map<String, Object> paramMap = new HashMap<String, Object>(); private int paramInt1; private int paramInt2; private String orderBy; private String orderType; public BaseDaoQueryParam(String paramString, Map<String, Object> paramMap, int paramInt1, int paramInt2) { super(); this.paramString = paramString; if(paramMap != null) this.paramMap = paramMap; this.paramInt1 = paramInt1; this.paramInt2 = paramInt2; } public BaseDaoQueryParam(String paramString, Map<String, Object> paramMap, int paramInt1, int paramInt2, String orderBy, String orderType) { super(); this.paramString = paramString; if(paramMap != null) this.paramMap = paramMap; this.paramInt1 = paramInt1; this.paramInt2 = paramInt2; this.orderBy = orderBy; this.orderType = orderType; } public String getParamString() { return paramString; } public void setParamString(String paramString) { this.paramString = paramString; } public Map<String, Object> getParamMap() { return paramMap; } public void setParamMap(Map<String, Object> paramMap) { this.paramMap = paramMap; } public int getParamInt1() { return paramInt1; } public void setParamInt1(int paramInt1) { this.paramInt1 = paramInt1; } public int getParamInt2() { return paramInt2; } public void setParamInt2(int paramInt2) { this.paramInt2 = paramInt2; } public String getOrderBy() { return orderBy; } public void setOrderBy(String orderBy) { this.orderBy = orderBy; } public String getOrderType() { return orderType; } public void setOrderType(String orderType) { this.orderType = orderType; }}

補充 知識:mybatis的mapper文件的大于號特殊符號使用

第一種方法:

用了轉義字符把>和<替換掉,然后就沒有問題了。

SELECT * FROM test WHERE 1 = 1 AND start_date &lt;= CURRENT_DATE AND end_date &gt;= CURRENT_DATE

附:XML轉義字符

&lt;

<

小于號

&gt;

>

大于號

&amp;

&

&apos;

單引號

&quot;

'

雙引號

第二種方法:

因為這個是xml格式的,所以不允許出現類似“>”這樣的字符,但是都可以使用<![CDATA[ ]]>符號進行說明,將此類符號不進行解析

你的可以寫成這個:

mapper文件示例代碼

<![CDATA[ when min(starttime)<=’12:00’ and max(endtime)<=’12:00’ ]]>

在mybatis 的mapper配置文件sql語句中, 有時用到 大于, 小于等等的比較, 直接寫在里面就被當做標簽的開頭來處理了, 所以不可.現在又2種解決方法:

一, 用<![CDATA[ ]]>標識,例如:

<if test='menu.authority != null'> <![CDATA[ and authority < #{menu.authority}]]> </if>

其中不但能用大于’>’, 小于’<’, 小于等于’<=’, 大于等于’>=’ 也是可以的.

二, 轉義, 例如:

<if test='menu.authority != null'> and authority &lt; #{menu.authority} </if>

如此這般......

同樣可以可以和等號’=’一起來使用, 來表示大于等于, 小于等于等.如

<if test='menu.authority != null'> and authority &gt;= #{menu.authority} </if>

以上這篇mybatis的使用-Mapper文件各種語法介紹就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 欧美一级大黄特黄毛片视频 | 色综合色狠狠天天久久婷婷基地 | 精品成人免费一区二区在线播放 | 女教师的一级毛片 | 色老头一区二区三区在线观看 | 中文欧美一级强 | 久久久久综合一本久道 | 欧美一区高清 | 国产精品自在线 | 一 级 黄 色 大片 | 一级a级国产不卡毛片 | 久久久亚洲国产精品主播 | 国产日产欧产精品精品推荐在线 | 久久99国产精品久久 | 精品一区二区三区波多野结衣 | 国产精品亚洲欧美日韩久久 | 性色a | 国产亚洲精品一区二区在线观看 | 一级做a爰片性色毛片中国 一级做a爰性色毛片 | 日本天堂免费 | 成人看片免费 | 高清在线观看自拍视频 | 欧美jlzz18性欧美 | 久久久久999 | 她也啪在线视频精品网站 | www亚洲视频 | 国内精品久久久久久久久久影视 | 国产自一区 | 玖玖在线免费视频 | 韩国一级理黄论片 | 九九免费精品视频在这里 | 99精品视频一区在线视频免费观看 | 亚洲免费影院 | 欧美成人中文字幕 | 欧美日韩在线播一区二区三区 | 日本加勒比在线 | 欧美三级久久 | 99久久精品免费观看区一 | 久久精品视频99 | 一级特黄爽大片刺激 | 成人在线综合网 |