getArguments()
方法的参数序列是什么
MessageSourceResolvable 界面,带有@Size
批注?
Employee.java
public class Employee {
private int id;
@Size(message = "length exceeds : name",max = CommonConstants.NAME)
@NotBlank(message="should not be null")
private String name;
@Size(max = CommonConstants.ROLE, min=1, message = "length exceeds : role")
private String role;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
EmployeeController.java
@Controller
public class EmployeeController {
private static final Logger logger = LoggerFactory
.getLogger(EmployeeController.class);
private Map<Integer, Employee> emps = null;
@RequestMapping(value = "/emp/save.do", method = RequestMethod.POST)
public String saveEmployeeAction(
@Valid Employee employee,
BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) {
logger.info("Returning empSave.jsp page");
List<FieldError> errorslist = bindingResult.getFieldErrors();
for (FieldError error : errorslist) {
Object[] args=error.getArguments();
System.out.println();
for (Object object : args) {
System.out.println(object.toString());
}
}
return "empSave";
}
logger.info("Returning empSaveSuccess.jsp page");
model.addAttribute("emp", employee);
emps.put(employee.getId(), employee);
return "empSaveSuccess";
}
}
CommonConstants.java
public class CommonConstants {
public static final int NAME=4;
public static final int ROLE=2;
}
输入
name="xyzxyzxyzxyzxyzxyzxyzxyzxyzxyz"
role="CEO"
控制台输出
arg : org.springframework.context.support.DefaultMessageSourceResolvable: codes [employee.role,role]; arguments []; default message [role]
arg : 2
arg : 1
arg : org.springframework.context.support.DefaultMessageSourceResolvable: codes [employee.name,name]; arguments []; default message [name]
arg : 4
arg : 0
在第一个输出中,2
是max
,1
是角色的min
批注的@Size
参数值(请参阅Employee.java)
和
在第二个输出中,4
是max
,0
是 name 的min
批注的@Size
参数值(请参阅Employee。 .java)
现在的问题是我从 MessageSourceResolvable ??
的getArguments()
方法中获得这些参数的顺序
即使我更改了参数的顺序,此顺序也一样吗?