有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring默认页面未通过控制器类

在mvc视图配置中。xml,我有<mvc:view-controller path="/" view-name="countrys/countryList" />,在Controller中我有下面的代码。想法是加载country/countryList。第一次加载站点时使用jsp。问题是它显示的是正确的jsp页面,但代码没有在控制器类中调用这个showCountryList()。但如果我只是做我的网站。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";        
    }

共 (1) 个答案

  1. # 1 楼答案

    此配置元素

    <mvc:view-controller .../>
    

    只注册一个^{},它

    [...] always returns a named view.

    您已将其映射到/。因此,当您向/发送请求时,将使用该控制器,而不是包含您显示的处理程序方法的控制器

    我不明白为什么需要这个config元素,只需将处理程序方法映射到/以及其他路径

    @RequestMapping(value = {"/", "/countrys", "/countrys/countryList"})
    

    此外,“国家”的复数形式是“国家”