MyBatis中bind标签用法
1、静态字段/变量/常量
@
class
@field
<bind name="YES" value="@com.example.Example@YES"/>
2、枚举字段值
<bind name="ADD" value="@com.example.ExampleEnum@ADD.getKey"/>
3、内部静态类的静态字段
<bind name="NORMAL" value="@com.example.Example$Inside@NORMAL"/>
4、静态方法
@
class
@``method(args)
<bind name="VALUE" value="@com.example.Example@getValue()"/>
Java类
JAVA普通类
package com.example;
public class Example {
public static final String YES = "1";
public static final String NO = "0";
public static String getValue(){
return "EXAMPLE";
}
/**
* 内部类
*/
public final static class Inside{
public static final int NORMAL = 0;
}
}
JAVA枚举类
package com.example;
public enum ExampleEnum {
ADD(1, "添加"), EDIT(2, "编辑");
private Integer key;
private String value;
ExampleEnum(Integer key, String value) {
this.key = key;
this.value = value;
}
public Integer getKey() {
return key;
}
public String getValue() {
return value;
}
}