标签:username Exception return Spring param Controller MVC ModelAndView throws
/** * 方式一:使用servlet原生的方式,request.getParameter("key")获取参数; * @param request * @param response * @return * @throws Exception */ @RequestMapping("/get1") ModelAndView get1(HttpServletRequest request,HttpServletResponse response) throws Exception{ String username=request.getParameter("username"); String password=request.getParameter("password"); return null; } /** * 方式二:同名规则接收传参 * @param username * @return * @throws Exception */ @RequestMapping("/get2") ModelAndView get2(String username)throws Exception{ return null; } /** * 方式二的另一种形式:前后台参数名不同,使用@RequestParam("前台参数名称")注解
* 如前台传参:username1,Controller中使用username * @param username * @return * @throws Exception */ @RequestMapping("/get3") ModelAndView get3(@RequestParam("username1")String username) throws Exception{ return null; } /** * 方式三:模型传参 * @param user * @return * @throws Exception */ @RequestMapping("/get4") ModelAndView get4(User user)throws Exception{ return null; }
/** * 方式四:使用地址栏传参,需要使用注解@PathVariable("parameter_name") * 如请求地址为:/get5/zhangsan * 此时地址栏的zhangsan会被当作username的参数值 * @param username * @return * @throws Exception */ @RequestMapping("/get5/{username}") ModelAndView get5(@PathVariable("username")String username)throws Exception{ return null; }
标签:username,Exception,return,Spring,param,Controller,MVC,ModelAndView,throws 来源: https://www.cnblogs.com/shichq/p/16194783.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。