【SpringBoot】09.SpringBoot整合Freemarker

【SpringBoot】09.SpringBoot整合Freemarker,第1张

概述SpringBoot整合Freemarker 1.修改pom文件,添加坐标freemarker启动器坐标 <project xmlns="http://maven.ap SpringBoot整合Freemarker1.修改pom文件,添加坐标freemarker启动器坐标
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <parent>    <groupID>org.springframework.boot</groupID>    <artifactID>spring-boot-starter-parent</artifactID>    <version>2.1.2.RELEASE</version>  </parent>  <groupID>com.dxh</groupID>  <artifactID>09-spring-boot-vIEw-freemarker</artifactID>  <version>0.0.1-SNAPSHOT</version>    <!-- 修改JDK版本 -->  <propertIEs>  	<java.version>1.8</java.version>  </propertIEs>  <dependencIEs>		<!-- Spring Boot 的启动器 -->		<dependency>			<groupID>org.springframework.boot</groupID>			<artifactID>spring-boot-starter-web</artifactID>		</dependency>		<!-- freemarker启动器坐标 -->		<dependency>			<groupID>org.springframework.boot</groupID>			<artifactID>spring-boot-starter-freemarker</artifactID>		</dependency>	</dependencIEs></project>
2.编写视图:SpringBoot要求模板形式的视图层技术的文件必须放在src/main/resources/目录下必须要一个名称为:templates目录。 视图名为userList.ftl
<HTML>	<head>		<Title>展示用户数据</Title>		<Meta charset="utf-8"></Meta>	</head>	<body>		<table border="1" align="center" wIDth="50%">		<tr>			<th>ID</th>			<th>name</th>			<th>Age</th>		</tr>		<#List List as user>			<tr>				<td>${user.userID}</td>				<td>${user.username}</td>				<td>${user.userAge}</td>			</tr>		</#List>	</table>	</body></HTML>
3.创建controller、POJO
import java.util.ArrayList;import java.util.List;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapPing;import com.dxh.pojo.Users;/** * SpringBoot整合Jsp * */@Controllerpublic class UserController {	/**	   * 处理请求,产生数据	 */	@RequestMapPing("/showUser")	public String showUser(Model model) {		List<Users> List  = new ArrayList<>();		List.add(new Users(1,"张三",20));		List.add(new Users(2,"李四",22));		List.add(new Users(3,"赵武",25));		//需要一个Model对象		model.addAttribute("List",List);		//跳转视图		return "userList";	}}
package com.dxh.pojo;public class Users {	private Integer userID;	private String username;	private Integer userAge;	public Users(Integer userID,String username,Integer userAge) {		super();		this.userID = userID;		this.username = username;		this.userAge = userAge;	}	public Integer getUserID() {		return userID;	}	public voID setUserID(Integer userID) {		this.userID = userID;	}	public String getUsername() {		return username;	}	public voID setUsername(String username) {		this.username = username;	}	public Integer getUserAge() {		return userAge;	}	public voID setUserAge(Integer userAge) {		this.userAge = userAge;	}	}
4.创建启动器——运行 总结

以上是内存溢出为你收集整理的【SpringBoot】09.SpringBoot整合Freemarker全部内容,希望文章能够帮你解决【SpringBoot】09.SpringBoot整合Freemarker所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1217027.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存