下面小編就為大家帶來一篇SpringMvc接收參數方法總結(必看篇)。小編覺得蠻不錯的,現在就分享給大家,也給大家做個參考。一起跟著小編過來看看吧
接收參數的方式:
#1.HttpServletRequest方式接收
public ModelAndView test1(HttpServletRequest req){ String userName = req.getParameter("userName"); String password = req.getParameter("password"); System.out.println(userName); System.out.println(password); return new ModelAndView("jsp/hello"); }
2.@RequestParam方式
public ModelAndView test2(String userName, @RequestParam("password") String pwd){ System.out.println(userName+","+pwd); return new ModelAndView("jsp/hello"); }
3.物件的方式接收
public ModelAndView test3(User user){ System.out.println(user); return new ModelAndView("jsp/hello"); }
4.
##
/** * 使用ModelAndView传出参数 内部 HttpServletRequest的Attribute传递 到jsp页面 * ModelAndView(String viewName,Map data)data是处理结果 */ @RequestMapping("action") public ModelAndView test4(User user){ Map<String, Object> data = new HashMap<String, Object>(); data.put("user", user); return new ModelAndView("jsp/hello",data); }
5. Session的方式
/** * session存储 可以使用HttpServletRequest的getSession方法访问 */ @RequestMapping("action") public ModelAndView test7(HttpServletRequest req){ HttpSession session = req.getSession(); session.setAttribute("salary", 6000.0); return new ModelAndView("jsp/hello"); }
6.重定向:
@RequestMapping("/updateitem") //spirngMvc可以直接接收pojo类型:要求页面上input框的name属性名称必须等于pojo的属性名称 public ModelAndView updateitem(Items items){ itemsService.updateitems(items); //不可以加斜杠 解析不了 itemList.action return new ModelAndView(new RedirectView("itemList.action")); }
7.重定向
#
@RequestMapping("/updateitem") //spirngMvc可以直接接收pojo类型:要求页面上input框的name属性名称必须等于pojo的属性名称 public String updateitem(Items items){ itemsService.updateitems(items); //重定向到action 可以加斜杠 redirect:/itemList.action 解析的了 return "redirect:itemList.action"; }使用Model和ModelMap的效果一樣,如果直接使用Model,springmvc會實例化ModelMap。 如果使用Model則可以不使用ModelAndView對象,Model對象可以向頁面傳遞數據,View對象則可以使用String回傳值替代。不管是Model還是ModelAndView,其本質都是使用Request物件向jsp傳遞資料。
以上是SpringMvc中接收參數方法介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Javaremainsagoodlanguageduetoitscontinuousevolutionandrobustecosystem.1)Lambdaexpressionsenhancecodereadabilityandenablefunctionalprogramming.2)Streamsallowforefficientdataprocessing,particularlywithlargedatasets.3)ThemodularsystemintroducedinJava9im

Javaisgreatduetoitsplatformindependence,robustOOPsupport,extensivelibraries,andstrongcommunity.1)PlatformindependenceviaJVMallowscodetorunonvariousplatforms.2)OOPfeatureslikeencapsulation,inheritance,andpolymorphismenablemodularandscalablecode.3)Rich

Java的五大特色是多態性、Lambda表達式、StreamsAPI、泛型和異常處理。 1.多態性讓不同類的對象可以作為共同基類的對象使用。 2.Lambda表達式使代碼更簡潔,特別適合處理集合和流。 3.StreamsAPI高效處理大數據集,支持聲明式操作。 4.泛型提供類型安全和重用性,編譯時捕獲類型錯誤。 5.異常處理幫助優雅處理錯誤,編寫可靠軟件。

java'stopfeatureSnificallyenhanceItsperformanCandScalability.1)對象 - 方向clincipleslike-polymormormormormormormormormormormormorableableflexibleandscalablecode.2)garbageCollectionAutectionAutoctionAutoctionAutoctionAutoctionAutoctionAutoMenateMememorymanateMmanateMmanateMmanagementButCancausElatemention.3)

JVM的核心組件包括ClassLoader、RuntimeDataArea和ExecutionEngine。 1)ClassLoader負責加載、鏈接和初始化類和接口。 2)RuntimeDataArea包含MethodArea、Heap、Stack、PCRegister和NativeMethodStacks。 3)ExecutionEngine由Interpreter、JITCompiler和GarbageCollector組成,負責bytecode的執行和優化。

Java'ssafetyandsecurityarebolsteredby:1)strongtyping,whichpreventstype-relatederrors;2)automaticmemorymanagementviagarbagecollection,reducingmemory-relatedvulnerabilities;3)sandboxing,isolatingcodefromthesystem;and4)robustexceptionhandling,ensuringgr

Javaoffersseveralkeyfeaturesthatenhancecodingskills:1)對象 - 方向 - 方向上的allowslowsmodelowsmodelingreal-worldentities

thejvmisacrucialcomponentthatrunsjavacodebytranslatingitolachine特定結構,影響性能,安全性和便攜性。 1)theclassloaderloader,links andinitializesClasses.2)theexecutionEngineExecutionEngineExecutionEngineExecuteNexeCuteByteCuteByteCuteByTecuteByteCuteByteCuteBytecuteBytecuteByteCoDeinintolachineinstructionsions.3)Memo.3)Memo


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。