您好,登錄后才能下訂單哦!
本篇內容主要講解“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怎么使用枚舉值”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。