springboot中使用thymeleaf动态模板增删改查
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
(1)application.properties
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
(2)controller
@Controller("user_controller")
@RequestMapping("/user")
public class UserController{
@Autowired
@Qualifier("userService") /* 一个接口多个实现用name区分*/
private IUserService userService;
@RequestMapping("/")
public String list(Model model) {
System.out.println(" *** controller *** "+this);
List<UserPO> list = userService.findUsers();
model.addAttribute("userList", list);
return "users/list";
}
@RequestMapping("/delete/{id}")
public String delete(@PathVariable("id") String id){
userService.deleteUser(id);
return "redirect:/user/";
}
@RequestMapping(value="/save", method=RequestMethod.POST)
//public String save(@RequestBody UserVO user){ //415错误
public String save() {
return "forward:/user/";
}
@RequestMapping("/{id}")
public String get(@PathVariable String id, Model model){
if("toadd".equals(id)) {
return toAddPage();
}
System.out.println(" *** controller *** "+this);
UserVO user = userService.findUserByID(id);
model.addAttribute("user", user);
// return "forward:/";
return "users/detail";
}
public String toAddPage(){
return "users/add";
}
}
(3)页面
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- jquery -->
<script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
<!-- bootstrap -->
<link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap.min.css}" />
<script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
<!-- jquery-validator -->
<script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
<script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.min.js}"></script>
<!-- layer -->
<script type="text/javascript" th:src="@{/layer/layer.js}"></script>
<!-- md5.js -->
<script type="text/javascript" th:src="@{/js/md5.min.js}"></script>
<!-- common.js -->
<script type="text/javascript" th:src="@{/js/common.js}"></script>
<script type="text/javascript">
function toAddPage(){
window.location.href="/boot/user/toadd/";
}
</script>
</head>
<body>
<div>
<div class="title-search fl" style="width:100%;">
<span class="ft14" style="width: 60px;">用户编号</span>
<input id="yhbh" class="ft12 search-box" type="text" placeholder=""/>
<span class="ft14" style="width: 60px;margin-left: 20px;">用户名称</span>
<input id="yhmc" class="ft12 search-box" type="text" placeholder="用户名称"/>
<input type="button" id="userquery" class="btn-blue" value="查询" style="width: 80px;margin-left:20px;margin-bottom:5px;"/>
<button class="btn btn-primary btn-block" type="button" id="addbtn" style="width:80px" onclick="toAddPage()">新建</button>
</div>
<table class="table" >
<tr>
<th><input type="checkbox"/></th>
<th>用户编号</th>
<th>用户名称</th>
<th>邮箱</th>
<th>办公电话</th>
<th>状态</th>
<th>操作</th>
</tr>
<tr th:each="u,uStat:${userList}">
<td><input name="userId" type="checkbox" th:value="${u.userId}"/></td>
<td th:text="${u.userNo}"></td>
<td th:text="${u.userName}"></td>
<td th:text="${u.email}"></td>
<td th:text="${u.officeTel}"></td>
<td th:text="${u.status}"></td>
<td>
<!--
编辑
删除
-->
<a th:href="'/boot/user/'+${u.userId}" >编辑</a>
<a th:href="'/boot/user/delete/'+${u.userId}" style="margin-left:10px;">删除</a>
</td>
</tr>
</table>
</div>
</body>
</html>
android入门实例:https://gitbook.cn/gitchat/activity/5d382e64b669c0566c335b32
分享到:
相关推荐
基于java的开发源码-HTML5模板引擎 Thymeleaf.zip 基于java的开发源码-HTML5模板引擎 Thymeleaf.zip 基于java的开发源码-HTML5模板引擎 Thymeleaf.zip 基于java的开发源码-HTML5模板引擎 Thymeleaf.zip 基于java的...
HTML5模板引擎 Thymeleaf简介 Thymeleaf是一个Java库。这是个XML/XHTML/HTML5模板引擎,提供一组模板文件到文本的转换。Thymeleaf更适应在web应用中提供XHTML/HTML5的服务,但也可以在web或任何的独立应用中处理...
thymeleaf使用模板 ,此代码是样例代码, 需要的可以下载看下
springboot+thymeleaf+maven+html+css实现精美大方好看官网模板完整源码 不需要搭建数据库即可启动,如果需要后台管理+数据库可以自己迭代拓展增加; 项目可以轻易修改,非常简单,非常适合新手
Thymeleaf是一个面向web和独立环境的现代服务器端Java模板引擎。 Thymeleaf的主要目标是将优雅的自然模板引入到您的开发工作流程中——可以在浏览器中正确显示的HTML,也可以作为静态原型工作,从而在开发团队中实现...
HTML5模板引擎 Thymeleaf
springboot整合thymeleaf模板
- `spring.thymeleaf.prefix`:模板文件的路径前缀,默认为 `classpath:/templates/`。 - `spring.thymeleaf.suffix`:模板文件的后缀,默认为 `.html`。 - `spring.thymeleaf.cache`:是否启用缓存,默认为 `true`...
开源项目结合了springboot框架+thymeleaf模板引擎+layui前端框架+数据库+redis等技术
SpringBoot加Thymeleaf模板
处理视图模板文件的servlet基类; 继承:HttpServlet类 重写了init()方法: 1.获取ServletContext对象 2.创建Thymeleaf解析器对象 3.给解析器对象设置参数(前缀、后缀、缓存过期时间、是否缓存、编码方式) 4....
Thymeleaf是⾯向Web和独⽴环境的现代服务器端Java模板引擎, 能够处 理HTML, XML, JavaScript, CSS甚⾄纯⽂本。 Thymeleaf旨在提供⼀个优雅的、 ⾼度可维护的创建模板的⽅式。 为了实 现这⼀⽬标, Thymeleaf建⽴...
eclipse插件thymeleaf。 thymeleaf-extras-eclipse-plugin-3.0.1
springboot 自带模板thymeleaf 写的小项目 小白可以单做学习用 全是用HTML写的 带数据库 我是用软件idea写的代码 用idea可直接运行 其他软件也许要轻微改动
SpringBoot模板引擎Thymeleaf使用说明官方文档中文版(翻译的不错),带左侧标签目录(本人添加的),方便按点击目录查看,原英文版本详见:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.pdf
# spring-boot-thymeleaf 在springboot用thymeleaf模板引擎
SpringBoot在搭建的时候不用XML配置文件,同时嵌入Tomcat,无需部署war,是一个搭建、使用起来都比较方便的框架。
Spring Boot Thymeleaf是一个集成了Thymeleaf模板引擎的Spring Boot Starter,用于简化在Spring Boot应用程序中使用Thymeleaf的过程。 Thymeleaf是一个现代服务器端Java模板引擎,可以处理HTML、XML、JavaScript、...
在模板文件的表达式中,可以使用“${T(全限定类名).方法名(参数)}”这种格式来调用Java类的静态方法。 开发环境:IntelliJ IDEA 2019.2.2 Spring Boot版本:2.1.8 新建一个名称为demo的Spring Boot项目。 1、pom....
Thymeleaf所需要的jar包