简体   繁体   English

Spring 3.0 MVC控制器请求映射

[英]Spring 3.0 MVC Controller Request Mappings

I have 2 controllers in my app as follows 我的应用程序中有2个控制器,如下所示

@Controller("/test1")
public class Test1Controller {
    @RequestMapping("/new")
    public String newtest1() {
     //....
    }  
}

@Controller("/test2")
public class Test2Controller {
    @RequestMapping("/new")
    public String newtest2() {
     //....
    }  
}

Now, if I make a request to /test2/new the request is going to the other controller /test1/new . 现在,如果我向/test2/new发出请求,则该请求将转到另一个控制器/test1/new Is there anything wrong here? 这里有什么问题吗?

Resolving off the controller name is just a fallback, it won't mix-and-match between that and actual request mappings. 解析控制器名称只是一个后备,它不会在控制器名称和实际请求映射之间进行混合匹配。 Just put a real request mapping on the controller. 只需在控制器上放置一个真实的请求映射即可。

@Controller
@RequestMapping("/test1")
public class Test1Controller {
    @RequestMapping("/new")
    public String newtest1() {
     //....
    }  
}

@Controller
@RequestMapping("/test2")
public class Test2Controller {
    @RequestMapping("/new")
    public String newtest2() {
     //....
    }  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM