Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

7.2. View

7.2.1. Using Spring’s form tag library

7.2.1.1. css

			
	
			
			
7.2.1.1.1. cssClass

cssClass 使用該屬性指定表單元素CSS樣式名,相當於HTML元素的class屬性

				
<form:input path="userName" cssClass="inputStyle"/>
				
				
7.2.1.1.2. cssStyle

cssStyle 直接通過該屬性指定樣式,相當於HTML元素的style屬性

				
<form:input path="userName" cssStyle="width:100px"/>
				
				
7.2.1.1.3. cssErrorClass

cssError Class表示表單元素髮生錯誤時對應的樣式

				
<form:input path="userName" cssClass="userNameClass" cssErrorClass= "userNameClassError"/>
				
				

7.2.1.2. cssClass

			
	
			
			

7.2.2. Thymeleaf

http://thymeleaf.org/

7.2.2.1. Maven pom.xml

			
			<dependency>  
	            <groupId>org.springframework.boot</groupId>  
	            <artifactId>spring-boot-starter-thymeleaf</artifactId>  
	        </dependency>  		
			
			

7.2.2.2. Spring 配置

			
	<!-- **************************************************************** -->
	<!-- THYMELEAF-SPECIFIC ARTIFACTS -->
	<!-- TemplateResolver <- TemplateEngine <- ViewResolver -->
	<!-- **************************************************************** -->

	<bean id="templateResolver"
		class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
		<property name="prefix" value="/WEB-INF/templates/" />
		<property name="suffix" value=".html" />
		<property name="templateMode" value="HTML5" />
	</bean>

	<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
		<property name="templateResolver" ref="templateResolver" />
	</bean>

	<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
		<property name="templateEngine" ref="templateEngine" />
	</bean>	
			
			

7.2.2.3. controller

			
package cn.netkiller.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
public class HelloController {

	@RequestMapping(value = "/{name}", method = RequestMethod.GET)
	public String getMovie(@PathVariable String name, ModelMap model) {
		model.addAttribute("name", name);
		return "hello";
	}

}			
			
			

7.2.2.4. HTML5 Template

			
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Spring MVC + Thymeleaf Example</title>
</head>
<body>
	Hello, <span th:text="${name}" />!
</body>
</html>
			
			

7.2.3. FreeMarker

http://freemarker.org/