1. 程式人生 > >Springboot註解[email protected]和@RestCon

Springboot註解[email protected]和@RestCon

1.使用@Controller 註解,在對應的方法上,檢視解析器可以解析return 的jsp,html頁面,並且跳轉到相應頁面;若返回json等內容到頁面,則需要加@ResponseBody註解 [email protected]註解,相當於@[email protected]兩個註解的結合,返回json資料不需要在方法前面加@ResponseBody註解了,但使用@RestController這個註解,就不能返回jsp,html頁面,檢視解析器無法解析jsp,html頁面 以下是相當於@RestController註解的@[email protected]兩個註解的結合示例程式碼:
@Controller   //處理檔案上傳時,@[email protected]兩個註解的結合
public @ResponseBody String uploadImg(@RequestParam("file") MultipartFile file,
HttpServletRequest request) {
      。。。。。。

}