Mybatis中的常用OGNL表達(dá)式
在Mybatis的動(dòng)態(tài)SQL和${}形式的參數(shù)中都用到了OGNL表達(dá)式。
Mybatis常用的OGNL表達(dá)式如下
1、e1 or e2:或
<if test="userEmail != null or userEmail == '1'"> </if>
2、e1 and e2:且
<if test="userEmail != null and userEmail != ''"> </if>
3、e1 == e2 或e1 eq e2:相等
<if test="userEmail == null and userEmail == ''"> </if>
4、e1 != e2 或 e1 neq e2:不等
<if test="userEmail != null and userEmail != ''"> </if>
5、e1 lt e2:小于
<if test="age lt 10"> ?? ??? ?#{userEmail,jdbcType=VARCHAR}, </if>
6、e1 lte e2:小于等于
7、e1 gt e2:大于
8、e1 gte e2:大于等于
9、 e1 + e2(加),e1 - e2(減),e1 * e2(乘),e1/e2(除),e1%e2(余)
10、!e或not e:非,取反
11、e.method(args):調(diào)用對(duì)象方法
<if test="list != null and list.size() > 0 "> ?? ??? ?#{userEmail,jdbcType=VARCHAR}, </if>
12、e.property:對(duì)象屬性值
<!-- 多接口參數(shù)的查詢方法(@Param + javaBean方式) --> ? <select id="selectByUserIdAndEnabledUseBean" resultMap="BaseResultMap"> ? ? select r.id, r.role_name, r.enabled, r.create_by, r.create_time,? ? ? u.user_name as "user.userName", u.user_email as "user.userEmail" ? ? from sys_user u? ? ? inner join sys_user_role ur on u.id = ur.user_id? ? ? inner join sys_role r on ur.role_id = r.id? ? ? where u.id = #{user.id} and r.enabled = #{role.enabled} </select>
13、e1[e2]:按索引取值(List、數(shù)組和map)
14、@class@method(args):調(diào)用類的靜態(tài)方法
<bind name="name" value="@ex.mybatis.rbac.mapper.UserMaperTest@setName()"/>
15、@class@field:調(diào)用類的靜態(tài)字段值
<bind name="name" value="@ex.mybatis.rbac.mapper.UserMaperTest@NAME"/>
Mybatis jstl表達(dá)式
寫了一個(gè)特別簡單的小例子,使用struts1+mybatis+spring,,,其中做了一個(gè)增刪改查,
結(jié)果遇到了一個(gè)特別無知的錯(cuò)誤!以后一定要記住,不能再犯了!
我在數(shù)據(jù)庫中建的表的字段是xx_xx這種格式的,例如notice_title,在pojo實(shí)體類中定義的屬性是noticeTitle這種形式的,
在做查找所有數(shù)據(jù)的時(shí)候,sql語句中對(duì)各個(gè)字段起了別名,但是別名沒有與pojo類的屬性名對(duì)應(yīng),導(dǎo)致resultMap對(duì)應(yīng)的類不能與自己起的別名對(duì)應(yīng),導(dǎo)致不能進(jìn)行實(shí)體類封裝值
?public ActionForward show(ActionMapping mapping, ActionForm form, ??????????? HttpServletRequest request, HttpServletResponse response) ??????????? throws Exception { ?????? ? ??????? List<Notice> noticeList = noticeService.getNoticeList(); ??????? request.setAttribute("noticeList", noticeList); ??????? return mapping.findForward("begin"); ??? }
<table border="1"> ??? <tr> ??????? <td>選擇</td> ??????? <td>主題</td> ??????? <td>內(nèi)容</td> ??????? <td>發(fā)表時(shí)間</td> ??????? <td>備注</td> ??????? <td>編輯人員</td> ??? </tr> ??? <c:forEach var="notices" items="${requestScope.noticeList }" > ??? <tr> ??????? <td><input type="checkbox" name="keyid" value="${notices.keyid}"/></td> ??????? <td>${notices.noticeTitle}</td> ??????? <td>${notices.noticeContent }</td> ??????? <td>${notices.noticePublishTime}</td> ??????? <td>${notices.noticeComment}</td> ??????? <td>${notices.noticeEditor }</td> ??? </tr> ??? </c:forEach> </table>
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決Unable to start embedded container&nbs
這篇文章主要介紹了解決Unable to start embedded container SpringBoot啟動(dòng)報(bào)錯(cuò)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07Java如何通過枚舉實(shí)現(xiàn)有限狀態(tài)機(jī)
這篇文章主要介紹了Java如何通過枚舉實(shí)現(xiàn)有限狀態(tài)機(jī),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07SpringCloud兩種注冊(cè)中心的實(shí)現(xiàn)
本文主要介紹了SpringCloud兩種注冊(cè)中心的實(shí)現(xiàn),包括服務(wù)注冊(cè)、服務(wù)拉取、負(fù)載均衡和實(shí)例權(quán)重配置等,具有一定的參考價(jià)值,感興趣的可以了解一下2025-01-01springboot項(xiàng)目中全局設(shè)置用UTC+8
本文主要介紹了springboot項(xiàng)目中全局設(shè)置用UTC+8,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04Java function函數(shù)式接口的使用方法與實(shí)例
這篇文章主要介紹了Java function函數(shù)式接口的使用方法與實(shí)例,函數(shù)式接口如一支未完成的詩篇,用Lambda表達(dá)式作韻腳,將代碼的機(jī)械美感與藝術(shù)的抽象融為一體,悄然重構(gòu)了開發(fā)者對(duì)代碼之美的認(rèn)知,需要的朋友可以參考下2025-02-02