Skip to content

Commit

Permalink
修正prepare接口在新版MVC上的bug,在createForm提交时,如果有hidden input value且值为空时出错,因此…
Browse files Browse the repository at this point in the history
…将required=false 改为 defaultValue="-1"
  • Loading branch information
calvin1978 committed Jul 3, 2013
1 parent e5b8e30 commit a70cb10
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public String update(@Valid @ModelAttribute("user") User user) {
* 因为仅update()方法的form中有id属性,因此仅在update时实际执行.
*/
@ModelAttribute
public void getUser(@RequestParam(value = "id", required = false) Long id, Model model) {
if (id != null) {
public void getUser(@RequestParam(value = "id", defaultValue = "-1") Long id, Model model) {
if (id != -1) {
model.addAttribute("user", accountService.getUser(id));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public String delete(@PathVariable("id") Long id, RedirectAttributes redirectAtt
* 因为仅update()方法的form中有id属性,因此仅在update时实际执行.
*/
@ModelAttribute
public void getUser(@RequestParam(value = "id", required = false) Long id, Model model) {
if (id != null) {
public void getUser(@RequestParam(value = "id", defaultValue = "-1") Long id, Model model) {
if (id != -1) {
model.addAttribute("user", accountService.getUser(id));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class TaskController {
@Autowired
private TaskService taskService;

@RequestMapping(value = "")
@RequestMapping(method = RequestMethod.GET)
public String list(@RequestParam(value = "page", defaultValue = "1") int pageNumber,
@RequestParam(value = "page.size", defaultValue = PAGE_SIZE) int pageSize,
@RequestParam(value = "sortType", defaultValue = "auto") String sortType, Model model,
Expand Down Expand Up @@ -112,9 +112,9 @@ public String delete(@PathVariable("id") Long id, RedirectAttributes redirectAtt
* 所有RequestMapping方法调用前的Model准备方法, 实现Struts2 Preparable二次部分绑定的效果,先根据form的id从数据库查出Task对象,再把Form提交的内容绑定到该对象上。
* 因为仅update()方法的form中有id属性,因此仅在update时实际执行.
*/
@ModelAttribute()
public void getTask(@RequestParam(value = "id", required = false) Long id, Model model) {
if (id != null) {
@ModelAttribute
public void getTask(@RequestParam(value = "id", defaultValue = "-1") Long id, Model model) {
if (id != -1) {
model.addAttribute("task", taskService.getTask(id));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public String checkLoginName(@RequestParam("oldLoginName") String oldLoginName,
* 因为仅update()方法的form中有id属性,因此仅在update时实际执行.
*/
@ModelAttribute
public void getUser(@RequestParam(value = "id", required = false) Long id, Model model) {
if (id != null) {
public void getUser(@RequestParam(value = "id", defaultValue = "-1") Long id, Model model) {
if (id != -1) {
model.addAttribute("user", accountService.getUser(id));
}
}
Expand Down

0 comments on commit a70cb10

Please sign in to comment.