Controller的使用

注: 通常程式開發後端需要提供的是rest接口,傳回一些json格式給前端,盡量不要使用模闆的方式,使用模闆會
在性能上帶來很大的損耗.
參數的擷取
知識點整理
- @Restcontroller和@controller的差別
- 如果使用@Restcontroller注解,就不能傳回jsp,html頁面,視圖解析器無法解析jsp,html頁面
- @Controller注解,若傳回json等内容到頁面,則需要加@Response注解,而且需要頁面傳回
-
url映射可以是以集合的形式擷取
例:@RequestMapping(value ={"/hello/","/hi"})
-
擷取一個id值
:@RequestMapping(value ={"/hello/{id}",method=RequestMethod.GET})
@PathVariable("id") 擷取操作 導航欄: /hello/12
也可以 12/hello
@RequestParam("id") 擷取操作 導航欄