나는 이것이 간단한 문제라고 느낀다. 그러나 나에게 도움이되는 것들은 없다. 열거 형을 가지고있는 이유는 Java가 열거 형을 허용하지 않기 때문에 문자열 생성자가 있습니다. 문자열 생성자없이 AA, AB, 2C를 직접 시도했지만 오류가 발생합니다. 기존 enum에 대해서는 C ("2C")를 추가하고 있습니다. 자바 MyBatis 열거 형 문자열 값
public enum TestEnum{
AA("AA"), AB("AB"), C("2C");
private String display;
private TestEnum(String display) {
this.display = display;
}
public String toString() {
return display;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
public String getName() {
return display;
}
지금 내가 병합이 존재하고 매퍼에 PARAM 중 하나가 TestEnum입니다 않는 MyBatis로 매퍼가 있습니다. 지금까지 열거 형 값과 문자열 값이 동일하기 때문에이 방법이 유용했지만 C ("2C")를 추가했습니다. 지금은 mybaits을 사용하여 테이블에 2C를 삽입 할, 그러나 그것은 항상
merge into text t
using (select #{id} as id from dual) d on (d.id = t.id)
when matched then
update set
appId = #{applId},
src = #{testEnum}
testEnum가 C를 삽입 C.
삽입, 그래서 내가 #이 {testEnum.toString은()} 나을 준에 더 게터가 없음을 변경 속성 이름 toString() 오류. 나는 # {testEnum.display}와 # {testEnum.name}을 시도했지만 C가 삽입되는 반면 C는 2C를 삽입하려고합니다. 이 문제를 처리하는 더 쉬운 방법을 알고 계십니까?모델 객체를 변경하지 않고 mybatis 매퍼에서 수행 할 수있는 방법이 있습니다.이 객체가 많은 장소에서 사용되고 있기 때문에 TestEnum보다는 String을 전달하는 모델 객체를 변경하고 싶지 않습니다. 그런 다음
public static TestEnum fromDisplay(String display){
for (TestEnum v : TestEnum.values()){
if (v.getDisplay().equals(display)){
return v;
}
}
return null;
}
: 당신의 도움 :)에 대한
덕분에
엄청나게 필요한 것. 고마워요. –