- Add the controller in
@InitBinder
public void initBinder(WebDataBinder binder){
binder.registerCustomEditor(BigDecimal.class, new BigDecimalEditor());//BigDecimalEditor为转换器
}
- Add class
/**
* created by lxy 2019年2月12日10:56:50
*/
public class BigDecimalEditor extends PropertyEditorSupport {
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (StringUtils.isNotEmpty(text)) {
if (text.contains(",")) {
text=text.replaceAll(",", "");
}
} else {
text = "0";
}
setValue(new BigDecimal(text));
}
}