最近想搞一实习相关设计,选了一下技术,js 我不会那就是排除前后端分离了,前后端不分离那就是我们的 jsp 和模板技术了啊
jsp想学但是好像目前市面上除了政府银行国企就没啥人用了 那以后学
先谈谈模板thymeleaf 和freemarker以及velocity;velocity据说更新慢,所以少有人用了,freemarker历史悠久但是比较难一点 所以选择Thymeleaf了啊 样式不会写 那只有用bootstrap了啊
模板用途就是显示页面数据,比如说我们页面静态化之类的
<table>
<thead>
<tr>
<th th:text="#{msgs.headers.name}">Name</th>
<th th:text="#{msgs.headers.price}">Price</th>
</tr>
</thead>
<tbody>
<tr th:each="prod: ${allProducts}">
<td th:text="${prod.name}">Oranges</td>
<td th:text="${#numbers.formatDecimal(prod.price, 1, 2)}">0.99</td>
</tr>
</tbody>
</table>
整合boot和Thymeleaf+mybatis
1
然后等待下载配置yml
spring:
# 模板引擎
thymeleaf:
mode: HTML
encoding: utf-8
# 禁用缓存
cache: false
prefix: classpath:/templates/
suffix: .html
server:
port: 8080
创建index
创建model层
package cn.xinyuan.demo.contoller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* @author xiaozheng
* @description
* @date 2023/2/23$
*/
@Controller
public class FirstIndex {
@RequestMapping("first")
public String first(Model modelAndView){
modelAndView.addAttribute("name","boot和模板整合");
return "index";
}
}
最后启动
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>boot和模板整合</title>
</head>
<body>
<input type="text" value="boot和模板整合">
</body>
</html>
入门结束 boot 2.5.6版本 jdk+8