Skip to content

Instantly share code, notes, and snippets.

@arahansa
Last active July 27, 2016 22:03
Show Gist options
  • Save arahansa/1985eb043a1c8afd656b57af13aaad29 to your computer and use it in GitHub Desktop.
Save arahansa/1985eb043a1c8afd656b57af13aaad29 to your computer and use it in GitHub Desktop.
프로퍼티 에디터
@Inject
Provider<FakeDbUserPropertyEditor> fakeDbUserPropertyEditorProvider;
@InitBinder
public void initBinder(WebDataBinder dataBinder){
dataBinder.registerCustomEditor(Level.class, new LevelPropertyEditor());
// 커스텀 서비스를 넣어주는 방법
dataBinder.registerCustomEditor(int.class, "age", new MinMaxPropertyEditor(0, 200));
// 02. 모조 방법
dataBinder.registerCustomEditor(FakeUser.class, new FakeUserPropertyEditor());
// 03. prototype 방법
dataBinder.registerCustomEditor(FakeDBUser.class, fakeDbUserPropertyEditorProvider.get());
}
public class LevelPropertyEditor extends PropertyEditorSupport {
public String getAsText(){
return String.valueOf(((Level)this.getValue()).intValue());
}
public void setAsText(String text) throws IllegalArgumentException{
this.setValue(Level.valueOf(Integer.parseInt(text.trim())));
}
// @init binder 가 필요하다
// 적용대상 @RequestParam, @CookieValue, @RequestHeader, @PathVaraible, @ModelAttribute
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment