java制作的属性编辑器_java-Spring属性编辑器仅适用于表单吗?

您可以使用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时,这将很有用.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值