SpringBoot+通用Mapper+Thymeleaf+Bootstrap遇到的问题

SpringBoot+通用Mapper+Thymeleaf+Bootstrap整和遇到的问题

pom.xml:

主要是依赖jar包的配置

    <dependencies>
        <!--web依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--Mybatis依赖-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.4</version>
        </dependency>

        <!--数据库连接依赖-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.32</version>
            <scope>runtime</scope>
        </dependency>

        <!--单元测试依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- 通用mapper -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.0.2</version>
        </dependency>

        <!-- thymeleaf依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

application.yml文件配置:

此处导入的是mysql5.1.32版本的jar包因此仍然写旧的包名

#端口配置
server:
  port: 8080
spring:
  #jdbc配置
  datasource:
    #新版mysql包名:com.mysql.cj.jdbc.Driver
    driver-class-name: com.mysql.jdbc.Driver
    #新版mysql需要设置时区:&serverTimezone=GMT
    url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf8
    username: root
    password: root
  #thymeleaf配置
  thymeleaf:
    cache: false
    prefix: classpath:/templates/
    suffix: .html
    encoding: utf-8
    mode: HTML5
    servlet:
      content-type: text/html
  #springboot 引入js 和css 失效问题
  mvc:
    static-path-pattern: /static/**
#mybatis配置
mybatis:
  #实体类所在包名
  type-aliases-package: com.example.domain
#通用mapper配置
mapper:
  identity: MYSQL
  

遇到的主要问题:

在login.html页面导入本地的静态资源无法访问的问题

在这里插入图片描述
login.html页面导入本地静态资源

<link rel="stylesheet" href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}">
<script src="../static/js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>
<script src="../static/js/jquery-3.2.1.min.js" th:src="@{/js/jquery-3.2.1.min.js}"></script>

将静态资源导入后,必须重新Rebuild资源,否则静态资源无法加载。

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
好的,以下是基于 Spring Boot、MyBatis-Plus、ThymeleafBootstrap 的留言板的实现步骤: 1. 创建 Spring Boot 项目 在 IDEA 中创建一个 Spring Boot 项目,选择 Web 和 Thymeleaf 作为依赖。 2. 添加 MyBatis-Plus 依赖 在 pom.xml 文件中添加 MyBatis-Plus 依赖: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.0</version> </dependency> ``` 3. 创建留言板数据表 在 MySQL 中创建一个名为 message_board 的数据表,包含以下字段: ```sql CREATE TABLE `message_board` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL COMMENT '留言人姓名', `email` varchar(50) NOT NULL COMMENT '留言人邮箱', `content` varchar(255) NOT NULL COMMENT '留言内容', `create_time` datetime NOT NULL COMMENT '创建时间', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留言板'; ``` 4. 创建 MyBatis-Plus 实体类和 Mapper 使用 MyBatis-Plus 的代码生成器,生成 Message 实体类和 MessageMapper 接口。 5. 编写 Service 层 创建 MessageService 接口和 MessageServiceImpl 实现类,其中 MessageServiceImpl 实现类注入 MessageMapper,实现增删改查等方法。 6. 编写 Controller 层 创建 MessageController 类,其中注入 MessageService,实现留言板的展示、添加留言和删除留言等功能。 7. 编写 Thymeleaf 页面 在 templates 目录下创建 message.html 页面,使用 ThymeleafBootstrap 实现留言板的展示和添加留言的表单。 8. 运行项目 使用 IDEA 运行项目,在浏览器中访问 http://localhost:8080/message 即可看到留言板页面。 以上就是基于 Spring Boot、MyBatis-Plus、ThymeleafBootstrap 的留言板的实现步骤,你可以参考这些步骤来实现自己的留言板。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值