原來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;
}