Spring4 MVC HelloWord实例
使用springWind
/SpringWind/src/main/webapp/WEB-INF/web.xml
如果你不想用 SpringMVC 的使用原则,可以重新配置 SpringMVC DispatcherServlet 在 web.xml 文件中:【具体原则看原文,Servlet.xml跟web.xml在同个目录下】
<servlet> <servlet-name>springServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
classpath:spring/servlet-context.xml
等于:/SpringWind/src/main/resources/spring/servlet-context.xml
/SpringWind/src/main/resources添加至classpath方法(添加classpath)
右键工程:Build Path:configure build path→Source标签Add Folder→【/SpringWind/src/main/resources】
/SpringWind/src/main/resources/spring/servlet-context.xml
知识点(<!-- 扫描 controller -->):context:component-scan
知识点<!-- 定义视图解析器 -->:VelocityLayoutViewResolver和VelocityViewResolver的区别
<!-- 扫描 controller --> <context:component-scan base-package="com.baomidou.springwind.controller" /> <!-- 定义视图解析器 --> <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="resourceLoaderPath" value="/WEB-INF/views/" /> <property name="configLocation" value="classpath:properties/velocity.properties" /> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver"> <property name="suffix" value=".html" /> <property name="cache" value="false" /> <property name="contentType" value="text/html;charset=utf-8" /> <property name="dateToolAttribute" value="date" /><!--日期函数名称 --> <property name="numberToolAttribute" value="number" /><!--数字函数名称 --> <property name="layoutUrl" value="layout/default.vm" /> <property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml" /> </bean>
/SpringWind/src/main/java/com/baomidou/springwind/controller/HelloWorldController.java
@Controller public class HelloWorldController extends BaseController { @Permission(action = Action.Skip) @RequestMapping("/helloworld") public String hello (Model model) { return "/helloworld"; } }
/SpringWind/src/main/webapp/WEB-INF/views/helloworld.html
#override("title") HelloWorld! #end #override("breadcrumb") <li class="active"><strong>介绍说明</strong></li> #end #override("content") <div class="row"> <img alt="spring-wind" src="#springUrl('/static/img/spring-wind.png')"> </div> <div class="row"> <br><br> <h1>HelloWorld!!</h1> </div> #end #extends("/common/framework.html")
小结
应用程序流程,编写流程
重点和主要工作:只写controller
来源:oschina
链接:https://my.oschina.net/u/2882061/blog/2221632