저는 Float 값을 바인딩하기 위해 CustomNumberEditorEditor 편집기를 사용하고 있습니다. 값이 숫자가 아닌 경우 가끔 값을 구문 분석하여 오류가 반환되지 않는다고 실험했습니다.Spring CustomNumberEditor가 숫자가 아닌 숫자를 파싱합니다.
- 수 = 10 ...... 다음 = 수가 10이고
- 번호 = 10A는 ...... 그 수가 10 인 오류가 없다 및
- 수가 오류를 없다 10a25 ...... 다음 수는 10이고 수는
은 그래서 에디터가 값을 구문 분석하는 것 유효하지 않기 때문에
내가 편집기를 등록하는 방법은 다음과 같습니다
@InitBinder
public void initBinder(WebDataBinder binder){
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setGroupingUsed(false);
binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, numberFormat, true));
}
감사합니다.
감사합니다. 그러나 사용자 지정 구현을 만들었다면 CustomNumberEditor 클래스를 확장하고 setAsText 메서드 검사를 재정의 할 수 있다고 생각합니다. 값이 숫자 일 경우 super.setAsText – Javi