国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot 集成 Mybatis

這篇具有很好參考價(jià)值的文章主要介紹了SpringBoot 集成 Mybatis。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

SpringBoot 集成 Mybatis 詳細(xì)教程

(只有操作,沒有理論,僅供參考學(xué)習(xí))

一、操作部分

1. 準(zhǔn)備數(shù)據(jù)庫

1.1 數(shù)據(jù)庫版本:

C:\WINDOWS\system32>mysql -V
mysql  Ver 8.0.25 for Win64 on x86_64 (MySQL Community Server - GPL)

1.2 啟動(dòng) mysql 服務(wù):

C:\WINDOWS\system32>net start mysql
The MySQL service is starting..
The MySQL service was started successfully.

1.3 新創(chuàng)建數(shù)據(jù)庫 spring,并創(chuàng)建一個(gè) user 表,user 表詳情:

Column Name 		Datatype		PrimaryKey 		Unique
id     				  INT				√			  √
username			  VARCHAR(45)	
password			  VARCHAR(45)	

如下圖:

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

2. 創(chuàng)建工程

2.1 使用 spring 官網(wǎng)頁面創(chuàng)建工程(其他亦可),鏈接:Spring Initializr 創(chuàng)建 SpringBoot 工程,如下圖:

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

2.2 用 IDEA 打開工程:

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

2.3 配置項(xiàng)目的 maven 環(huán)境:
File -> Setting... -> Maven

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端
2.4 導(dǎo)入依賴 pom.xml 文件:

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <version>8.0.25</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

注意點(diǎn):由于我的項(xiàng)目運(yùn)行有報(bào)錯(cuò)的原因,我把項(xiàng)目的版本調(diào)整了一下:
修正前:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.13</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

修正后:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

配置完成后完整的 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.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.buzl</groupId>
    <artifactId>main</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>main</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>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <version>8.0.25</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
    </dependencies>

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

</project>

2.5 配置數(shù)據(jù)庫連接文件 application.properties

注意點(diǎn)
第一行的數(shù)據(jù)庫要修改為自己的數(shù)據(jù)庫名稱,我的數(shù)據(jù)庫名稱是 spring,根據(jù)實(shí)際需求更改
第二行和第三行是連接數(shù)據(jù)庫的用戶名和密碼,根據(jù)實(shí)際需求更改
第四行是數(shù)據(jù)庫的驅(qū)動(dòng),使用 com.mysql.cj.jdbc.Driver 還是 com.mysql.jdbc.Driver 按需更改
第五行是 mybatis mapper 文件路徑,我的文件路徑是:resources/mapper/UserMapper.xml,按需更改

spring.datasource.url=jdbc:mysql://localhost:3306/spring?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.mapper-locations=classpath:mapper/*.xml

2.6 創(chuàng)建 User.java 實(shí)體類

public class User {

    /**
     * 主鍵 id
     */
    private Integer id;

    private String username;

    private String password;
    
    public User(Integer id, String username, String password) {
        this.id = id;
        this.username = username;
        this.password = password;
    }

    /**
     * 重寫 toString 方法
     * @return
     */
    @Override
    public String toString() {
        return "User{" +
                "id = " + id +
                "\t username = " + username +
                "\t password = " + password +
                "}";
    }
    // set and get method ...
}

2.7 創(chuàng)建 UserMapper 接口

@Mapper // 表示這是一個(gè) Mybatis 的 mapper 類
@Repository
public interface UserMapper {

    @Autowired
    int insertUser(User user);
    
    @Autowired
    int deleteByPrimaryKey(Integer id);
    
    @Autowired
    User selectByPrimaryKey(Integer id);
    
    @Autowired
    int updateUserByPrimaryKey(User user);
    
    @Autowired
    List<User> selectAll();
    
}

2.8 創(chuàng)建 UserMapper 控制器

@RestController
@RequestMapping("/mybatis")
public class UserConroller {

    @Resource
    private UserMapper userMapper;

    @GetMapping("/selectAll")
    public List<User> selectAll() {
        List<User> userList = userMapper.selectAll();
        return userList;
    }

    @GetMapping("/selectByPrimaryKey")
    public User selectByPrimaryKey() {
        User user = userMapper.selectByPrimaryKey(111);
        return user;
    }

    @GetMapping("/insertSelective")
    public String insertUser() {
        User user = new User(123, "梅花", "pwd123");
        userMapper.insertUser(user);
        return "insert data to database success!";
    }

    @GetMapping("/updateByPrimaryKeySelective")
    public String updateUserByPrimaryKey() {
        Integer id = 123;
        User user = new User(id, "劉備", "pwd666");
        userMapper.updateUserByPrimaryKey(user);
        return "database updated success!";
    }

    @GetMapping("/deleteByPrimaryKey")
    public String deleteByPrimaryKey() {
        Integer id = 123;
        userMapper.deleteByPrimaryKey(id);
        return "delete database success!";
    }

}

2.6 UserMapper.xml 文件

注意點(diǎn)id 的值要和 UserMapper 接口的函數(shù)名稱對(duì)應(yīng)上
如:

 xml 文件 id 的值 selectAll 名字和 UserMapper 接口中的函數(shù)名一一對(duì)應(yīng)
xml 文件:
<select id="selectAll" resultType="com.buzl.main.entity.User">

UserMapper 接口函數(shù):
@Autowired
List<User> selectAll();
<?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.buzl.main.mapper.UserMapper">

    <!--共通屬性抽出-->
    <sql id="Base_Column_List">
        id,username,password
    </sql>

    <!--查詢數(shù)據(jù)庫中所有的數(shù)據(jù)-->
    <select id="selectAll" resultType="com.buzl.main.entity.User">
        <!--select * from spring.user-->
        select <include refid="Base_Column_List" /> from spring.user
    </select>

    <!--通過 id 查詢數(shù)據(jù)-->
    <select id="selectByPrimaryKey" resultType="com.buzl.main.entity.User">
        select <include refid="Base_Column_List" /> from spring.user where id=#{id}
    </select>

    <!--向數(shù)據(jù)庫中插入數(shù)據(jù)-->
    <insert id="insertUser" parameterType="com.buzl.main.entity.User">
        insert into spring.user(<include refid="Base_Column_List" />) values(#{id},#{username},#{password})
    </insert>

    <!--更新數(shù)據(jù)庫中的數(shù)據(jù)-->
    <update id="updateUserByPrimaryKey" parameterType="com.buzl.main.entity.User">
        update spring.user set username=#{username},password=#{password} where id=#{id}
    </update>

    <!--通過 id 刪除數(shù)據(jù)-->
    <delete id="deleteByPrimaryKey" parameterType="Integer">
        delete from spring.user where id=#{id}
    </delete>

</mapper>

二、代碼部分

1. 項(xiàng)目目錄結(jié)構(gòu):

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

2. User 實(shí)體類

package com.buzl.main.entity;

/**
 * 實(shí)體類
 *
 * @author buzenglai@gmail.com
 * @data 2023-07-10
 */
public class User {

    /**
     * 主鍵 id
     */
    private Integer id;

    private String username;

    private String password;

    public Integer getId() {
        return id;
    }

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

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public User(Integer id, String username, String password) {
        this.id = id;
        this.username = username;
        this.password = password;
    }

    /**
     * 重寫 toString 方法
     * @return
     */
    @Override
    public String toString() {
        return "User{" +
                "id = " + id +
                "\t username = " + username +
                "\t password = " + password +
                "}";
    }

}

3. UserController 控制器類

package com.buzl.main.controller;

import com.buzl.main.mapper.UserMapper;
import com.buzl.main.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * controller 實(shí)現(xiàn)
 *
 * @author buzenglai@gmail.com
 * @data 2023-07-10
 */
@RestController
@RequestMapping("/mybatis")
public class UserConroller {

    @Resource
    private UserMapper userMapper;

    /**
     * 查詢數(shù)據(jù)操作
     *
     * @return
     */
    @GetMapping("/selectAll")
    public List<User> selectAll() {
        List<User> userList = userMapper.selectAll();
        System.out.println("數(shù)據(jù)庫中所有的 user 數(shù)據(jù) :" + userList);
        return userList;
    }

    /**
     * 通過 id 查詢操作
     *
     * @return
     */
    @GetMapping("/selectByPrimaryKey")
    public User selectByPrimaryKey() {
        User user = userMapper.selectByPrimaryKey(111);
        System.out.println("通過 id 查詢出來的 user : " + user);
        return user;
    }

    /**
     * 插入數(shù)據(jù)
     *
     * @return
     */
    @GetMapping("/insertSelective")
    public String insertUser() {
        User user = new User(123, "梅花", "pwd123");
        userMapper.insertUser(user);
        System.out.println("user :" + user + " 被成功插入數(shù)據(jù)庫");
        return "insert data to database success!";
    }

    /**
     * 更新數(shù)據(jù)
     *
     * @return
     */
    @GetMapping("/updateByPrimaryKeySelective")
    public String updateUserByPrimaryKey() {
        Integer id = 123;
        User user = new User(id, "劉備", "pwd666");
        userMapper.updateUserByPrimaryKey(user);
        System.out.println("數(shù)據(jù)庫中 id = " + id + " 的數(shù)據(jù)已經(jīng)被更新了");
        return "database updated success!";
    }

    /**
     * 刪除數(shù)據(jù)
     *
     * @return
     */
    @GetMapping("/deleteByPrimaryKey")
    public String deleteByPrimaryKey() {
        Integer id = 123;
        userMapper.deleteByPrimaryKey(id);
        System.out.println("數(shù)據(jù)庫中 id = " + id + " 的 user 數(shù)據(jù)已經(jīng)被刪除了");
        return "delete database success!";
    }

}

4. UserMapper 接口

package com.buzl.main.mapper;

import com.buzl.main.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 接口類
 *
 * @author buzenglai@gmail.com
 * @data 2023-07-10
 */
@Mapper // 表示這是一個(gè) Mybatis 的 mapper 類
@Repository
public interface UserMapper {

    /**
     * 向數(shù)據(jù)庫中插入一條數(shù)據(jù)
     *
     * @param user
     * @return
     */
    @Autowired
    int insertUser(User user);

    /**
     * 通過主鍵 id 刪除數(shù)據(jù)
     *
     * @param id
     * @return
     */
    @Autowired
    int deleteByPrimaryKey(Integer id);

    /**
     * 通過主鍵 id 刪除數(shù)據(jù)庫中的數(shù)據(jù)
     *
     * @param id
     * @return
     */
    @Autowired
    User selectByPrimaryKey(Integer id);

    /**
     * 通過主鍵 id 更新數(shù)據(jù)庫中的數(shù)據(jù)
     *
     * @param user
     * @return
     */
    @Autowired
    int updateUserByPrimaryKey(User user);

    /**
     * 查詢數(shù)據(jù)庫中所有的數(shù)據(jù)
     *
     * @return
     */
    @Autowired
    List<User> selectAll();

}

5. UserMapper.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.buzl.main.mapper.UserMapper">

    <!--共通屬性抽出-->
    <sql id="Base_Column_List">
        id,username,password
    </sql>

    <!--查詢數(shù)據(jù)庫中所有的數(shù)據(jù)-->
    <select id="selectAll" resultType="com.buzl.main.entity.User">
        <!--select * from spring.user-->
        select <include refid="Base_Column_List" /> from spring.user
    </select>

    <!--通過 id 查詢數(shù)據(jù)-->
    <select id="selectByPrimaryKey" resultType="com.buzl.main.entity.User">
        select <include refid="Base_Column_List" /> from spring.user where id=#{id}
    </select>

    <!--向數(shù)據(jù)庫中插入數(shù)據(jù)-->
    <insert id="insertUser" parameterType="com.buzl.main.entity.User">
        insert into spring.user(<include refid="Base_Column_List" />) values(#{id},#{username},#{password})
    </insert>

    <!--更新數(shù)據(jù)庫中的數(shù)據(jù)-->
    <update id="updateUserByPrimaryKey" parameterType="com.buzl.main.entity.User">
        update spring.user set username=#{username},password=#{password} where id=#{id}
    </update>

    <!--通過 id 刪除數(shù)據(jù)-->
    <delete id="deleteByPrimaryKey" parameterType="Integer">
        delete from spring.user where id=#{id}
    </delete>

</mapper>

6. 數(shù)據(jù)庫連接配置文件:

spring.datasource.url=jdbc:mysql://localhost:3306/spring?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.mapper-locations=classpath:mapper/*.xml

7. 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.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.buzl</groupId>
    <artifactId>main</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>main</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>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--springboot 集成 mybatis,導(dǎo)入依賴-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>
        <!--mysql 驅(qū)動(dòng)-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <version>8.0.25</version>
        </dependency>
        <!--jdbc連接數(shù)據(jù)庫-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
    </dependencies>

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

</project>

三、測試

使用 ApiFox 工具進(jìn)行測試(用瀏覽器也是一樣)

  1. 查詢數(shù)據(jù)庫中所有的數(shù)據(jù):

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

  1. 通過 id 查詢數(shù)據(jù)庫中的數(shù)據(jù):

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

  1. 向數(shù)據(jù)庫中插入數(shù)據(jù):

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

  1. 通過 id 更改數(shù)據(jù)庫中的數(shù)據(jù)

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端

  1. 通過 id 刪除數(shù)據(jù)庫的數(shù)據(jù)
    SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端
    SpringBoot 集成 Mybatis,Spring,spring boot,mybatis,后端
  2. 控制臺(tái)打印信息:
數(shù)據(jù)庫中所有的 user 數(shù)據(jù) :[User{id = 111	 username = 張三	 password = pwd111}, User{id = 222	 username = 李四	 password = pwd222}]
數(shù)據(jù)庫中所有的 user 數(shù)據(jù) :[User{id = 111	 username = 張三	 password = pwd111}, User{id = 222	 username = 李四	 password = pwd222}]
通過 id 查詢出來的 user : User{id = 111	 username = 張三	 password = pwd111}
user :User{id = 123	 username = 梅花	 password = pwd123} 被成功插入數(shù)據(jù)庫
數(shù)據(jù)庫中所有的 user 數(shù)據(jù) :[User{id = 111	 username = 張三	 password = pwd111}, User{id = 123	 username = 梅花	 password = pwd123}, User{id = 222	 username = 李四	 password = pwd222}]
數(shù)據(jù)庫中 id = 123 的數(shù)據(jù)已經(jīng)被更新了
數(shù)據(jù)庫中所有的 user 數(shù)據(jù) :[User{id = 111	 username = 張三	 password = pwd111}, User{id = 123	 username = 劉備	 password = pwd666}, User{id = 222	 username = 李四	 password = pwd222}]
數(shù)據(jù)庫中 id = 123 的 user 數(shù)據(jù)已經(jīng)被刪除了
數(shù)據(jù)庫中所有的 user 數(shù)據(jù) :[User{id = 111	 username = 張三	 password = pwd111}, User{id = 222	 username = 李四	 password = pwd222}]

這是結(jié)束標(biāo)志,結(jié)束了 ~文章來源地址http://www.zghlxwxcb.cn/news/detail-579799.html

到了這里,關(guān)于SpringBoot 集成 Mybatis的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • spring-boot集成mybatis真的很簡單嗎?

    spring-boot集成mybatis真的很簡單嗎?

    在日常的后端開發(fā)中,使用mybatis作為DAO層的持久框架已經(jīng)是慣例。但很多時(shí)候都是在別人搭好的框架中進(jìn)行開發(fā),對(duì)怎么搭建環(huán)境是一知半解,今天就來實(shí)踐下。 來看下集成mybatis需要哪些步驟, 1、確定環(huán)境及依賴 2、配置文件; 3、測試 這里, 基于springboot集成mybatis。 先

    2024年02月08日
    瀏覽(84)
  • spring boot集成mybatis-plus——Mybatis Plus 查詢數(shù)據(jù)(圖文講解)

    spring boot集成mybatis-plus——Mybatis Plus 查詢數(shù)據(jù)(圖文講解)

    ?更新時(shí)間 2023-01-03 16:07:12 大家好,我是小哈。 本小節(jié)中,我們將學(xué)習(xí)如何通過 Mybatis Plus 查詢數(shù)據(jù)庫表中的數(shù)據(jù)。 在前面小節(jié)中,我們已經(jīng)定義好了一個(gè)用于測試的用戶表, 執(zhí)行腳本如下: 定義一個(gè)名為? User ?實(shí)體類: 不明白 Mybatis Plus 實(shí)體類注解的小伙伴,可參考前面

    2024年02月02日
    瀏覽(23)
  • 從零開始學(xué)Spring Boot系列-集成MyBatis-Plus

    從零開始學(xué)Spring Boot系列-集成MyBatis-Plus

    在Spring Boot應(yīng)用開發(fā)中,MyBatis-Plus是一個(gè)強(qiáng)大且易于使用的MyBatis增強(qiáng)工具,它提供了很多實(shí)用的功能,如代碼生成器、條件構(gòu)造器、分頁插件等,極大地簡化了MyBatis的使用和配置。本篇文章將指導(dǎo)大家如何在Spring Boot項(xiàng)目中集成MyBatis-Plus。 首先,確保你已經(jīng)安裝了Java開發(fā)環(huán)

    2024年04月08日
    瀏覽(75)
  • spring boot集成mybatis-plus——Mybatis Plus 批量 Insert_新增數(shù)據(jù)(圖文講解)

    spring boot集成mybatis-plus——Mybatis Plus 批量 Insert_新增數(shù)據(jù)(圖文講解)

    ?更新時(shí)間 2023-01-10 16:02:58 大家好,我是小哈。 本小節(jié)中,我們將學(xué)習(xí)如何通過 Mybatis Plus 實(shí)現(xiàn) MySQL 批量插入數(shù)據(jù)。 先拋出一個(gè)問題:假設(shè)老板給你下了個(gè)任務(wù),向數(shù)據(jù)庫中添加 100 萬條數(shù)據(jù),并且不能耗時(shí)太久! 通常來說,我們向 MySQL 中新增一條記錄,SQL 語句類似如下:

    2024年02月04日
    瀏覽(28)
  • Spring Boot集成MyBatis Plus中的QueryWrapper的eq方法詳解及示例代碼

    1. 簡介 MyBatis Plus是一個(gè)強(qiáng)大的MyBatis增強(qiáng)工具包,它為我們?cè)谶M(jìn)行數(shù)據(jù)庫操作時(shí)提供了很多便利的方法。其中,QueryWrapper是MyBatis Plus中的一個(gè)重要類,它可以用于構(gòu)建復(fù)雜的查詢條件。 在QueryWrapper中,eq方法是最常用的一個(gè),它用于構(gòu)建等值條件查詢。在本文中,我們將詳細(xì)

    2024年02月10日
    瀏覽(44)
  • spring boot集成mybatis-plus——Mybatis Plus 新增數(shù)據(jù)并返回主鍵 ID(圖文講解)

    spring boot集成mybatis-plus——Mybatis Plus 新增數(shù)據(jù)并返回主鍵 ID(圖文講解)

    ?更新時(shí)間 2023-01-10 15:37:37 大家好,我是小哈。 本小節(jié)中,我們將學(xué)習(xí)如何通過 Mybatis Plus 框架給數(shù)據(jù)庫表新增數(shù)據(jù),主要內(nèi)容思維導(dǎo)圖如下: Mybatis Plus 新增數(shù)據(jù)思維導(dǎo)圖 為了演示新增數(shù)據(jù),在前面小節(jié)中,我們已經(jīng)定義好了一個(gè)用于測試的用戶表, 執(zhí)行腳本如下: 定義一

    2024年02月02日
    瀏覽(41)
  • spring boot集成mybatis-plus——Mybatis Plus 多表聯(lián)查(包含分頁關(guān)聯(lián)查詢,圖文講解)...

    spring boot集成mybatis-plus——Mybatis Plus 多表聯(lián)查(包含分頁關(guān)聯(lián)查詢,圖文講解)...

    ?更新時(shí)間 2023-01-03 21:41:38 大家好,我是小哈。 本小節(jié)中,我們將學(xué)習(xí)如何通過 Mybatis Plus 實(shí)現(xiàn) 多表關(guān)聯(lián)查詢 ,以及 分頁關(guān)聯(lián)查詢 。 本文以 查詢用戶所下訂單 ,來演示 Mybatis Plus 的關(guān)聯(lián)查詢,數(shù)據(jù)庫表除了前面小節(jié)中已經(jīng)定義好的用戶表外,再額外創(chuàng)建一張訂單表,然后

    2024年02月01日
    瀏覽(25)
  • 【SpringBoot】Spring Boot 項(xiàng)目中整合 MyBatis 和 PageHelper

    目錄 前言? ? ? ?? 步驟 1: 添加依賴 步驟 2: 配置數(shù)據(jù)源和 MyBatis 步驟 3: 配置 PageHelper 步驟 4: 使用 PageHelper 進(jìn)行分頁查詢 IDEA指定端口啟動(dòng) 總結(jié) ????????Spring Boot 與 MyBatis 的整合是 Java 開發(fā)中常見的需求,特別是在使用分頁插件如 PageHelper 時(shí)。PageHelper 是一個(gè)針對(duì) MyBat

    2024年04月25日
    瀏覽(32)
  • spring boot集成Elasticsearch-SpringBoot(25)

    spring boot集成Elasticsearch-SpringBoot(25)

    ??搜索引擎(search engine )通常意義上是指:根據(jù)特定策略,運(yùn)用特定的爬蟲程序從互聯(lián)網(wǎng)上搜集信息,然后對(duì)信息進(jìn)行處理后,為用戶提供檢索服務(wù),將檢索到的相關(guān)信息展示給用戶的系統(tǒng)。 ??而我們講解的是捜索的索引和檢索,不涉及爬蟲程序的內(nèi)容爬取。大部分公司

    2023年04月09日
    瀏覽(24)
  • Spring Boot學(xué)習(xí)隨筆- 集成JSP模板(配置視圖解析器)、整合Mybatis(@MapperScan注解的使用)

    Spring Boot學(xué)習(xí)隨筆- 集成JSP模板(配置視圖解析器)、整合Mybatis(@MapperScan注解的使用)

    學(xué)習(xí)視頻:【編程不良人】2021年SpringBoot最新最全教程 在main創(chuàng)建webapp,然后創(chuàng)建index.jsp進(jìn)行測試,在訪問之前需要進(jìn)行一個(gè)設(shè)置,否則springboot是找不到j(luò)sp頁面的 修改jsp無需重啟應(yīng)用 數(shù)據(jù)庫訪問框架:hibernate、jpa、mybatis【主流】 SpringBoot(微框架) = Spring(工廠) + SpringMV

    2024年02月05日
    瀏覽(58)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包