天天看点

Mybatis xml中引用枚举值

xml中引用枚举值

${@[email protected]}
${@枚举类全类名@枚举实例.属性名}
           
  • 例:
package com.demo.Sex;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum Sex{

    /**
     * 0=男
     */
    MAN("0"),

    /**
     * 1=女
     */
    WOMAN("1"),

    ;

    private final String value;
}

           
#那么xml文件中应该写
select * from user where sex = '${@[email protected]}'
#如果枚举类是一个内部类的话,则使用`$`符获取
select * from user where sex = '${@[email protected]}'