1. 程式人生 > >mybatis中XML檔案列舉比較用法

mybatis中XML檔案列舉比較用法

package com.farer.collection.enums; 

/**
 * @Title:  AssetTypeEnum.java   
 * @Package com.farer.collection.enums   
 * @Description:  
 * @author: huafu.su     
 * @date: 2018年8月14日 下午5:56:00
 */
public enum AssetTypeEnum implements Annotation{
	 
	one("1","one"),
	two("2","two"),
	three("3","three");
	private String value;
	private String lable;
	 
	
	AssetTypeEnum(String value, String lable) {
		this.value = value;
		this.lable = lable;
	}
	
	@Override
	public Class<? extends Annotation> annotationType() {
		return AssetTypeEnum.class;
	}
	 
	/**
	 * @Title: getLableByValue   
	 * @Description: 根據值獲取說明   
	 * @param value
	 * @return String  
	 * @author: huafu.su
	 */
	public static String getLableByValue(String value){
		for (AssetTypeEnum bt : AssetTypeEnum.values()) {
			if(bt.getValue().equals(value)){
				return bt.getLable();
			}
		}
		return value;
	}
	
	/**
	 * @Title: getLableByValue   
	 * @Description: 根據說明獲取值 
	 * @param lable
	 * @return String  
	 * @author: huafu.su
	 */
	public static String getValueByLable(String lable){
		for (AssetTypeEnum bt : AssetTypeEnum.values()) {
			if(bt.getLable().equals(lable)){
				return bt.getValue();
			}
		}
		return lable;
	}
	
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getLable() {
		return lable;
	}
	public void setLable(String lable) {
		this.lable = lable;
	}
}
 

/**
 * @Title:  HouseMapper.java   
 * @Package com.farer.collection.app.mapper   
 * @Description: Mapper
 * @author: huafu.su     
 * @date: 2018年8月15日 下午4:24:41
 */
public interface HouseMapper { 
 

    HouseVo selectByPrimaryKey(@Param("houseCode") String houseCode, @Param("enum") AssetTypeEnum enum); 
     
}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.farer.scheduled.building.mapper.HouseMapper" >
 <resultMap id="BaseResultMap" type="com.farer.collection.HouseVo" >
    <id column="house_ID" property="houseId" jdbcType="INTEGER" />
   <result column="house_code" property="houseCode" jdbcType="VARCHAR" />
   <result column="house_floor" property="houseFloor" jdbcType="VARCHAR" />
   <result column="house_number" property="houseNumber" jdbcType="VARCHAR" />
   <result column="building_code" property="buildingCode" jdbcType="VARCHAR" />
  </resultMap>
  
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select house_ID,house_number,house_floor, house_code,building_code  from house where 1=1
    <if test="houseCode!=null and houseCode!=''">
      and  house_code =#{houseCode}
    </if>
	<if test="
[email protected]
@one"> and enum =#{enum} </if> </select> </mapper>