最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Mybatis條件if test如何使用枚舉值

 更新時(shí)間:2022年06月06日 16:38:48   作者:二十六畫(huà)生的博客  
這篇文章主要介紹了Mybatis條件if test如何使用枚舉值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Mybatis條件if test使用枚舉值

1.正確

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">&lt;!&ndash;wrong,java.lang.ClassNotFoundException: Unable to resolve class: com.weather.weatherexpert.common.utils.City.XINZHOU&ndash;&gt;-->
<!--<if test="cityName == @com.weather.weatherexpert.common.utils.City@XINZHOU@getName">&lt;!&ndash;wrong,[org.apache.ibatis.ognl.ParseException: Encountered " "@" "@ "" at line 1, column 65.&ndash;&gt;-->
<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>	

2.錯(cuò)誤

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>	

可見(jiàn),直接定義的枚舉類(lèi)可以正常使用,在類(lèi)中定義的枚舉類(lèi)這樣使用會(huì)報(bào)錯(cuò),可能方法還沒(méi)有找到。

如下正確:

 <if test="cityName == @com.a.b.c.CityClass$CityEnum@XINZHOU.getName"><!--right-->
  name = #{username}
 </if>

Mybatis里使用枚舉Enum判斷

<if test="dtEnum == @com.xxx.xxx.TestTypeEnum@HOUR">
? DATE_FORMAT(TM,'%Y-%m-%d %H') as keyStr,
</if>

TestTypeEnum定義如下

  • HOUR("hour"),
  • DAY("day"),
  • MONTH("month"),
  • YEAR("year");

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

江永县| 佛山市| 辉南县| 瓦房店市| 鄂托克前旗| 富裕县| 古浪县| 广东省| 盖州市| 乌拉特前旗| 深州市| 西吉县| 冷水江市| 隆化县| 家居| 遂宁市| 石狮市| 吴忠市| 墨脱县| 灌阳县| 青州市| 黄石市| 南部县| 松阳县| 彝良县| 甘南县| 平塘县| 兴城市| 平阴县| 两当县| 柘荣县| 惠水县| 西青区| 东兰县| 长岭县| 嘉定区| 长汀县| 滨州市| 永昌县| 香格里拉县| 荣昌县|