您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“Mybatis條件if test怎么使用枚舉值”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Mybatis條件if test怎么使用枚舉值”吧!
package com.weather.weatherexpert.common.utils; /** * <p>Title: </p> * <p>Description: </p> * * @Author * @CreateTime */ public enum City { XINZHOU(100002,"忻州"), DATONG(100003,"大同"), TAIYUAN(100001,"太原"); private final Integer code; private final String name; City(Integer value, String desc) { this.code = value; this.name = desc; } public Integer getCode() { return code; } public String getName() { return name; } }
xml:
<!--<if test="cityName == @com.weather.weatherexpert.common.utils.City.XINZHOU@getName"><!–wrong,java.lang.ClassNotFoundException: Unable to resolve class: com.weather.weatherexpert.common.utils.City.XINZHOU–>--> <!--<if test="cityName == @com.weather.weatherexpert.common.utils.City@XINZHOU@getName"><!–wrong,[org.apache.ibatis.ognl.ParseException: Encountered " "@" "@ "" at line 1, column 65.–>--> <if test="cityName == @com.weather.weatherexpert.common.utils.City@XINZHOU.getName"><!--right--> area_table </if> where 1=1 <if test="cityName == @com.weather.weatherexpert.common.utils.City@XINZHOU.getName"><!--right--> and city_name=#{cityName} </if>
package com.weather.weatherexpert.common.utils; /** * <p>Title: </p> * <p>Description: </p> * * @Author * @CreateTime */ public class CityClass { public static enum CityEnum { XINZHOU(100002, "忻州"), DATONG(100003, "大同"), TAIYUAN(100001, "太原"); private final Integer code; private final String name; CityEnum(Integer value, String desc) { this.code = value; this.name = desc; } public Integer getCode() { return code; } public String getName() { return name; } } }
xml:
/* Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'cityName == @com.weather.weatherexpert.common.utils.CityClass@CityEnum.XINZHOU.getName'. Cause: org.apache.ibatis.ognl.OgnlException: Could not get static field CityEnum from class com.weather.weatherexpert.common.utils.CityClass [java.lang.NoSuchFieldException: CityEnum]*/ <if test="cityName == @com.weather.weatherexpert.common.utils.CityClass@CityEnum.XINZHOU.getName"><!--wrong--> area_table </if>
可見,直接定義的枚舉類可以正常使用,在類中定義的枚舉類這樣使用會報錯,可能方法還沒有找到。
如下正確:
<if test="cityName == @com.a.b.c.CityClass$CityEnum@XINZHOU.getName"><!--right--> name = #{username} </if>
<if test="dtEnum == @com.xxx.xxx.TestTypeEnum@HOUR"> DATE_FORMAT(TM,'%Y-%m-%d %H') as keyStr, </if>
HOUR
("hour"),
DAY
("day"),
MONTH
("month"),
YEAR
("year");
到此,相信大家對“Mybatis條件if test怎么使用枚舉值”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。