您可以使用Spring Tablib
并使用转换标记
${status.value}
要么
要么
关于值属性
The value can either be a plain value to transform (a hard-coded String value in a JSP or a JSP expression),or a JSP EL expression to be evaluated (transforming the result of the expression). Like all of Spring’s JSP tags,this tag is capable of parsing EL expressions itself,on any JSP version.
其API
Provides transformation of variables to String,using an appropriate custom PropertyEditor from BindTag (can only be used inside BindTag)
如果您使用MultiActionController,我建议您使用Dummy Command类作为波纹管
public class Command {
public BigDecimal bigDecimal;
public Date date;
/**
* Other kind of property which needs a PropertyEditor
*/
// getter's and setter's
}
在您的MultiActionController内部
public class AccountController extends MultiActionController {
@Autowired
private Repository accountRepository;
public AccountController() {
/**
* You can externalize this WebBindingInitializer if you want
*
* Here it goes as a anonymous inner class
*/
setWebBindingInitializer(new WebBindingInitializer() {
public void initBinder(WebDataBinder dataBinder,WebRequest request) {
binder.registerCustomEditor(BigDecimal.class,new CustomNumberEditor(BigDecimal.class,numberFormat,true));
binder.registerCustomEditor(Date.class,new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"),true));
}
});
}
public ModelAndView(HttpServletRequest request,HttpServletResponse response) throws Exception {
return new ModelAndView()
.addAllObjects(
createBinder(request,new Command())
.getBindingResult().getModel())
.addObject(accountRepository.findById(Integer.valueOf(request.getParameter("accountId"))));
}
}
在您的JSP中
当您的Target命令没有提供需要在另一个命令中使用的PropertyEditor时,这将很有用.