【SpringBoot】| ORM 操作 MySQL(集成MyBatis)

这篇具有很好参考价值的文章主要介绍了【SpringBoot】| ORM 操作 MySQL(集成MyBatis)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

一:ORM 操作 MySQL 

1. 创建 Spring Boot 项目

2. @MapperScan

3. mapper文件和java代码分开管理

4. 事务支持


一:ORM 操作 MySQL 

使用MyBatis框架操作数据, 在SpringBoot框架集成MyBatis,使用步骤:

(1)mybatis起步依赖 : 完成mybatis对象自动配置, 对象放在容器中

(2)pom.xml 指定把src/main/java目录中的xml文件包含到classpath中

(3)创建实体类Student

(4)创建Dao接口 StudentDao , 创建一个查询学生的方法

(5)创建Dao接口对应的Mapper文件, xml文件, 写sql语句

(6)创建Service层对象, 创建StudentService接口和它的实现类。 去dao对象的方法,完成数据库的操作

(7)创建Controller对象,访问Service。

(8)写application.properties文件,配置数据库的连接信息。

1. 创建 Spring Boot 项目

(1)准备数据库表

字段及其类型

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

 插入数据

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

 (2)创建一个SpringBoot项目

选择Spring Web依赖

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

MybatisFramework依赖、MySQL Driver依赖

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

(3)生成的pom.xml配置和手动添加的resource插件配置

注:resource插件配置是表示将src/java/main下的或者说子包下的*.xml配置文件最终加载到target/classes目录下。

<?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.7.9</version>
        <relativePath/>
    </parent>
    <groupId>com.zl</groupId>
    <artifactId>study-springboot-mysql</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <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.3.0</version>
        </dependency>
        <!--mysql驱动依赖-->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--测试-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <!--手动添加resources插件-->
        <resources>
            <resource>
                <!--指定目录-->
                <directory>src/main/java</directory>
                <!--指定目录下的文件-->
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>

        <!--plugins插件-->
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

(4)实体类

准备一个实体类,类的属性名与数据库中的字段名保持一致。

package com.zl.pojo;

public class Student {
    private Integer id;
    private String name;
    private Integer age;

    public Student() {
    }

    public Student(Integer id, String name, Integer age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

(5)创建Dao接口

需要在类上加@Mapper注解:告诉MyBatis这是一个dao接口,创建此接口的代理对象。

package com.zl.dao;

import com.zl.pojo.Student;
import org.apache.ibatis.annotations.Mapper;

@Mapper //用来创建代理对象的
public interface StudentDao {
    // 根据id进行查询
    Student selectById(@Param("stuId") Integer id);
}

(6)在Dao接口下创建一个同名的StudentDao.xml文件

注:前面我们配置的resource配置就是为这个StudentDao.xml配置服务的!

<?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.zl.dao.StudentDao">
    <!--编写sql语句,id是这条sql语句的唯一表示-->
    <select id="selectById" resultType="com.zl.pojo.Student">
        select id,name,age from t_student where id = #{stuId}
    </select>
</mapper>

(7)编写Service接口和对应的实现类

StudentService接口

package com.zl.service;

import com.zl.pojo.Student;

public interface StudentService {
    // 方法调用
   Student queryStudent(Integer id);

}

StudentService接口实现类,编写业务逻辑

package com.zl.service.impl;

import com.zl.dao.StudentDao;
import com.zl.pojo.Student;
import com.zl.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service // 交给Spring容器管理
public class StudentServiceImpl implements StudentService {

    // 调用Dao
    @Resource // 给属性赋值
    private StudentDao studentDao;

    @Override
    public Student queryStudent(Integer id) {
        Student student = studentDao.selectById(id);
        return student;
    }
}

(8)创建controller去调用service

package com.zl.controller;

import com.zl.pojo.Student;
import com.zl.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller 
public class StudentController {
    @Resource
    public StudentService studentService;
    
    @RequestMapping("/student/query")
    @ResponseBody
    public String queryStudent(Integer id){
        Student student = studentService.queryStudent(id);
        return student.toString();
    }
}

(9)连接数据库,需要application.properties配置

useUnicode使用unicode编码,characterEncoding字符集是utf-8,serverTimezone时区。

server.port=9090
server.servlet.context-path=/orm
#连接数据库的配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123

(10)执行结果

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

2. @MapperScan

如果有多个Dao接口,那么需要在每个Dao接口上都加入@Mapper注解,比较麻烦!

StudentDao接口

package com.zl.dao;

import com.zl.pojo.Student;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface StudentDao {
    // 根据id进行查询
    Student selectById(Integer id);
}

UserDao接口

package com.zl.dao;

import com.zl.pojo.User;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface UserDao {
    // 根据id进行查询
    SUser selectById(Integer id);
}

也可以在主类上(启动类上)添加注解包扫@MapperScan("com.zl.dao")

注:basePackages是一个String数组,可以写多个要扫描的包。

package com.zl;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan(basePackages = "com.zl.dao")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

细节:

如果我们导入一个项目,对于IDEA是不能识别resources的,图标如下:

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

右击鼠标----》Mark Directory as-----》 Resources Root即可

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

此时的图标如下: 

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

3. mapper文件和java代码分开管理

现在的xml文件和java代码是放在同一个包下管理的!

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

 也可以分开存储,把xml文件放到resources目录下!在resources下创建一个mapper目录,把所有的*.xml全都放进去;但是此时就找不到了,需要我们去配置指定。

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

 此时需要在application.properties文件里指定:

#指定mapper文件的位置
mybatis.mapper-locations=classpath:mapper/*.xml

注:此时低版本的Springboot可能出现application.properties文件没有编译到target/classes目录的情况下,此时就需要修改resources插件配置:

<resources>
     <resource>
       <directory>src/main/resources</directory>
       <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>  
       </includes>
     </resource>
</resources>

要想看到SQL语句的信息,需要在application.properties中添加日志框架

#指定mybatis的日志,使用StdOutImpl输出到控制台
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

此时就可以看到SQL语句的日志信息

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

4. 事务支持

Spring框架中的事务:

(1)使用管理事务的对象: 事务管理器(接口, 接口有很多的实现类)

例:使用Jdbc或mybatis访问数据库,使用的事务管理器:DataSourceTransactionManager

(2)声明式事务: 在xml配置文件或者使用注解说明事务控制的内容

控制事务: 隔离级别,传播行为, 超时时间等

(3)事务处理方式:

①Spring框架中的@Transactional;

②aspectj框架可以在xml配置文件中,声明事务控制的内容;

SpringBoot使用事务非常简单,底层依然采用的是 Spring 本身提供的事务管理

①在业务方法的上面加入@Transactional , 加入注解后,方法有事务功能了。

②在主启动类的上面 ,加入@EnableTransactionManager,开启事务支持。

注:只加上@Transactional也能完成事务的功能,对于@EnableTransactionManager建议也加上。

第一步:创建一个SpringBoot项目,引入:Spring Web、MybatisFramework、MySQL Driver

第二步:使用mybatis逆向工程插件生成个pojo类、dao接口

①添加Mybatis逆向工程的插件

注:这个插件是需要MySQL驱动依赖的,如果这里没有引入MySQL驱动的依赖,那么下面的generatorConfig.xml配置中就需要<classPathEntry>标签去指定连接数据库的JDBC驱动包所在位置,指定到你本机的完整路径 ,例如:<classPathEntry location="E:\mysql-connector-java-5.1.38.jar"/>。

<!--mybatis逆向⼯程插件-->
<plugin>
     <!--插件的GAV坐标-->
     <groupId>org.mybatis.generator</groupId>
     <artifactId>mybatis-generator-maven-plugin</artifactId>
     <version>1.4.1</version>
    
     <configuration>
            <!--配置文件的位置,放在项目根目录下必须指定一下-->
	       <!--<configurationFile>GeneratorMapper.xml</configurationFile>-->
            <!--允许覆盖-->
           <overwrite>true</overwrite>
     </configuration>
     <!--插件的依赖-->
     <dependencies>
         <!--mysql驱动依赖-->
         <dependency>
               <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.23</version>
         </dependency>
      </dependencies>
</plugin>

②编写generatorConfig.xml配置文件

注:如果下面的generatorConfig.xml配置文件放到src的resources目录下,那么配置文件的名字必须是generatorConfig.xml(不区分大小写),并且不需要上面的<configurationFile>标签去指定。

注:如果我们把generatorConfig.xml配置文件直接放到项目的根目录下(和src同级目录),那么此时generatorConfig.xml配置文件的名字随意,但是必须使用上面的<configurationFile>标签去指定一下(两者保持一致即可)。

注:当然也可以不直接放到项目的根目录下,例如:放到src/main目录下,那么对于<configurationFile>标签就需要指定src/main/generatorConfig.xml(两者也要保持一致)

注:对于高版本的MySQL驱动,对于URL后面必须跟上时区,但是在xml中是无法识别&,所以需要使用&amp去替换,例如:

connectionURL="jdbc:mysql://localhost:3306/springdb?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=GMT%2B8"

最终会生成*.xml配置,要想让它最终编译后放到target/classes中,就需要配置处理资源目录

<!--处理资源目录-->
<resources>
    <resource>
       <directory>src/main/java</directory>
       <includes>
             <include>**/*.xml</include>
             <include>**/*.properties</include>
       </includes>
    </resource>
    <resource>
       <directory>src/main/resources</directory>
       <includes>
             <include>**/*.xml</include>
             <include>**/*.properties</include>
       </includes>
    </resource>
</resources>

 generatorConfig.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>


    <!-- 指定连接数据库的JDBC驱动包所在位置,如果前面插件中指定了,这里就不要指定了 -->
    <!--<classPathEntry location="E:\mysql-connector-java-5.1.38.jar"/>-->

    <!--
        targetRuntime有两个值:
            MyBatis3Simple:生成的是基础版,只有基本的增删改查。
            MyBatis3:生成的是增强版,除了基本的增删改查之外还有复杂的增删改查。
    -->
    <context id="DB2Tables" targetRuntime="MyBatis3Simple">
        <!--防止生成重复代码-->
        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"/>

        <commentGenerator>
            <!--是否去掉生成日期-->
            <property name="suppressDate" value="true"/>
            <!--是否去除注释-->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <!--连接数据库信息-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/springboot"
                        userId="root"
                        password="123">
        </jdbcConnection>

        <!-- 生成pojo包名和位置 -->
        <javaModelGenerator targetPackage="com.zl.pojo" targetProject="src/main/java">
            <!--是否开启子包-->
            <property name="enableSubPackages" value="true"/>
            <!--是否去除字段名的前后空白-->
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!-- 生成SQL映射文件的包名和位置 -->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
            <!--是否开启子包-->
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <!-- 生成Mapper接口的包名和位置 -->
        <javaClientGenerator
                type="xmlMapper"
                targetPackage="com.zl.mapper"
                targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!-- 表名和对应的实体类名-->
        <table tableName="t_Student" domainObjectName="Student"/>

    </context>
</generatorConfiguration>

双击插件,执行结果如下:

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

第三步:编写application.properties配置

注:如果StudentMapper.xml的目录与StudentMapper目录保持一致,就不需要以下这个配置mybatis.mapper-locations=classpath:mapper/*.xml;这里我们是自己定义的mapper目录,把mapper.xml文件放进去了,所以需要我们指定出来它的位置!

#设置端口
server.port=8082
#配置项目根路径context-path
server.servlet.context-path=/myboot
#配置数据库
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123
#配置mybatis
mybatis.mapper-locations=classpath:mapper/*.xml
#配置日志
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

第四步:编写service接口和实现类

StudentService接口

package com.zl.service;

import com.zl.pojo.Student;

public interface StudentService {
    int addStudent(Student student);
}

StudentService接口的实现类StudentServiceImpl

package com.zl.service.impl;

import com.zl.mapper.StudentMapper;
import com.zl.pojo.Student;
import com.zl.service.StudentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service // 交给Spring容器管理
public class StudentServiceImpl implements StudentService {

    @Resource // 属性赋值
    private StudentMapper studentDao;

    @Transactional // 事务控制
    @Override
    public int addStudent(Student student) {
        System.out.println("准备执行sql语句");
        int count = studentDao.insert(student);
        System.out.println("已完成sql语句的执行");
        // 模拟异常,回滚事务
        int sum = 10 / 0;

        return count;
    }
}

第五步:编写controller类去调用service

package com.zl.controller;

import com.zl.pojo.Student;
import com.zl.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class StudentController {

    @Resource
    private StudentService studentService;


    @RequestMapping("/addStudent")
    @ResponseBody
    public String addStudent(String name,Integer age){
        Student s = new Student();
        s.setName(name);
        s.setAge(age);
        int count = studentService.addStudent(s);
        return "添加的Student个数是:"+count;
    }
}

第六步:在启动类上面加上包扫描注解和启动事务管理器注解

package com.zl;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@MapperScan(basePackages = "com.zl.mapper") // 添加包扫描
@EnableTransactionManagement // 启动事务管理器
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

第七步:进行测试

有异常发生,会回滚事务,无法插入数据

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java

 无异常发生,正常插入数据

【SpringBoot】| ORM 操作 MySQL(集成MyBatis),第五步:互联网分布式,mysql,spring boot,java文章来源地址https://www.toymoban.com/news/detail-634821.html

到了这里,关于【SpringBoot】| ORM 操作 MySQL(集成MyBatis)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • SpringBoot中间件—ORM(Mybatis)框架实现

    目录 定义 需求背景 方案设计 代码展示 UML图  实现细节 测试验证  总结 源码地址(已开源) :https://gitee.com/sizhaohe/mini-mybatis.git  跟着源码及下述UML图来理解上手会更快, 拒绝浮躁,沉下心来搞         ORM:Object Relational Mapping  --  对象关系映射,是一种程序设计技术,

    2024年02月16日
    浏览(25)
  • 第五步:STM32F4端口复用

    STM32 有很多的内置外设,这些外设的外部引脚都是与 GPIO 复用的。也就是说,一个 GPIO 如果可以复用为内置外设的功能引脚,那么当这个 GPIO 作为内置外设使用的时候,就叫做复用。 例如串口 1 的发送接收引脚是 PA9,PA10 ,当我们把 PA9,PA10 不用作 GPIO ,而用做复用功能串口

    2024年02月12日
    浏览(47)
  • Springboot引入mybatis-plus及操作mysql的json字段

    springboot引入mybatis-plus,创建springboot项目省略 pom文件 配置文件 备注信息 springboot使用mybatis和mybatis-plus没有什么区别,需要注意的是配置文件跟配置名:mybatis-plus 使用mybatis-plus的有点在于,在mybatis的基础上记性了一系列的有效封装,节约了开发时间,有这方面兴趣额同学自行

    2024年02月06日
    浏览(39)
  • Win10/Win11 自动更新永久关闭【自用,推荐直接使用第五步即可】

    快捷键 windows 键 + R 打开运行框,输入 services.msc 需要确认关闭的三个服务项:Windows Update, Windows 安全中心服务(SecurityHealthService),Windows 更新医生服务(WaaSMedicSvc) windows update “启动类型”设置为禁用或手动,并将“恢复”的失败操作均设置为无操作 正常而言,除了 Win

    2024年02月08日
    浏览(40)
  • python使用SQLAlchemy进行mysql的ORM操作

    现在很多的企业进行后端开发时,程序员在分析完业务后,会使用Java的SpringBoot或者Python的Django、Flask等网络框架进行项目开发。在这些网络框架业务逻辑代码编写的过程中,很大概率会需要使用到MySQL数据库,但是原生的SQL语句又存在被SQL注入的风险,而且在复杂的查询时,

    2024年02月07日
    浏览(42)
  • SpringBoot 集成 Mybatis

    (只有操作,没有理论,仅供参考学习) 1.1 数据库版本: 1.2 启动 mysql 服务: 1.3 新创建数据库 spring,并创建一个 user 表,user 表详情: 如下图: 2.1 使用 spring 官网页面创建工程(其他亦可),链接:Spring Initializr 创建 SpringBoot 工程,如下图: 2.2 用 IDEA 打开工程: 2.3 配置

    2024年02月16日
    浏览(40)
  • 1. Springboot集成Mybatis

    在深入理解mybatis源码之前,首先搭建mybatis的测试环境用于跟踪代码测试用。 下面介绍两种springboot集成mybatis运行环境的案例。一种是通过springboot包装mybatis的构建过程,一种是自行构建Mybatis的执行环境。 以查询user表为例,数据如下 1.1 创建表对应的bean 1.2 创建查询接口dao

    2023年04月19日
    浏览(29)
  • 【极光系列】SpringBoot集成Mybatis

    浅夏的猫 @shawsongyue 直接下载可用 https://gitee.com/shawsongyue/aurora.git 详细参考我的另外一遍博客: https://blog.csdn.net/weixin_40736233/article/details/135582926?spm=1001.2014.3001.5501 1. 处理依赖pom.xml 2. 处理数据库表 登录mysql数据库,创建表 tianchi_resource,并插入数据 3. 处理配置application.yml 4.创

    2024年01月17日
    浏览(39)
  • Springboot集成MyBatis进行开发

    引入相关的依赖 2.配置application.yml        application.java 3.建表 在数据库中创建相应的表 4.键实体 在.java文件中引入数据库表中的字段,创建无参,有参构造函数和getter、setter、toString方法。 5.开发dao mapper文件 Userdao.java:定义实现的方法 mapper文件:编写方法的实现 6.开发serv

    2023年04月12日
    浏览(30)
  • idea 搭建 SpringBoot 集成 mybatis

    编译器:IDEA 环境:win10,jdk1.8,maven3.5 数据库:mysql 5.7 一、打开IDEA新建项目 1. 如果你是第一次使用IDEA,那么你需要配置你本地的maven,点击右下角 Configure,如已配置请忽略此步骤 在下拉框中选择setting,然后如下图操作,选择自己本地的maven路径与maven配置文件 点击OK 2.新

    2024年02月15日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包