Mybatis中的常用OGNL表達式
在Mybatis的動態(tài)SQL和${}形式的參數(shù)中都用到了OGNL表達式。
Mybatis常用的OGNL表達式如下
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)用對象方法
<if test="list != null and list.size() > 0 "> ?? ??? ?#{userEmail,jdbcType=VARCHAR}, </if>
12、e.property:對象屬性值
<!-- 多接口參數(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表達式
寫了一個特別簡單的小例子,使用struts1+mybatis+spring,,,其中做了一個增刪改查,
結(jié)果遇到了一個特別無知的錯誤!以后一定要記住,不能再犯了!
我在數(shù)據(jù)庫中建的表的字段是xx_xx這種格式的,例如notice_title,在pojo實體類中定義的屬性是noticeTitle這種形式的,
在做查找所有數(shù)據(jù)的時候,sql語句中對各個字段起了別名,但是別名沒有與pojo類的屬性名對應(yīng),導(dǎo)致resultMap對應(yīng)的類不能與自己起的別名對應(yīng),導(dǎo)致不能進行實體類封裝值
?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ā)表時間</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>
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Security使用數(shù)據(jù)庫認(rèn)證及用戶密碼加密和解密功能
這篇文章主要介紹了Spring Security使用數(shù)據(jù)庫認(rèn)證及用戶密碼加密和解密,本文通過代碼與截圖的形式給大家介紹的非常詳細,對大家的工作或?qū)W習(xí)具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03SpringBoot使用Flyway進行數(shù)據(jù)庫管理的操作方法
Flyway是一個開源的數(shù)據(jù)庫版本管理工具,并且極力主張“約定大于配置”,簡單、專注、強大。接下來通過本文給大家介紹SpringBoot使用Flyway進行數(shù)據(jù)庫管理的方法,感興趣的朋友一起看看吧2021-09-09Spring?Boot實現(xiàn)配置文件的自動加載和刷新功能
這篇文章我們介紹了Spring?Boot如何實現(xiàn)配置文件的自動加載和刷新,本文結(jié)合實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-05-05Intellij IDEA 2017.3使用Lombok及常用注解介紹
這篇文章主要介紹了Intellij IDEA 2017.3使用Lombok及常用注解介紹,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09java對象強轉(zhuǎn)成object的方法實現(xiàn)
在 Java 編程中,有時候我們需要將一個具體的對象強制轉(zhuǎn)換成 Object 類型,本文主要介紹了java對象強轉(zhuǎn)成object的方法實現(xiàn),具有一定的參考價值,感興趣的可以了解一下2024-03-03