Map params = ActionContext.getContext().getParameters();
原来params是以数组的形式存参数值的,修改后的程序段为:
public Object getModel() {
if(userDTO != null) return userDTO;
Integer pid = null;
String sid = null;
Map params = ActionContext.getContext().getParameters();
if(params.get("id")!=null)
{
sid = ((String[])params.get("id"))[0];
}
if(sid!=null&&!sid.equals("")) {
try {
user = userService.getUserByID(new Integer(sid));
//po 转换成 dto
userDTO = new UserDTO(user);
} catch (Exception e) {
log.error("该用户已不存在",e);
}
}else{
userDTO = new UserDTO();
}
return userDTO;
}
原来params是以数组的形式存参数值的,修改后的程序段为:
public Object getModel() {
if(userDTO != null) return userDTO;
Integer pid = null;
String sid = null;
Map params = ActionContext.getContext().getParameters();
if(params.get("id")!=null)
{
sid = ((String[])params.get("id"))[0];
}
if(sid!=null&&!sid.equals("")) {
try {
user = userService.getUserByID(new Integer(sid));
//po 转换成 dto
userDTO = new UserDTO(user);
} catch (Exception e) {
log.error("该用户已不存在",e);
}
}else{
userDTO = new UserDTO();
}
return userDTO;
}

博客展示了一段Java程序,从ActionContext获取参数,参数以数组形式存储。程序尝试从参数中获取用户ID,将其转换为整数类型,通过ID获取用户信息并转换为DTO对象,若出现异常则记录错误信息,若未获取到ID则创建新的DTO对象。
6115





