在 mvc-view-config.xml 中,我有 <mvc:view-controller path="/" view-name="countrys/countryList" />
在 Controller 中我有下面的代码。这个想法是在站点首次加载时加载countrys/countryList.jsp。问题是它显示了正确的 jsp 页面,但代码没有在 Controller 类中调用此 showCountryList() 。但是,如果我只执行 mysite.com/countrys 或 mysite.com/contrys/contryList,我可以看到该页面,并且代码也调用了 showCountryList() 函数。我错过了什么?
@RequestMapping(value = {"/countrys", "/countrys/countryList"})
public String showCountryList(Map<String, Object> model) {
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
// so it is simpler for Object-Xml mapping
System.out.println("---- in here-----------");
Collection<Country> results = this.clinicService.getCountry();
model.put("selections", results);
return "countrys/countryList";
}
最佳答案
此配置元素
<mvc:view-controller .../>
简单地注册一个ParameterizableViewController
其中
[...] always returns a named view.
并且您已将其映射到/
。因此,当您向 /
发送请求时,将使用该 Controller ,而不是包含您所显示的处理程序方法的 Controller 。
我不明白为什么您需要该配置元素,只需将处理程序方法映射到 /
除了其他路径之外
@RequestMapping(value = {"/", "/countrys", "/countrys/countryList"})
<小时/>
此外,“国家”的复数形式是“国家”。
关于java - Spring默认页面不经过Controller类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22951785/