Spring4 MVC HelloWord實例

Spring4 MVC HelloWord實例

使用springWindhtml

/SpringWind/src/main/webapp/WEB-INF/web.xmljava

若是你不想用 SpringMVC 的使用原則,能夠從新配置 SpringMVC  DispatcherServlet 在 web.xml 文件中:【具體原則看原文,Servlet.xml跟web.xml在同個目錄下】web

<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.xmlspring

等於:/SpringWind/src/main/resources/spring/servlet-context.xmlspring-mvc

本人推斷,classpath的設置【即添加源文件夾】:mvc

/SpringWind/src/main/resources添加至classpath方法(添加classpath)app

右鍵工程:Build  Path:configure build path→Source標籤Add Folder→【/SpringWind/src/main/resources】yii

 /SpringWind/src/main/resources/spring/servlet-context.xmlwebapp

知識點(<!-- 掃描 controller -->):context:component-scanide

知識點<!-- 定義視圖解析器 -->: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

相關文章
相關標籤/搜索