国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 息烽县| 潮州市| 璧山县| 金华市| 阿瓦提县| 山东省| 南木林县| 绥化市| 洱源县| 漳州市| 黔西县| 金沙县| 鹤峰县| 岑巩县| 延川县| 平远县| 竹溪县| 永和县| 深水埗区| 玛多县| 松原市| 卢氏县| 环江| 松潘县| 广宗县| 东乌珠穆沁旗| 嫩江县| 博爱县| 怀集县| 日土县| 保亭| 贵阳市| 渑池县| 宣化县| 长顺县| 林西县| 定兴县| 阿克苏市| 如东县| 平舆县| 嘉祥县|