SpringMVC遇到方法名重复的问题

Ambiguous mapping 就是方法名重复导致的错误 有一下两个方法 可以解决:

  1、将方法重复的名字找出来,改掉重复的名字即可;

  2、在控制层的那个类的最上面再添加一个注解RequestMapping;

package com.ttc.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("rs")
public class Test {
	 @RequestMapping("hello")
     public String add(String userno,NewsAdmin news,HttpSession session,HttpServletRequest request,Model model){
		 
		 System.out.println("userno="+userno);
		 model.addAttribute("userno",userno);
		 
    	 System.out.println("news="+news.getUserno());
		 model.addAttribute("news",news);
		 return "hello";
     }
}

我在原方法名叫"hello'的方法上还添加了一个名叫“rs”的注解

在此基础上 还得在前面的jsp出改下,

<a href="rs/hello.action?userno=12345">嘿嘿</a><br><br>
在hello.action前面加上rs/

为了以后不影响项目的运行,还需要在springmvc.xml里加上一段代码:

<!-- 视图解析器
	解析jsp解析,默认使用jstl标签,classpath下的得有jstl的包
	 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<!-- 配置jsp路径的前缀 -->
		<property name="prefix" value="/"/>
		<!-- 配置jsp路径的后缀 -->
		<property name="suffix" value=".jsp"/>


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值