标签:inpu 模块 nbsp 行数据 配置文件 数据格式 idt code ide
public class TestCon implements Converter<String, Employee> {
@Override
public Employee convert(String s) {
if(s != null){
String[] vals = s.split("-");
if(vals != null & vals.length == 4){
String lastName = vals[0];
String email = vals[1];
Integer gender = Integer.parseInt(vals[2]);
Department department = new Department();
department.setId(Integer.parseInt(vals[3]));
Employee employee = new Employee(null,lastName,email,gender,department);
return employee;
}
}
return null;
}
}
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<set>
<ref bean="testCon"/>
</set>
</property>
</bean>
<mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"></bean>
@RequestMapping(value = "/emp",method = RequestMethod.POST)
public String save(@Valid Employee employee, BindingResult result,Map<String,Object> map){
if(result.getErrorCount() > 0){
System.out.println("出错了");
for(FieldError error:result.getFieldErrors()){
System.out.println( error.getField() + ":" + error.getDefaultMessage());
}
//若验证出错则转向定制页面
map.put("departments", departmentDao.getDepartments());
return "input";
}
employeeDao.save(employee);
return "redirect:/emps";
}
标签:inpu 模块 nbsp 行数据 配置文件 数据格式 idt code ide
原文地址:https://www.cnblogs.com/bigdatalearn/p/61a7ed6d4d4667065f6103336c1cdbc7.html