Spring Boot-Free Marker小样例

【模板引擎FreeMarker】

WebController

public class WebController {

	@RequestMapping(value = "index")
	public String index(ModelMap map) {
		map.put("title", "freemarker hello word");  //ftl中代码可见要传title
		return "index"; // 想调用index.ftl,开头不要加上/,linux下面会出错
	}

}

FreeMarker很支持静态页面,这里的反例用到了resources目录下static目录下的css文件、图片文件和templates下的index.ftl文件

index.ftl

<!DOCTYPE html>
<html>
<head lang="en">
	<title>Spring Boot Demo - FreeMarker</title>
	
	<link href="/css/index.css" rel="stylesheet" />
	
</head>
<body>
	<center>
		<img src="/images/logo.png" />
		<h1 id="title">${title}</h1>
	</center>
	
	<script type="text/javascript" src="/webjars/jquery/2.1.4/jquery.min.js"></script>
	
	<script>
		$(function(){
			$('#title').click(function(){
				alert('点击了');
			});
		})
	</script>
</body>
</html>

界面效果

猜你喜欢

转载自blog.csdn.net/m0_38033475/article/details/81507244