Eclips新建一项目 NEW->Other… 输入“maven”选择 Maven Project,点击 Next。
一路默认,如下图,输入”com.test”,”smvc”,Finish。
项目上点击右键,properties,选择“Project Facets”。点击“Convert to faceted from …”,选择“Dynamic Web Module”。OK。
官网上的maven依赖拷贝过来。
项目上点击右键,properties,选择“Deployment Assembly”。点击 Add … 选择 Java Build
Path Entries,选择 Maven Dependencies。Finish
在WebContent/WEB-INF里添加web.xml
xmlns:util=\"http://www.springframework.org/schema/util\" xmlns:mvc=\"http://www.springframework.org/schema/mvc\" xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd\"> id=\"internalResourceViewResolver\"> 加入WEB依赖和json依赖。 添加类 package com.test.smvc.control; import java.util.Date; import java.util.HashMap; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping(\"/mvc\") publicclass Test { @RequestMapping(\"/hello\") public String hello() { return\"hello\"; } @RequestMapping(\"/hello1\") public ModelAndView hello1() { ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject(\"name\", new Date()); modelAndView.addObject(\"namexx\", new Object()); modelAndView.setViewName(\"hello\"); returnmodelAndView; } @RequestMapping(\"/hello2\") @ResponseBody public HashMap 添加JSP页面到WebContent/WEB-INF/jsp/hello.jsp 配置启动服务。 访问地址:如下,说明成功。 因篇幅问题不能全部显示,请点此查看更多更全内容