IDEA搭建Spring Boot项目(引入Mybatis Plus)

打开idea,左上角文件》》新建》》项目》》文件路径与名字(路径尽量不出现中文》》完成

等待右下角依赖性解析完成,随后打开左边pom.xml依赖,其中只包含保证运行的基本依赖和一个lombok

  <!-- Mybatis Plus整合-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>

        <!--Web支持(Spring Mvc)-->
        <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>

       <!--mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        
		<!--lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

修改配置文件在resources目录下新建yml文件(也可不新建,直接在application.properties中配置,但是yml文件可以使用缩进的形式省略重复的内容,语法比properties简洁)

 

spring:
  thymeleaf:
    cache: false # 关闭缓存,默认开启
  #    prefix: classpath:/pages/  #修改默认路径 classpath:/templates/
  datasource:
    url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8&serverTimezone=CTT
    username: root
    password:
    driver-class-name: com.mysql.cj.jdbc.Driver

# mybatis-plus配置
mybatis-plus:
  configuration:
    # 是否开启自动驼峰命名规则(camel case)映射,即从经典数据库列名 A_COLUMN(下划线命名) 到经典 Java 属性名 aColumn(驼峰命名) 的类似映射
    map-underscore-to-camel-case: true
    # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  #MyBaits 别名包扫描路径,通过该属性可以给包中的类注册别名
  type-aliases-package: com.company.springboot.entity
  #xml扫描,多个目录用逗号或者分号分隔(告诉 Mapper 所对应的 XML 文件位置)
  mapperLocations: classpath:mapper/*.xml

一个项目就创建完毕了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是基于 Spring BootMyBatis-Plus、Thymeleaf 和 Bootstrap 的留言板的实现步骤: 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 页面,使用 Thymeleaf 和 Bootstrap 实现留言板的展示和添加留言的表单。 8. 运行项目 使用 IDEA 运行项目,在浏览器中访问 http://localhost:8080/message 即可看到留言板页面。 以上就是基于 Spring BootMyBatis-Plus、Thymeleaf 和 Bootstrap 的留言板的实现步骤,你可以参考这些步骤来实现自己的留言板。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值