国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:138日期: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>

以及傳入?yún)⑷氲腷ean類:

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; }}

補(bǔ)充 知識(shí):mybatis的mapper文件的大于號(hào)特殊符號(hào)使用

第一種方法:

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

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

附:XML轉(zhuǎn)義字符

&lt;

<

小于號(hào)

&gt;

>

大于號(hào)

&amp;

&

&apos;

單引號(hào)

&quot;

'

雙引號(hào)

第二種方法:

因?yàn)檫@個(gè)是xml格式的,所以不允許出現(xiàn)類似“>”這樣的字符,但是都可以使用<![CDATA[ ]]>符號(hào)進(jìn)行說明,將此類符號(hào)不進(jìn)行解析

你的可以寫成這個(gè):

mapper文件示例代碼

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

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

一, 用<![CDATA[ ]]>標(biāo)識(shí),例如:

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

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

二, 轉(zhuǎn)義, 例如:

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

如此這般......

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

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

以上這篇mybatis的使用-Mapper文件各種語法介紹就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Mybatis 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 精品久久久久国产免费 | 国产视频久久久 | 亚洲午夜在线观看 | 国产一级片在线 | 欧美一级淫片免费播放口 | 亚洲社区在线 | 国产美女又黄又爽又色视频免费 | 色婷婷国产精品欧美毛片 | 日本欧美一区二区三区在线 | 青青热在线精品视频免费 | 精品久久久久久久高清 | 日本一线a视频免费观看 | 97精品国产综合久久久久久欧美 | 亚洲欧美片 | 久草在线免费资源站 | 久久久久依人综合影院 | 最近手机中文字幕1 | 宅男66lu国产乱在线观看 | 成人影院一区二区三区 | 美女被靠视频免费网站不需要会员 | 正在播放国产一区 | 亚洲黄网址 | 黄.www| 亚洲一级毛片免观看 | 免费观看欧美一级高清 | 一级国产在线观看高清 | 精品久久久久中文字幕日本 | 亚洲精品综合一二三区在线 | 欧美日韩另类综合 | 国产国产成人人免费影院 | 欧美高清视频一区 | 步兵社区 | 福利网址在线 | 亚洲日本高清成人aⅴ片 | 乱子伦一级在线现看 | 欧美日韩精品一区二区三区不卡 | 国产亚洲精品福利片 | 欧美亚洲另类久久综合 | 人人爽人人香蕉 | 日本加勒比高清一本大道 | 一区二区不卡久久精品 |