SpringBoot +LayUI+thymeleaf 实现一个功能(一)准备工作

tech2023-02-11  118

前言 经过一段时间的积累,我们需要通过一个项目验证一下我们的技术,那么通过一个前后端实现项目是最好不不过了。在网上看过一个视频教程,就一步步做下去,期间走过了很多弯路(不是别人的有错误,而是开发版本的问题),所以实践才是真理。 创建数据库 数据库类型:Mysql 数据库名称:sridb 表名:dept 表结构:

字段类型长度注释idbigint20主键parent_idbigint20上级部门ID。一级部门为0namevarchar50部门名称typetinyint2类型。0:公司;1:部门;2:科室/小组sortint11排序值。越小越靠前statustinyint2状态。0:正常;1:禁用update_timedatetime0修改时间create_bybigint20创建人create_timedatetime0创建时间

配置Spring Boot SDK:JAVA 11 项目结构: 依赖 pom.xml

<?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.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.flo</groupId> <artifactId>flo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>flo</name> <description>Flo project for Spring Boot</description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.2</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.22</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.10</version> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.68</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.10</version> </dependency> <!-- mybatis-plus相关依赖 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.3.0</version> </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.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.10</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <!--生产xml--> <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 --> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.yml</include> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.yml</include> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.html</include> <include>**/*.css</include> <include>**/*.js</include> <include>**/*.*</include> </includes> <filtering>false</filtering> </resource> </resources> </build> </project>

运行环境配置 application.properties

#端口 server.port=8888 server.servlet.context-path=/ #旧Mysql 驱动使用 com.mysql.jdbc.Driver 新Mysql:com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/sridb?useUnicode=true&amp&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password=123456 #数据源引擎 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource #反射文件 mybatis.mapper-locations=classpath:com/flo/dao/*.xml mybatis.type-aliases-package=com.flo.po spring.resources.static-locations=classpath:/static/,classpath:/templates/ #热启动 spring.devtools.restart.enabled=true #日期格式 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss spring.jackson.time-zone=GMT+8

主程序Floapplication

package com.flo; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @MapperScan("com.flo.dao") public class FloApplication { public static void main(String[] args) { SpringApplication.run(FloApplication.class, args); } }

配置LayUI 下载LayuiMini

配置到Spring boot 简单验证运行环境 启动Spring boot

最新回复(0)