前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >SpringBoot综合案例

SpringBoot综合案例

原创
作者头像
Java鱼头
发布于 2022-12-01 14:42:23
发布于 2022-12-01 14:42:23
54900
代码可运行
举报
文章被收录于专栏:Java-docJava-doc
运行总次数:0
代码可运行

综合案例

前面介绍了Freemaker,这节介绍SpringBoot整合MyBatis,同时结合Freemaker展现数据

5.1 项目创建

添加相关的依赖

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="UTF-8"?>
<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 https://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.3.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.bobo</groupId>
    <artifactId>springboot-demo09</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-demo09</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency><dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.14</version>
        </dependency>
    </dependencies><build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build></project>

添加相关的配置文件

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
server.port=8082
​
# 配置JDBC的相关信息
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/logistics?characterEncoding=utf-8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
​
# 配置连接池
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
​
# 配置MyBatis的package 设置别名
mybatis.type-aliases-package=com.bobo.pojo
​

创建实体对象

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.bobo.pojo;public class User {
    private String user_id    ;
    private String user_name  ;
    private String real_name  ;
    private String password   ;
    private String email      ;
    private String phone      ;
    private String u1         ;
    private String u2         ;public String getUser_id() {
        return user_id;
    }public void setUser_id(String user_id) {
        this.user_id = user_id;
    }public String getUser_name() {
        return user_name;
    }public void setUser_name(String user_name) {
        this.user_name = user_name;
    }public String getReal_name() {
        return real_name;
    }public void setReal_name(String real_name) {
        this.real_name = real_name;
    }public String getPassword() {
        return password;
    }public void setPassword(String password) {
        this.password = password;
    }public String getEmail() {
        return email;
    }public void setEmail(String email) {
        this.email = email;
    }public String getPhone() {
        return phone;
    }public void setPhone(String phone) {
        this.phone = phone;
    }public String getU1() {
        return u1;
    }public void setU1(String u1) {
        this.u1 = u1;
    }public String getU2() {
        return u2;
    }public void setU2(String u2) {
        this.u2 = u2;
    }
}

5.2 查询用户信息

创建接口

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.bobo.mapper;import com.bobo.pojo.User;import java.util.List;public interface UserMapper {
​
​
    List<User> query();
}

创建映射文件

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bobo.mapper.UserMapper">
    <select id="query" resultType="user">
        select * from t_user
    </select>
</mapper>

属性文件中添加Mapper映射文件的路径

创建Service

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.bobo.service;import com.bobo.pojo.User;import java.util.List;public interface IUserService {
​
    List<User> query();
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.bobo.service.impl;import com.bobo.mapper.UserMapper;
import com.bobo.pojo.User;
import com.bobo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;
​
@Service
public class UserServiceImpl implements IUserService {
​
    @Autowired
    private UserMapper mapper;
​
    @Override
    public List<User> query() {
        return mapper.query();
    }
}

创建控制器

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.bobo.controller;import com.bobo.pojo.User;
import com.bobo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;import java.util.List;
​
@Controller
@RequestMapping("/user")
public class UserController {
​
    @Autowired
    private IUserService service;
​
    @RequestMapping("/query")
    public String query(Model model){
        List<User> list = service.query();
        model.addAttribute("list",list);
        return "/user";
    }
}

属性文件中配置Freemaker的后缀

创建Freemaker模板文件,并且展示数据

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<html>
    <head>
        <title>用户管理</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <h1>用户管理</h1>
        <table>
            <tr>
                <th>编号</th>
                <th>账号</th>
                <th>姓名</th>
                <th>邮箱</th>
                <th>电话</th>
                <th>操作</th>
            </tr>
            <#list list as user>
                <tr>
                    <td>${user.user_id}</td>
                    <td>${user.user_name}</td>
                    <td>${user.real_name!""}</td>
                    <td>${user.email!""}</td>
                    <td>${user.phone!""}</td>
                    <td>...</td>
                </tr>
            </#list>
        </table>
    </body>
</html>

启动操作之前我们需要添加 MyBatis接口的扫描路径

访问测试

5.3 添加用户

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<html>
    <head>
        <title>用户管理</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <h1>用户管理</h1>
        <form action="/user/userUpdate" method="post" >
            <label>账号</label><input type="text" name="user_name"><br>
            <label>姓名</label><input type="text" name="real_name"><br>
            <label>邮箱</label><input type="text" name="email"><br>
            <label>电话</label><input type="text" name="phone"><br>
            <input type="submit" value="提交">
        </form>
    </body>
</html>

5.4 更新用户

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<html>
    <head>
        <title>用户管理</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <h1>用户管理</h1>
        <form action="/user/userUpdate" method="post" >
            <input type="hidden" name="user_id" value="${user.user_id}">
            <label>账号</label><input type="text" name="user_name" value="${user.user_name}"><br>
            <label>姓名</label><input type="text" name="real_name" value="${user.real_name!""}"><br>
            <label>邮箱</label><input type="text" name="email" value="${user.email!""}"><br>
            <label>电话</label><input type="text" name="phone" value="${user.phone!""}"><br>
            <input type="submit" value="提交">
        </form>
    </body>
</html>

5.5 删除用户

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<html>
    <head>
        <title>用户管理</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <h1>用户管理</h1>
        <h2>
            <a href="/user/dispatchUpdate">添加用户</a>
        </h2>
        <table>
            <tr>
                <th>编号</th>
                <th>账号</th>
                <th>姓名</th>
                <th>邮箱</th>
                <th>电话</th>
                <th>操作</th>
            </tr>
            <#list list as user>
                <tr>
                    <td>${user.user_id}</td>
                    <td>${user.user_name}</td>
                    <td>${user.real_name!""}</td>
                    <td>${user.email!""}</td>
                    <td>${user.phone!""}</td>
                    <td>
                        <a href="/user/dispatchUpdate?id=${user.user_id}">更新</a>
                        <a href="/user/deleteUser?id=${user.user_id}">删除</a>
                    </td>
                </tr>
            </#list>
        </table>
    </body>
</html>

6. Thymeleaf

Thymeleaf是SpringBoot中推荐使用的前端模板框架。所以比较重要

6.1 SpringBoot整合

创建一个SpringBoot项目,然后添加对应的依赖

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="UTF-8"?>
<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 https://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.3.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.bobo</groupId>
    <artifactId>springboot-demo10</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-demo10</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency><!-- 使用Thymeleaf需要添加的依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency><dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies><build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build></project>

创建Thymeleaf文件,Thymeleaf的后缀就是html,我在template目录下直接创建一个html页面即可,但是为了能够使用Thymeleaf中的标签提示,我们添加对应的xmlns即可

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Thymeleaf介绍</title>
</head>
<body>
    <h1>Hello Thymeleaf</h1></body>
</html>

添加跳转的控制器

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@Controller
public class UserController {
​
    @RequestMapping("/hello")
    public String hello(){
        System.out.println("hello ....");
        return "/user";
    }
}

启动服务测试

访问成功,说明整合搞定~

6.2 Thymeleaf基本使用

Thymeleaf表达式只能放置在Thymeleaf的自定义属性中(html标签中)。

6.2.1 变量输出

控制器中绑定数据

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@RequestMapping("/hello")
public String hello(Model model){
    System.out.println("hello ....");
    model.addAttribute("hello","Hello Thymeleaf");
    model.addAttribute("msg","hahaha");
    model.addAttribute("now",new Date());
    model.addAttribute("flag",true);
    model.addAttribute("age",18);
    return "/user";
}

模板文件

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Thymeleaf介绍</title>
</head>
<body>
    <h1>Hello Thymeleaf</h1>
    <label th:text="hello"></label><br>
    <label th:text="${hello}"></label><br>
    <label th:text="${now}"></label><br>
    <label th:text="${flag}"></label><br>
    <label th:text="${age}"></label><br>
    <h2>th:value的使用</h2>
    <input type="text" value="aaa"><br>
    <input type="text" th:value="${msg}"><br>
</body>
</html>

显示效果

6.2.2 内置函数

我们通过上面的案例发现显示Model中的数据很方便,但是显示的数据的格式可能不满足我们的需求,这时我们需要调整就需要借助内置的函数来帮助我们实现,我们主要介绍字符串和时间相关的函数,

注意点

  1. 调用内置函数对象一定要使用#
  2. 大部分的内置函数都以 s 结尾, 比如 strings numbers dates

字符串的处理

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Thymeleaf介绍</title>
</head>
<body>
    <h1>string类型介绍</h1>
    hello:<span th:text="${hello}"></span><br>
    hello是否为空:<span th:text="${#strings.isEmpty(hello)}"></span><br>
    hello字符串是否包含"th":<span th:text="${#strings.contains(hello,'th')}"></span><br>
    hello字符串是否包含"Th":<span th:text="${#strings.contains(hello,'Th')}"></span><br>
    hello以H开头:<span th:text="${#strings.startsWith(hello,'H')}"></span><br>
    hello以a开头:<span th:text="${#strings.startsWith(hello,'a')}"></span><br>
    hello以H结尾:<span th:text="${#strings.endsWith(hello,'H')}"></span><br>
    hello以a结尾:<span th:text="${#strings.endsWith(hello,'a')}"></span><br>
    hello的长度:<span th:text="${#strings.length(hello)}"></span><br>
    hello都大写:<span th:text="${#strings.toUpperCase(hello)}"></span><br>
    hello都小写:<span th:text="${#strings.toLowerCase(hello)}"></span><br></body>
</html>

日期时间类型的处理

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
    <h1>日期时间处理</h1>
    时间:<span th:text="${now}"></span><br>
    时间:<span th:text="${#dates.format(now)}"></span><br>
    时间:<span th:text="${#dates.format(now,'yy/MM/dd')}"></span><br>
    时间:<span th:text="${#dates.format(now,'yy/MM/dd hh:ss:mm')}"></span><br>
    时间:<span th:text="${#dates.format(now,'yy/MM/dd HH:ss:mm')}"></span><br>
    年份:<span th:text="${#dates.year(now)}"></span><br>
    月份:<span th:text="${#dates.month(now)}"></span><br>
    日期:<span th:text="${#dates.day(now)}"></span><br>
    本周的第几天:<span th:text="${#dates.dayOfWeek(now)}"></span><br>
    小时:<span th:text="${#dates.hour(now)}"></span><br>

6.2.3 条件判断
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Thymeleaf介绍</title>
</head>
<body><h1>条件判断</h1>
    <h2>if语句</h2>
    <span th:if="${sex} == '男'"></span>
    <span th:unless="${sex} =='男'"></span>
    <br>
    <!-- and or not -->
    <span th:if="${flag or false}">
        or的使用11
    </span>
    <span th:unless="${flag or false}">
        or的使用12
    </span>
    <br>
    <span th:if="${flag and false}">
        and的使用21
    </span>
    <span th:unless="${flag and false}">
        and的使用22
    </span>
    <br>
    <span th:if="${not flag}">
        not的使用11
    </span><span th:unless="${not flag}">
        not的使用22
    </span>
    <br>
<!-- 三木运算符 -->
    <span th:text="true?'A':'B'"></span><br><!-- switch语句 -->
    <hr>
    <div th:switch="${age}">
        <div th:case="17">
            17</div>
        <div th:case="18">
            18</div>
        <div th:case="19">
            19</div>
        <div th:case="*">其他...</div>
    </div></body>
</html>

6.2.4 循环语句
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Thymeleaf介绍</title>
</head>
<body><h1>循环判断</h1>
    <div th:each="c : ${list1}">
        <span th:text="${c}"></span><br>
    </div>
    <hr>
    <div th:each="user : ${list2}">
        <span th:text="${user.id}"></span>&nbsp;&nbsp;
        <span th:text="${user.userName}"></span>&nbsp;&nbsp;
        <span th:text="${user.address}"></span><br>
    </div>
    <hr>
    <div th:each="m : ${map}">
        <!-- 每次循环获取的是一个KV-->
        <span th:text="${m.getKey() + ':' + m.getValue().getId()}"></span>
        <span th:text="${m.getKey() + ':' + m.getValue().getUserName()}"></span>
        <span th:text="${m.getKey() + ':' + m.getValue().getAddress()}"></span>
    </div>
    <hr>
    <div th:each="user,iter : ${list2}">
        <span th:text="${iter.count}"></span>&nbsp;&nbsp;
        <span th:text="${iter.index}"></span>&nbsp;&nbsp;<span th:text="${user.id}"></span>&nbsp;&nbsp;
        <span th:text="${user.userName}"></span>&nbsp;&nbsp;
        <span th:text="${user.address}"></span><br>
    </div>
</body>
</html>

6.2.5 域对象的操作

也就是我们怎么在Thymeleaf中获取三大作用域中绑定的数据

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
    @RequestMapping("/hello4")
    public String hello4(HttpServletRequest request){
        request.setAttribute("req","request msg ...");
        request.getSession().setAttribute("sess","session msg ....");
        request.getServletContext().setAttribute("app","application msg ....");
        return "/user4";
    }
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Thymeleaf介绍</title>
</head>
<body><h1>域对象使用</h1>
    <h2>request:</h2>
    <span th:text="${#httpServletRequest.getAttribute('req')}"></span><br>
    <span th:text="${#request.getAttribute('req')}"></span><br>
    <span th:text="${req}"></span><br>
    <h2>session:</h2>
    <span th:text="${#httpSession.getAttribute('sess')}"></span><br>
    <span th:text="${#session.getAttribute('sess')}"></span><br>
    <h2>servletContext:</h2>
    <span th:text="${#servletContext.getAttribute('app')}"></span><br>
</body>
</html>

效果

6.2.6 URL表达式
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Thymeleaf介绍</title>
</head>
<body><h1>URL使用</h1>
    <a href="http://www.baidu.com">百度</a><br>
    <a th:href="@{http://www.baidu.com}">百度</a><br>
    <hr>
    <a th:href="@{/show}">相对路径</a><br>
    <a th:href="@{~/project2/app1}">相对于服务器的根</a><br>
    <a th:href="@{/show(id=1,name=aaa)}">相对路径--参数传递</a><br>
    <a th:href="@{/path/{id}/show(id=66,name=123)}">RestFul支持</a>
</body>
</html>

6.2.7 整合案例改造

我们可以将前面介绍的SpringBoot+MyBatis+Freemaker的案例改为SpringBoot+MyBatis+Thymeleaf的案例,涉及到的页面代码如下

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>用户管理</h1>
<h2>
    <a th:href="@{/user/dispatchUpdate}">添加用户</a>
</h2>
    <table>
        <tr>
            <th>编号</th>
            <th>账号</th>
            <th>姓名</th>
            <th>邮箱</th>
            <th>电话</th>
            <th>操作</th>
        </tr><tr th:each="user : ${list}">
            <td th:text="${user.user_id}"></td>
            <td th:text="${user.user_name}"></td>
            <td th:text="${user.real_name}"></td>
            <td th:text="${user.email}"></td>
            <td th:text="${user.phone}"></td>
            <td>
                <a th:href="@{/user/dispatchUpdate(id=${user.user_id})}">更新</a>
                <a th:href="@{/user/deleteUser(id=${user.user_id})}">删除</a>
            </td>
        </tr></table>
</body>
</html>
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form th:action="@{/user/userUpdate}" method="post" >
        <span th:if="${user}">
            <input type="hidden" name="user_id" th:value="${user.user_id}">
        </span><label>账号</label><input type="text" name="user_name" th:value="${ user==null ?'':user.user_name}"><br>
        <label>姓名</label><input type="text" name="real_name" th:value="${user==null ?'':user.real_name}"><br>
        <label>邮箱</label><input type="text" name="email" th:value="${user==null ?'':user.email}"><br>
        <label>电话</label><input type="text" name="phone" th:value="${user==null ?'':user.phone}"><br>
        <input type="submit" value="提交">
    </form>
</body>
</html>

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
1 条评论
热度
最新
笔记传送门:kdocs.cn/l/cgtkYcGAJdye
笔记传送门:kdocs.cn/l/cgtkYcGAJdye
回复回复点赞举报
推荐阅读
springboot(十五):springboot+jpa+thymeleaf增删改查示例
这篇文章介绍如何使用jpa和thymeleaf做一个增删改查的示例。 先和大家聊聊我为什么喜欢写这种脚手架的项目,在我学习一门新技术的时候,总是想快速的搭建起一个demo来试试它的效果,越简单越容易上手最好。在网上找相关资料的时候总是很麻烦,有的文章写的挺不错的但是没有源代码,有的有源代码但是文章介绍又不是很清楚,所在找资料的时候稍微有点费劲。因此在我学习Spring Boot的时候,会写一些最简单基本的示例项目,一方面方便其它朋友以最快的方式去了解,一方面如果我的项目需要用到相关技术的时候,直接在这个示例
纯洁的微笑
2018/04/18
1.6K0
springboot(十五):springboot+jpa+thymeleaf增删改查示例
Spring Boot (十五): Spring Boot + Jpa + Thymeleaf 增删改查示例
先和大家聊聊我为什么喜欢写这种脚手架的项目,在我学习一门新技术的时候,总是想快速的搭建起一个 Demo 来试试它的效果,越简单越容易上手最好。
纯洁的微笑
2019/08/20
6700
Spring Boot (十五): Spring Boot + Jpa + Thymeleaf 增删改查示例
SpringBoot【SpringMVC+mybatis完成CRUD案例】
  在main/src/resources目录下创建application.properties文件
用户4919348
2019/05/17
9220
springboot(15)Spring Security
在我们的项目开发中经常需要对页面做一些安全控制:对于没有访问权限的用户需要转到登录表单页面等。要实现访问控制的方法多种多样,可以通过Aop、拦截器实现,也可以通过框架(Apache Shiro、Spring Security)实现。Spring Security框架有两个概念:认证和授权,认证可以访问系统的用户,而授权则是用户可以访问的资源。 构建项目添加security依赖 <dependency> <groupId>org.springframework.boot</groupId>
IT架构圈
2018/06/01
5950
SpringBoot引入Thymeleaf
许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。
Bobby
2019/04/09
1.7K0
SpringBoot引入Thymeleaf
Spring全家桶之SpringBoot——初级阶段
• Spring Boot 设计目的是用来简化新Spring 应用的初始搭建以及开发过程。 • 嵌入的Tomcat,无需部署WAR 文件 • Spring Boot 并不是对Spring 功能上的增强,而是提供了一种快速使用Spring 的方式。
时间静止不是简史
2020/07/27
9070
Spring全家桶之SpringBoot——初级阶段
[SpringBoot——Web开发(使用Thymeleaf模板引擎)]
https://github.com/HCJ-shadow/SpringBootPlus
Noneplus
2019/09/24
4490
[SpringBoot——Web开发(使用Thymeleaf模板引擎)]
springboot安全之整合spring security实现(只有登录才有权限、不同用户显示不同内容、记住我)
1、新建一个springboot项目,选择web、thymeleaf、spring security
西西嘛呦
2020/08/26
8980
springboot安全之整合spring security实现(只有登录才有权限、不同用户显示不同内容、记住我)
SpringBoot 之 Web 使用 Thymeleaf 模板
SpringBoot 推荐使用 Thymeleaf,且默认不支持 JSP,因为 JSP 必须要打包war包才行。
AI码真香
2022/09/13
1.3K0
SpringBoot  之 Web 使用 Thymeleaf 模板
Spring Security 入门(五):在 Spring-Boot中的应用
前言 本文作为入门级的DEMO,完全按照官网实例演示; 项目目录结构 Maven 依赖 <parent> <groupId>org.springframework.boot</groupId>
程序猿DD
2018/03/26
1.6K0
Spring Security 入门(五):在 Spring-Boot中的应用
SpringBoot整合整合jsp、整合freemarker、整合Thymeleaf
1、SpringBoot整合整合jsp、整合freemarker、整合Thymeleaf。
别先生
2020/05/18
2.6K0
SpringBoot整合整合jsp、整合freemarker、整合Thymeleaf
SpringBoot高级使用
为了提高我们的开发效率,我们可以放开IDEA中的SpringBoot项目的热部署操作
Java鱼头
2022/12/01
7711
springboot开发之thymeleaf模板引擎
thymeleaf会默认访问classpath:/templates/下的html文件,因此发送/login请求时会返回/templates/success.html
西西嘛呦
2020/08/26
3360
springboot开发之thymeleaf模板引擎
springboot学习笔记-thymeleaf
简单说, Thymeleaf 是一个跟 Velocity、FreeMarker 类似的模板引擎,它可以完全替代 JSP 。相较与其他的模板引擎,它有如下三个极吸引人的特点:
Janti
2018/08/01
8410
springboot(19)-security
Spring Security是一种功能强大、高度可定制的身份验证和访问控制框架。这也是是保护基于Spring的应用程序的标准。
叔牙
2020/11/19
5150
springboot(19)-security
重学SpringBoot系列之整合静态资源与模板引擎
当然,可以通过spring.resources.static-locations配置指定静态文件的位置。但是要特别注意,一旦自己指定了静态资源目录,系统默认的静态资源目录就会失效。所以系统默认的就已经足够使用了,尽量不要自定义。
大忽悠爱学习
2021/12/07
5.3K0
重学SpringBoot系列之整合静态资源与模板引擎
Spring Security 登陆表单案例,结合数据库认证
在这篇 Spring Security 文章中,我们将学习怎么使用 Spring Security 和 MySQL 数据库进行数据库认证,并应用在自定义的登陆表单中。
Jimmy_is_jimmy
2023/11/28
3940
Spring Security 登陆表单案例,结合数据库认证
Spring Security (二) Guides
上一篇文章《Spring Security(一)--Architecture Overview》,我们介绍了Spring Security的基础架构,这一节我们通过Spring官方给出的一个guides例子,来了解Spring Security是如何保护我们的应用的,之后会对进行一个解读。 2 Spring Security Guides 2.1 引入依赖 <dependencies> <dependency> <groupId>org.springframework.boot</g
程序猿DD
2018/02/01
1.1K0
Spring Security (二) Guides
SpringBoot系列教程web篇之Thymeleaf环境搭建
上一篇博文介绍了如何使用Freemaker引擎搭建web项目,这一篇我们则看一下另外一个常见的页面渲染引擎Thymeleaf如何搭建一个web项目
一灰灰blog
2019/08/23
5370
SpringBoot系列教程web篇之Thymeleaf环境搭建
Spring Security 自定义登陆页面
在这个 Spring Security 教程中,我们将学到怎么创建一个自定义登陆页面来实现 Spring Security 基于表单的验证。
Jimmy_is_jimmy
2023/11/28
3670
Spring Security 自定义登陆页面
相关推荐
springboot(十五):springboot+jpa+thymeleaf增删改查示例
更多 >
LV.3
小作坊高级摸鱼攻城狮
目录
  • 综合案例
    • 5.1 项目创建
    • 5.2 查询用户信息
    • 5.3 添加用户
    • 5.4 更新用户
    • 5.5 删除用户
  • 6. Thymeleaf
    • 6.1 SpringBoot整合
    • 6.2 Thymeleaf基本使用
      • 6.2.1 变量输出
      • 6.2.2 内置函数
      • 6.2.3 条件判断
      • 6.2.4 循环语句
      • 6.2.5 域对象的操作
      • 6.2.6 URL表达式
      • 6.2.7 整合案例改造
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档