在春天无法从控制器获得价值

时间:2016-08-18 05:42:49

标签: spring spring-mvc

我有这个简单的代码来获取视图中的数据,但我无法获得,也没有得到任何堆栈跟踪

     @Controller
        public class ControllerClass {

            @Autowired
            RepoisitiryClass repoisitiryClass;

            @RequestMapping("testData")
            public String getView(Model model) {
                model.addAttribute("getData", repoisitiryClass.setData());
                return "domain";
            }
        }


    public class Domain {
        private String domain;

        public Domain(String domain) {
            this.domain = domain;
        }

        public String getDomain() {
            return domain;
        }
    }

@Repository
    public class RepoisitiryClass {
        private String dataDomain = "";

        public RepoisitiryClass() {
            System.out.println("inside Repo");
            Domain domain = new Domain("this is domain");
            dataDomain = domain.getDomain();
        }

        public String setData() {
            return dataDomain;
        }
    }
<mvc:annotation-driven />
    <context:component-scan base-package="com" />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

<servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

现在,当我尝试运行网址时:http://localhost:8080/Test_path_Variable/testData它找不到错误404页面。

无论如何都要解决这个错误,或者我做错了什么?

和项目结构enter image description here

0 个答案:

没有答案