看《看透springMvc源代码分析与实践》@ControllerAdvice中例子 不能正常运行,访问时报404,不知道什么原因
代码:
@ControllerAdvice
public class HahaResponseBodyAdvice implements ResponseBodyAdvice<String> {
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> con-verterType) {
return true;
}
@Override
public String beforeBodyWrite(String body, MethodParameter returnType, MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType,
ServerHttpRequest request, ServerHttpResponse response) {
return body+"<br/> haha,this is been modified";
}
}
//com.excelib.controller.GoController
//在处理器返回值前暂时添加@ResponseBody注释
@RequestMapping(value={"/index","/"},method= {RequestMethod.GET})
@ResponseBody public String index(HttpServletRequest request, Model model) throws Exception {
model.addAttribute("msg", "Go Go Go!");
return "go.jsp";
}
springmvc 配置文件
<mvc:annotation-driven />
<context:component-scan base-package="com.happy1" >
</context:component-scan>
需要maven-demo-web?你用的tomcat部署的?
不是的话,去掉试试。
是的,这是我写demo项目