一、第一个是(controller和RequestMapping)
记住这个组合拳(controller和RequestMapping)和(RestController和PostMapping(GetMapping等))
1)如果使用@RestController注解Controller,则Controller中的方法无法返回jsp者html页面,配置的视图解析器InternalResourceViewResolver不能作用,返回的内容就是Return里的内容。
如果:下面会返回hello这个字符串
@RestController
@RequestMapping("articles")
public class ArticleController {
//这里为什么用POST请求,因为在前面的接口说明的用POST请求
//对于另外的参数,我们建立一个vo下面的PageParams类专门表示参数
@PostMapping
public String listArticle(@RequestBody PageParams pageParams) {
//对于接受的参数问题,这里用的是RequestBody来接受
return "hello";
}
}
同时要记住controller加上responsebody是和上面这种情况一样的效果
2. 如果需要返回到指定页面,则需要用@Controller配合视图解析器
InternalResourceViewResolver才行。
使用Controller和RequestMapping时候,会返回页面。
如下面会返回hello.html页面
@RestController
@RequestMapping("articles")
public class ArticleController {
//这里为什么用POST请求,因为在前面的接口说明的用POST请求
//对于另外的参数,我们建立一个vo下面的PageParams类专门表示参数
@PostMapping
public String listArticle(@RequestBody PageParams pageParams) {
//对于接受的参数问题,这里用的是RequestBody来接受
return "hello";
}
}