SpringBoot服務(wù)訪問路徑動態(tài)處理方式
SpringBoot服務(wù)訪問路徑動態(tài)處理
@RestController
public class MainController {
@RequestMapping(value = "/echo/{message}", method = RequestMethod.GET)
public String echo(@PathVariable("message") String msg) {
return "【ECHO】" + msg;
}
}注意:
message是前臺傳過來的動態(tài)參數(shù),通過@PathVariable注解將message注入形參msg,然后可在方法里做靈活業(yè)務(wù)處理。
SpringBoot訪問路徑問題
路徑重復(fù)問題
如果配置了context-path
server.servlet.context-path=/mmrlc
同時在某個Controller類上也標(biāo)記了請求URI
@RequestMapping("/mmrlc")
public class MigrationController {則會造成路徑重復(fù);
請求路徑則變成了 http://localhost:8080/mmrlc/mmrlc/**
"/"問題
@RequestMapping("/mmrlc")
public class MigrationController {與
@RequestMapping("/mmrlc/")
public class MigrationController {訪問路徑不同
前者的默認(rèn)訪問路徑為 http://localhost:8080/mmrlc
后者的默認(rèn)訪問路徑為 http://localhost:8080/mmrlc/
最后一定要加“/” ,否則404 Not Found
RequestMapping問題
所有的控制器方法都要標(biāo)注@RequestMapping注解
@Controller
@RequestMapping("/mmrlc")
public class MigrationController {
@RequestMapping
public ModelAndView demo(){
ModelAndView mv = new ModelAndView();
mv.addObject("username","xiaobai");
mv.setViewName("index");
return mv;
}demo方法沒有設(shè)置特定路徑,但也要標(biāo)注@RequestMapping,否則ioc容器無法訪問
<input src=“…”> 問題
使用SpringBoot時,模板文件index.html位于templates文件夾下
vue.js位于 static文件下的js文件夾中
瀏覽器會按照src路徑發(fā)送請求尋找vue.js,所以src路徑中不寫static,同時注意請求路徑避免和
@RequestMapping(“/{name1}/{name2}”) 重復(fù)
如果出現(xiàn)vue.js not found, 可以按路徑在瀏覽器地址欄中請求一下,從而尋找原因
<script type="text/javascript" src="../js/vue.js"></script>
icon問題
icon圖標(biāo)應(yīng)該放置在static目錄下,名稱為favicon.ico;同時要在html頁面中引入才能生效
<head> <meta charset="utf-8"> <link href="favicon.ico" rel="external nofollow" rel="shortcut icon" type="image/x-icon" /> </head>
總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
java定時任務(wù)實(shí)現(xiàn)的4種方式小結(jié)
這篇文章主要介紹了java定時任務(wù)實(shí)現(xiàn)的4種方式小結(jié),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
Maven 搭建SpringMVC+Hibernate項(xiàng)目詳解
本文主要介紹Maven 搭建SpringMVC+Hibernate的知識,這里整理了詳細(xì)的資料,并附示例代碼,有興趣的小伙伴可以參考下2016-09-09
java中ArrayList 、LinkList的區(qū)別分析
java中ArrayList 、LinkList的區(qū)別分析,需要的朋友可以參考一下2013-05-05

