@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
binder.registerCustomEditor(SystemInfo.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (!StringUtils.hasText(text)) {
return;
}
{
Long systemInfoId = Long.valueOf(text);
SystemInfo systemInfo = systemInfoService.findById(systemInfoId);
setValue(systemInfo);
}
}
});
binder.registerCustomEditor(Category.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (!StringUtils.hasText(text)) {
return;
} else {
Long categoryId = Long.valueOf(text);
Category category = categoryService.findById(categoryId);
setValue(category);
}
}
});
}
<form:form modelAttribute="categoryEditForm" id="categoryForm" method="post" action="saveOrUpdate.do">
<form:hidden path="category.objectId" />
<input type="hidden" name="category.parent" value="${categoryEditForm.category.parent.objectId}"/>
<input type="hidden" name="category.systemInfo" value="${categoryEditForm.category.systemInfo.objectId }"/>
<div class="area">
<div class="areaTitle">
<div class="inner">
<label>Category Information Form</label>
<div class="clear"></div>
</div>
</div>
</div>
<div class="areaBody">
<table class="formTable">
<tbody>
<tr>
<td colspan="4">
<span class="button"><span><a href="javascript:sumbit();" class="btnSave">Submit</a></span></span>
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td align="right">Parent Category Name:</td>
<td colspan="3"><form:input path="category.parent.name.fullName" readonly="true" id="parentCategory" cssClass="input readOnly" /></td>
</tr>
<tr>
<td align="right">Current Category Name:</td>
<td><form:input path="category.name.fullName" id="categoryName" cssClass="input"/></td>
<td align="right">description:</td>
<td><form:input path="category.description" id="description" cssClass="input"/></td>
</tr>
</tbody>
</table>
</div>
</form:form>
分享到:
相关推荐
本篇文章主要介绍了详解SpringMVC注解@initbinder解决类型转换问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要介绍了spring mvc使用@InitBinder标签对表单数据绑定的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面。Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块。Spring MVC4是当前zuixin的版本,在众多特性上有了进一步的提升。, 在精通Spring...
Spring MVC 之@ModelAttribute使用.rar
主要介绍了SpringMVC的@InitBinder参数转换代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
在Spring mvc中,注解@ModelAttribute是一个非常常用的注解,下面这篇文章主要给大家介绍了关于spring mvc中@ModelAttribute注解的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下。
主要给大家介绍了关于spring mvc中注解@ModelAttribute妙用的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Android具有一定的参考学习价值,需要的朋友们下面来一起看看吧。
本文详细介绍spring MVC的原理和开发心得体会。
精通Spring MVC 4 中文
1.创建第一个 Spring MVC 程序案例 2.Spring MVC @RequestMapping 注解案例 3.Spring MVC 请求参数的获取案例 4.Spring MVC 域对象共享数据案例 5.Spring MVC @ModelAttribute 注解案例 6.Spring MVC 国际化案例 7....
本文主要介绍了spring mvc中的@PathVariable获得请求url中的动态参数的代码。具有很好的参考价值,下面跟着小编一起来看下吧
Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于...
Spring MVC是Spring框架中用于Web应用快速开发的一个模块,其中的MVC是Model-View-Controller的缩写。作为当今业界最主流的Web开发框架,Spring MVC已经成为当前最热门的开发技能,同时也广泛用于桌面开发领域。 ...
《Spring MVC+MyBatis开发从入门到项目实战》适用于拥有Java基础的软件开发人员学习框架开发,也适用于大中专院校在校师生学习开发技术,以及软件从业实习生提升框架开发技术水平,也可作为高等院校计算机及相关专业...
Spring MVC所需jar包,包含java开发中 Spring MVC架构中最常用的jar包
这篇文章将教你快速地上手使用 Spring 框架. 如果你手上有一本《Spring in Action》, 那么你最好从第三部分"Spring 在 Web 层的应用--建立 Web 层"开始看, 否则那将是一场恶梦! 首先, 我需要在你心里建立起 Spring...