亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

剛剛開始學習Springboot中添加 @restcontroller報錯 ?

剛剛開始學習Springboot中添加 @restcontroller報錯 ?

白豬掌柜的 2019-08-20 18:14:09
剛剛開始學習Springboot中添加 @restcontroller報錯 
查看完整描述

4 回答

?
不負相思意

TA貢獻1777條經驗 獲得超10個贊

其實簡單粗暴的理解,
就是如果@RestController注解Controller,則返回的內容就是Return 里的內容。
例如:
@RestController
@RequestMapping
public class TestController {
@RequestMapping("/index")
public String index() {
return "user/hello";
}
}
頁面顯示的是user/hello字符串
如果@Controller注解Controller,則返回到指定頁面。
例如:
@Controller
@RequestMapping
public class TestController {
@RequestMapping("/index")
public String index() {
return "user/hello";
}
}
顯示user底下的hello頁面上的內容

查看完整回答
反對 回復 2019-08-24
?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

有兩種方法:
1、return "redirect:/class/list.action?name=value"; 返回的時候直接通過?傳遞值
2、@RequestMapping(value="/delClass.action")
public String delClass(ModelMap model) {
model.addAttribute("name", "value");
return "redirect:/class/list.action";
}
方法2記憶中成功過,這樣傳值沒有太多限制,像map一樣,隨便放就可以

查看完整回答
反對 回復 2019-08-24
?
肥皂起泡泡

TA貢獻1829條經驗 獲得超6個贊

4.0重要的一個新的改進是@RestController注解,它繼承自@Controller注解。4.0之前的版本,Spring MVC的組件都使用@Controller來標識當前類是一個控制器servlet。 使用這個特性,我們可以開發REST服務的時候不需要使用@Controller而專門的@RestController。 當你實現一個RESTful web services的時候,response將一直通過response body發送。為了簡化開發,Spring 4.0提供了一個專門版本的controller。下面我們來看看@RestController實現的定義: @Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Controller @ResponseBody public @interface RestController 官方解釋: A convenience annotation that is itself annotated with @Controller and @ResponseBody. Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default. ...4.0重要的一個新的改進是@RestController注解,它繼承自@Controller注解。4.0之前的版本,Spring MVC的組件都使用@Controller來標識當前類是一個控制器servlet。 使用這個特性,我們可以開發REST服務的時候不需要使用@Controller而專門的@RestController。 當你實現一個RESTful web services的時候,response將一直通過response body發送。為了簡化開發,Spring 4.0提供了一個專門版本的controller。下面我們來看看@RestController實現的定義: @Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Controller @ResponseBody public @interface RestController 官方解釋: A convenience annotation that is itself annotated with @Controller and @ResponseBody. Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default. 注解本身使用@Controller和@ResponseBody注解。使用了這個注解的類會被看作一個controller-使用@RequestMapping的方法有一個默認的@ResponseBody注解。 @ResponseBody – As of version 4.0 this annotation can also be added on the type level in which case is inherited and does not need to be added on the method level. @ResponseBody也可以加到類一級,通過繼承方法一級不需要添加。

查看完整回答
反對 回復 2019-08-24
  • 4 回答
  • 0 關注
  • 3289 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號