首頁 Java java教程 SpringMVC學習系列(3) 之 URL請求到Action的映射規則

SpringMVC學習系列(3) 之 URL請求到Action的映射規則

Mar 03, 2017 am 10:49 AM
springmvc

在系列(SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則)中我們展示了一個簡單的get請求,並回傳了一個簡單的helloworld頁面。本篇我們來學習如何來設定一個action的url映射規則。

在系列(SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則)中我們在HelloWorldController上配置了一個@RequestMapping(value = "/helloworld")這表示對該controller的所有action請求必須是以"/helloworld」開始。

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.URL路徑映射

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.對一個action配置多個URL映射:

我們把上一篇中的HelloWorldController的index() action方法的@ RequestMapping更改為@RequestMapping(value={"/index", "/hello"}, method = {RequestMethod.GET}),這表示對該action配置了/index和/hello兩個對應。執行測試,如下:

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則

可以看到/helloworld/hello要求也成功匹配。

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.URL請求參數映射:

這在查詢的時候常用到,例如我們根據id或編號來取得某筆記錄。

在HelloWorldController新增getDetail的action,程式碼如下:

@RequestMapping(value="/detail/{id}", method = {RequestMethod.GET})public ModelAndView getDetail(@PathVariable(value="id") Integer id){
    
    ModelAndView modelAndView = new ModelAndView();  
    modelAndView.addObject("id", id);  
    modelAndView.setViewName("detail");  
    return modelAndView;
}
登入後複製


其中value="/detail/{id}",中的{id}為佔位符表示可以對應請求為/detail/xxxx 的URL如:/detail/SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則SpringMVC學習系列(3) 之 URL請求到Action的映射規則等。

方法的參數@PathVariable(value="id") Integer id 用於將URL中佔位符所對應變數對應到參數id上,@PathVariable(value="id") 中value的值要和占位符/{id}大括號中的值一致。

在views中加入detail.jsp視圖,用於將取得到的id值展示出來。檢視內容如下:

<%@ page language="java" contentType="text/html; charset=UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"
    pageEncoding="UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"%><!DOCTYPE html PUBLIC "-//WSpringMVC學習系列(3) 之 URL請求到Action的映射規則C//DTD HTML SpringMVC學習系列(3) 之 URL請求到Action的映射規則.0SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則 Transitional//EN" "http://www.wSpringMVC學習系列(3) 之 URL請求到Action的映射規則.org/TR/htmlSpringMVC學習系列(3) 之 URL請求到Action的映射規則/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"><title>Insert title here</title></head><body>
    ${id}</body></html>
登入後複製


執行測試,請求URL位址http://localhost:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/detail/SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則SpringMVC學習系列(3) 之 URL請求到Action的映射規則  ,結果如下:

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則

可以看到已經正確的顯示了我們請求的id。

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.SpringMVC學習系列(3) 之 URL請求到Action的映射規則.URL通配符映射:

我們也可以透過通配符對URL映射進行配置,通配符有「?」和「*」兩個字元。其中“?”表示SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則個字符,“*”表示匹配多個字符,“**”表示匹配0個或多個路徑。

例如:

“/helloworld/index?”可以匹配“/helloworld/indexA”、“/helloworld/indexB”,但不能匹配“/helloworld/index”也不能匹配“ /helloworld/indexAA”;

“/helloworld/index*”可以匹配“/helloworld/index”、“/helloworld/indexA”、“/helloworld/indexAA”但不能匹配“/helloworld/index/ A」;

「/helloworld/index/*」可以搭配「/helloworld/index/」、「/helloworld/index/A」、「/helloworld/index/AA」、「/helloworld/index /AB”但不能匹配    “/helloworld/index”、“/helloworld/index/A/B”;

“/helloworld/index/**”可以匹配“/helloworld/index/”下的多有子路徑,例如:“/helloworld/index/A/B/C/D”;

如果現在有“/helloworld/index”和“/helloworld/*”,如果請求位址為“ /helloworld/index」那麼將如何匹配? Spring MVC會按照最長匹配優先原則(即和映射配置中哪個匹配的最多)來匹配,所以會匹配“/helloworld/index”,下面來做測試:

在HelloWorldController添加一個urlTest的action,內容如下:

@RequestMapping(value="/*", method = {RequestMethod.GET})public ModelAndView urlTest(){
    
    ModelAndView modelAndView = new ModelAndView();   
    modelAndView.setViewName("urltest");  
    return modelAndView;
}
登入後複製


在views資料夾中新增加一個視圖urltest.jsp,為了和index.jsp做區別urltest.jsp的內容如下:

<%@ page language="java" contentType="text/html; charset=UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"
    pageEncoding="UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"%><!DOCTYPE html PUBLIC "-//WSpringMVC學習系列(3) 之 URL請求到Action的映射規則C//DTD HTML SpringMVC學習系列(3) 之 URL請求到Action的映射規則.0SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則 Transitional//EN" 
    "http://www.wSpringMVC學習系列(3) 之 URL請求到Action的映射規則.org/TR/htmlSpringMVC學習系列(3) 之 URL請求到Action的映射規則/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則">
    <title>Insert title here</title>
    </head>
    <body>
    urlTest!</body></html>
登入後複製


請求http://localhost:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/index檢視結果:

SpringMVC學習系列(3) 之 URL請求到Action的映射規則

#可以看出映射的是index對應的action。

請http://localhost:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/AAA查看結果:

SpringMVC學習系列(3) 之 URL請求到Action的映射規則

可以看出對應的是urlTest對應的action。

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.SpringMVC學習系列(3) 之 URL請求到Action的映射規則.URL正規表示式對應:

Spring MVC还支持正则表达式方式的映射配置,我们通过一个测试来展示:

在HelloWorldController添加一个regUrlTest的action,内容如下:

@RequestMapping(value="/reg/{name:\\w+}-{age:\\d+}", 
method = {RequestMethod.GET})public ModelAndView regUrlTest(@PathVariable(value="name") String name, 
@PathVariable(value="age") Integer age){
    
    ModelAndView modelAndView = new ModelAndView();   
    modelAndView.addObject("name", name); 
    modelAndView.addObject("age", age); 
    modelAndView.setViewName("regurltest");  
    return modelAndView;
}
登入後複製


在views文件夹中新加一个视图regurltest.jsp内容如下:

<%@ page language="java" contentType="text/html; charset=UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"
    pageEncoding="UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"%><!DOCTYPE html PUBLIC "-//WSpringMVC學習系列(3) 之 URL請求到Action的映射規則C//DTD HTML SpringMVC學習系列(3) 之 URL請求到Action的映射規則.0SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則 Transitional//EN" 
    "http://www.wSpringMVC學習系列(3) 之 URL請求到Action的映射規則.org/TR/htmlSpringMVC學習系列(3) 之 URL請求到Action的映射規則/loose.dtd"><html>
    <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則">
    <title>Insert title here</title></head><body>
    ${name}-${age}</body></html>
登入後複製


请求http://www.php.cn/:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/reg/Hanmeimei-SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則SpringMVC學習系列(3) 之 URL請求到Action的映射規則查看结果:

SpringMVC學習系列(3) 之 URL請求到Action的映射規則

请求http://www.php.cn/:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/reg/Hanmeimei-Lilei查看结果(会发现找不到对应的action返回SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則):

SpringMVC學習系列(3) 之 URL請求到Action的映射規則

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.限制action所接受的请求方式(get或post):

之前我们在HelloWorldController的index() action方法上配置的为@RequestMapping(value="/*", method = {RequestMethod.GET})我们把它改为@RequestMapping(value="/*", method = {RequestMethod.POST})再次请求http://www.php.cn/:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/index试一下:

SpringMVC學習系列(3) 之 URL請求到Action的映射規則

这里可以看到结果映射到了urlTest这个action,这是因为我们在urlTest上配置的为@RequestMapping(value="/*", method = {RequestMethod.GET}),当index这个action映射不在符合时便映射到了urlTest。

我们也可以这样配置@RequestMapping(value="/*", method = {RequestMethod.GET, RequestMethod.POST})表示该action可以接受get或post请求,不过更简单的是不对method做配置则默认支持所有请求方式。

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.限制action所接受请求的参数:

我们可以为某个action指定映射的请求中必须包含某参数,或必须不包含某参数,或者某参数必须等于某个值,或者某参数必须不等于某个值这些限制。

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.指定映射请求必须包含某参数:

在HelloWorldController添加一个paramsTest的action,内容如下:

@RequestMapping(value="/paramstest", params="example", 
method = {RequestMethod.GET})public ModelAndView paramsTest(){
    
    ModelAndView modelAndView = new ModelAndView();   
    modelAndView.setViewName("paramstest");  
    return modelAndView;
}
登入後複製


在views文件夹中新加一个视图paramstest.jsp内容如下:

<%@ page language="java" contentType="text/html; charset=UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"
    pageEncoding="UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"%><!DOCTYPE html PUBLIC "-//WSpringMVC學習系列(3) 之 URL請求到Action的映射規則C//DTD HTML SpringMVC學習系列(3) 之 URL請求到Action的映射規則.0SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則 Transitional//EN" 
    "http://www.wSpringMVC學習系列(3) 之 URL請求到Action的映射規則.org/TR/htmlSpringMVC學習系列(3) 之 URL請求到Action的映射規則/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; 
    charset=UTF-SpringMVC學習系列(3) 之 URL請求到Action的映射規則"><title>Insert title here</title></head><body>
    paramstest!</body></html>
登入後複製


请求http://www.php.cn/:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/paramstest查看结果:

SpringMVC學習系列(3) 之 URL請求到Action的映射規則

这里可以看到没有找到paramsTest这个action结果还是映射到了urlTest这个action。

请求http://www.php.cn/:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/paramstest?example查看结果:

SpringMVC學習系列(3) 之 URL請求到Action的映射規則

这次可以看到请求映射到了paramsTest这个action。

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.指定映射请求必须包含某参数:

把刚才添加的paramsTest的@RequestMapping(value="/paramstest", params="example", method = {RequestMethod.GET}) 改为@RequestMapping(value="/paramstest", params="!example", method = {RequestMethod.GET})

重新请求http://www.php.cn/:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/paramstest?example查看结果:

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則0

可以看到又没有找到paramsTest这个action而映射到了urlTest这个action。

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.SpringMVC學習系列(3) 之 URL請求到Action的映射規則.指定映射请求中或者某参数必须等于某个值:

把刚才添加的paramsTest的@RequestMapping(value="/paramstest", params="example", method = {RequestMethod.GET}) 改为@RequestMapping(value="/paramstest", params="example=AAA", method = {RequestMethod.GET})

請求http://www.php.cn/:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/paramstest?example=BBB查看結果:

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則

可以看到沒有找到paramsTest這個action而映射到了urlTest這個action。

請求http://localhost:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/paramstest?example=BBB檢視結果:

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則

這次可以看到請求對應到了paramsTest這個action。

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.SpringMVC學習系列(3) 之 URL請求到Action的映射規則.指定映射請求中或某參數必須等於某個值:

把剛才加的paramsTest的@RequestMapping(value="/paramstest", params="example", method = {RequestMethod.GET}) 改為@RequestMapping(value="/paramstest", params="example!=AAA", method = {RequestMethod.GET})

請http://localhost:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/paramstest?example=AAA查看結果:

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則SpringMVC學習系列(3) 之 URL請求到Action的映射規則

可以看到請求映射到了paramsTest這個action。

請求http://localhost:SpringMVC學習系列(3) 之 URL請求到Action的映射規則0SpringMVC學習系列(3) 之 URL請求到Action的映射規則0/SpringMVCLesson/helloworld/paramstest?example=AAA查看結果:

SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則SpringMVC學習系列(3) 之 URL請求到Action的映射規則

可以看到沒有找到paramsTest這個action而映射到了urlTest這個action。

註:當我們為params指定多個參數時如:params={"exampleSpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則", "exampleSpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則"},表示的是and關係,即兩個參數限制必須同時滿足。

 

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.限制action所接受請求頭參數:

同限制action所接受的請求參數一樣,我們也可以為某個action指定映射的請求頭中必須包含某一參數,或必須不包含某參數,或某參數必須等於某個值,或某參數必須不等於某個值這些限制。

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.指定映射請求頭必須包含某個參數:

@RequestMapping(value="/headerTest", headers = "example")。與限制請求參數是一樣的,可以參考上面的範例進行測試。

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則.指定映射請求頭必須包含某參數:

#@RequestMapping(value="/headerTest", headers = "!example")。與限制請求參數是一樣的,可以參考上面的範例進行測試。

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.SpringMVC學習系列(3) 之 URL請求到Action的映射規則.指定映射請求頭中或某參數必須等於某個值:

@RequestMapping(value="/headerTest", headers = "Accept=text/html")。與限制請求參數是一樣的,可以參考上面的範例進行測試。

SpringMVC學習系列(3) 之 URL請求到Action的映射規則.SpringMVC學習系列(3) 之 URL請求到Action的映射規則.指定映射請求頭中或某參數必須等於某個值:

@RequestMapping(value="/headerTest", headers = "Accept! =text/html")。與限制請求參數是一樣的,可以參考上面的範例進行測試。

註:當我們為headers指定多個參數時如:headers={"exampleSpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則", "exampleSpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之 URL請求到Action的映射規則"},表示的是and關係,即兩個參數限制必須同時滿足。

 

 以上就是SpringMVC學習系列(SpringMVC學習系列(3) 之 URL請求到Action的映射規則) 之URL請求到Action的映射規則的內容,更多相關內容請關注PHP中文網(www.php.cn)!


#
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
4 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

SpringBoot與SpringMVC的比較及差別分析 SpringBoot與SpringMVC的比較及差別分析 Dec 29, 2023 am 11:02 AM

SpringBoot和SpringMVC都是Java開發中常用的框架,但它們之間有一些明顯的差異。本文將探究這兩個框架的特點和用途,並對它們的差異進行比較。首先,我們來了解一下SpringBoot。 SpringBoot是由Pivotal團隊開發的,它旨在簡化基於Spring框架的應用程式的建立和部署。它提供了一種快速、輕量級的方式來建立獨立的、可執行

比較SpringBoot與SpringMVC的差異是什麼? 比較SpringBoot與SpringMVC的差異是什麼? Dec 29, 2023 am 10:46 AM

SpringBoot與SpringMVC的不同之處在哪裡? SpringBoot和SpringMVC是兩個非常流行的Java開發框架,用於建立Web應用程式。儘管它們經常分別被使用,但它們之間的差異也是很明顯的。首先,SpringBoot可以被看作是一個Spring框架的擴充或增強版。它旨在簡化Spring應用程式的初始化和配置過程,以幫助開發人

SpringBoot與SpringMVC的差別是什麼? SpringBoot與SpringMVC的差別是什麼? Dec 29, 2023 pm 05:19 PM

SpringBoot和SpringMVC是Java開發中常用的兩個框架,它們都是由Spring框架所提供的,但在功能和使用方式上有一些區別。本文將分別介紹SpringBoot和SpringMVC的特點和區別。一、SpringBoot的特點:簡化配置:SpringBoot透過約定優於配置的原則,大大簡化了專案的配置過程。它可以自動配置專案所需的參數,開發人

springboot和springmvc有哪些差別 springboot和springmvc有哪些差別 Jun 07, 2023 am 10:10 AM

springboot和springmvc區別是:1、意義不同;2、配置不同;3、依賴項不同;4、開發時間不同;5、生產力不同;6、實現JAR打包功能的方式不同;7、是否提供批次處理功能;8、作用不同;9、社群和文件支援不同;10、是否需要部署描述符。

spring和springmvc有哪些差別 spring和springmvc有哪些差別 Dec 29, 2023 pm 05:02 PM

spring和springmvc的區別:1、定位和功能;2、核心功能;3、應用領域;4、擴展性。詳細介紹:1、定位和功能,Spring是一個綜合性的應用程式開發框架,提供了依賴注入、面向切面編程、事務管理等功能,旨在簡化企業級應用程式的開發,而Spring MVC是Spring框架中的一個模組,用於Web應用程式的開發,實現了MVC模式;2、核心功能等等。

Java的SpringMVC攔截器怎麼用 Java的SpringMVC攔截器怎麼用 May 13, 2023 pm 02:55 PM

攔截器(interceptor)的作用SpringMVC的攔截器類似於Servlet開發中的過濾器Filter,用於對處理器進行預處理和後處理。將攔截器依一定的順序聯結成一條鏈,這條鏈稱為攔截器鏈(InterceptorChain)。在存取被攔截的方法或欄位時,攔截器鏈中的攔截器就會依其先前定義的順序被呼叫。攔截器也是AOP思想的具體實作。攔截器和過濾器區別區別過濾器(Filter)攔截器(Intercepter)使用範圍是servlet規格中的一部分,任何JavaWeb工程都可以使用是Spri

Java API 開發中使用 SpringMVC 進行 Web 服務處理 Java API 開發中使用 SpringMVC 進行 Web 服務處理 Jun 17, 2023 pm 11:38 PM

隨著網路的發展,Web服務越來越普遍。 JavaAPI作為一種應用程式接口,也不斷地推出新的版本來適應不同的應用場景。而SpringMVC作為一種流行的開源框架,能夠幫助我們輕鬆地建立Web應用程式。本文將詳細講解在JavaAPI開發中,如何使用SpringMVC進行Web服務處理,包括配置SpringMVC、編寫控制器、使用

比較SpringBoot和SpringMVC的異同點 比較SpringBoot和SpringMVC的異同點 Dec 29, 2023 am 08:30 AM

解析SpringBoot和SpringMVC之間的異同SpringBoot和SpringMVC是Java領域中非常重要的開發架構。雖然它們都屬於Spring框架的一部分,但在使用和功能上有一些明顯的區別。本文將對SpringBoot和SpringMVC進行比較,解析它們之間的異同。首先,讓我們來了解一下SpringBoot。 SpringBo

See all articles