国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

SpringMVC之Ambiguous mapping(模棱兩可的映射)

2019-11-08 02:14:25
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

1、web.xml和核心配置文件的編輯見(jiàn)上篇http://blog.csdn.net/u010101142/article/details/55005330;

2、還是HelloController類:

package com.slz.hello.controller;import org.sPRingframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;@Controller@RequestMapping("/hello")public class HelloController {	@RequestMapping(path={"/hello","/slz.html","/*/benboba.php","/**/baboben.aspx","/ab*.htm"})	public ModelAndView hello(){		System.out.println("Hello World!");		ModelAndView mav = new ModelAndView();		mav.setViewName("hello");///WEB-INF/hello.jsp		return mav;	}		@RequestMapping(path={"index"})	public ModelAndView index(){		System.out.println("Hello Index!");		ModelAndView mav = new ModelAndView();		mav.setViewName("index");///WEB-INF/index.jsp		return mav;	}		@RequestMapping(path={"index","indexAmbiguous"})//調(diào)用時(shí)報(bào)錯(cuò),Ambiguous mapping,模棱兩可的映射	public ModelAndView indexAmbiguous(){		System.out.println("Hello Index!");		ModelAndView mav = new ModelAndView();		mav.setViewName("index");///WEB-INF/index.jsp		return mav;	}	//	@RequestMapping(path={"index"})	//啟動(dòng)時(shí)報(bào)錯(cuò),Ambiguous mapping,模棱兩可的映射//	public ModelAndView indexAmbiguous02(){//		System.out.println("Hello Index!");//		ModelAndView mav = new ModelAndView();//		mav.setViewName("index");///WEB-INF/index.jsp//		return mav;//	}}3、注意如果方法(不一定在同一個(gè)類)的RequestMapping路徑中存在相同的path值(默認(rèn)訪問(wèn)方法為get,比如index()和indexAmbiguous02()),啟動(dòng)時(shí)會(huì)報(bào)Ambiguous Mapping異常;也會(huì)有調(diào)用時(shí)才報(bào)Ambiguous Mapping異常,比如index()和indexAmbiguous();

4、新建MethodAmbiguousController:

package com.slz.hello.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView;@Controllerpublic class MethodAmbiguousController {	//啟動(dòng)沒(méi)問(wèn)題,	//testMethod01和testMethod02方法共存時(shí),則:執(zhí)行g(shù)etMethod方法,根據(jù)方法類型選擇執(zhí)行的方法	//testMethod03方法與其他兩個(gè)方法共存時(shí),則:執(zhí)行g(shù)etMethod方法,根據(jù)請(qǐng)求類型報(bào)錯(cuò)偷笑	//(Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/mvc/getMethodAmbiguous')	@RequestMapping(path="getMethodAmbiguous",method=RequestMethod.GET)	public ModelAndView testMethod01(){		System.out.println("getMethodAmbiguous");		return null;	}	@RequestMapping(path="getMethodAmbiguous",method=RequestMethod.POST)	public ModelAndView testMethod02(){		System.out.println("getMethodAmbiguous");		return null;	}	@RequestMapping(path="getMethodAmbiguous",method={RequestMethod.GET,RequestMethod.POST})	public ModelAndView testMethod03(){		System.out.println("getMethodAmbiguous");		return null;	}}

總結(jié):出現(xiàn)Ambiguous Mapping異常時(shí),找到同一請(qǐng)求路徑映射到兩個(gè)方法的地方,修改即可~


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 江西省| 大宁县| 永寿县| 涪陵区| 开远市| 江陵县| 海安县| 龙陵县| 陇川县| 甘洛县| 灵石县| 乌兰浩特市| 千阳县| 勐海县| 松溪县| 桂阳县| 余干县| 深泽县| 广汉市| 博乐市| 长沙县| 称多县| 镶黄旗| 西华县| 革吉县| 汽车| 凌海市| 女性| 天祝| 呼玛县| 新干县| 财经| 广州市| 阿拉善盟| 兴国县| 珲春市| 英超| 金昌市| 英超| 个旧市| 佛山市|