Java框架_SpringBoot整合Freemarker

1、创建项目


2、修改pom文件,添加坐标

3、编写视图

注意:springBoot要求模板形式的视图层技术的文件必须要放到src/main/resources目录下必须要一个名称为templates

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</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.age}</td>
		</tr>
		</#list>
	</table>
</body>
</html>

4、创建Controller

package com.lxp.controller;

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.lxp.pojo.User;

@Controller
public class ShowUserController {

	@RequestMapping("/showUser")
	public String showUser(Model model) {

		List<User> list = new ArrayList<User>();
		list.add(new User(1, "张三", 20));
		list.add(new User(2, "李四", 22));
		list.add(new User(3, "王五", 24));

		model.addAttribute("list", list);
		return "userList";
	}
}
pojo类
package com.lxp.pojo;

public class User {
	private Integer userId;
	private String userName;
	private Integer age;

	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 getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public User(int id, String name, int age) {
		this.userId = id;
		this.userName = name;
		this.age = age;
	}

}

6,创建启动类

@SpringBootApplication
public class App {

	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值