简体   繁体   中英

Spring 3.0 MVC Controller Request Mappings

I have 2 controllers in my app as follows

@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 . 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() {
     //....
    }  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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