轉(zhuǎn)換器:converter
格式化:Format
在“校驗器”、“文件上傳”中的例子中都使用了數(shù)據(jù)綁定(將表單數(shù)據(jù)綁定到bean對象中),例如:
@RequestMapping(value = "/output")
public String output(Person person, Model model) {
model.addAttribute("person", person);
return "hello/output";
}
表單的數(shù)據(jù)都是String類型,如果我們的bean類中的屬性是其他類型,例如Date、int,這時候就需要寫一個工具,將String轉(zhuǎn)換成Date、int。
這就是轉(zhuǎn)換器與格式化做的事情:類型轉(zhuǎn)換。字符串轉(zhuǎn)換成數(shù)字類型是內(nèi)置的。
資料:
9. Validation, Data Binding, and Type Conversion
Spring MVC request parameter conversion with minimal configuration
Introduction to Spring Converters and Formatters
更多建議: