Spring MVC如何创建没有return(String)视图的控制器?

sok*_*kid 0 spring controller

以下是我的样本控制器.

@RequestMapping(value = "/validate", method = RequestMethod.POST)
public String validatePage1 (@ModelAttribute("page1")
                        Page1 pg1, BindingResult result) {

    System.out.println("Value1:" + pg1.getVal1() + 
                "Value2:" + pg1.getVal2());

    return "page2"; // I don't want to take any action (page navigation) here
}

@RequestMapping("/page1")
public ModelAndView pageShow() {

    return new ModelAndView("page1", "command", new Page1());
}
Run Code Online (Sandbox Code Playgroud)

现在问题是,当Spring框架调用方法(validatePage1)时,我不想在客户端采取任何操作,该怎么办?

实际上我在加载时已经在我的客户端加载了所有必需的页面(以避免重复的页面加载),所以我不想在客户端采取任何页面导航操作,我只是想做'数据绑定'来完成我的服务器端的业务逻辑.

当我在"validatePage1()"中返回""空字符串时,Spring框架抛出异常"请求处理失败;嵌套异常是org.apache.tiles.definition.NoSuchDefinitionException:",因为我使用的是tile,我必须稍后删除tile配置因为我在第一次加载时加载所有文件.

Ant*_*ton 6

您可以按照此处的建议将方法设置为返回void并对其进行注释.无需处理等@ResponseBodyHttpServletResponse