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,,,其中做了一個增刪改查,
結果遇到了一個特別無知的錯誤!以后一定要記住,不能再犯了!
我在數(shù)據(jù)庫中建的表的字段是xx_xx這種格式的,例如notice_title,在pojo實體類中定義的屬性是noticeTitle這種形式的,
在做查找所有數(shù)據(jù)的時候,sql語句中對各個字段起了別名,但是別名沒有與pojo類的屬性名對應,導致resultMap對應的類不能與自己起的別名對應,導致不能進行實體類封裝值



?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)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
解決Unable to start embedded container&nbs
這篇文章主要介紹了解決Unable to start embedded container SpringBoot啟動報錯問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07
Java function函數(shù)式接口的使用方法與實例
這篇文章主要介紹了Java function函數(shù)式接口的使用方法與實例,函數(shù)式接口如一支未完成的詩篇,用Lambda表達式作韻腳,將代碼的機械美感與藝術的抽象融為一體,悄然重構了開發(fā)者對代碼之美的認知,需要的朋友可以參考下2025-02-02

