Last active
July 27, 2016 22:03
-
-
Save arahansa/1985eb043a1c8afd656b57af13aaad29 to your computer and use it in GitHub Desktop.
프로퍼티 에디터
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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