欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

快速上手Mybatis-plus結(jié)構(gòu)構(gòu)建過程

 更新時(shí)間:2024年07月17日 11:26:48   作者:qwecxzz  
這篇文章主要介紹了快速上手Mybatis-plus結(jié)構(gòu)構(gòu)建過程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

前言

如何快速上手使用一次Mybatis-plus?

話不多說 直接開始

官方文檔

配置實(shí)體類(和自己數(shù)據(jù)庫表對(duì)應(yīng))

package com.example.jsr303.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;

/**
 * 學(xué)習(xí)測(cè)試JSR303
 */

@Data
@TableName("test")
public class TestEntity implements Serializable {

    //忽略掉 設(shè)置序列化和反序列化的serialVersionUID
    //想了解一下可以去這篇博客 https://blog.csdn.net/qq_45503106/article/details/107950914
    private static final long serialVersionUID = 1L;

    /**
     * test表主鍵ID
     */
    @TableId
    private Integer id;
    /**
     *  姓名
     */
    private String name;

    /**
     * 郵箱
     */
    private String email;

}

一定記得使用@TableName 綁定你這個(gè)數(shù)據(jù)庫的表

否則按照 數(shù)據(jù)庫名+實(shí)體類 名去找你的表

一般都找不到

一、導(dǎo)入依賴

<dependencies>
<!--        web mvc-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--        mysql鏈接-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
<!--        lombok簡(jiǎn)化插件-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
<!--        test測(cè)試-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--        myabtis-plus依賴-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>
    </dependencies>

二、配置配置文件yml

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/jsr303?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8
server:
  port: 8082
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

三 配置Mapper Service Controller三層架構(gòu)

Mapper層

package com.example.jsr303.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.jsr303.entity.TestEntity;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface TestDao extends BaseMapper<TestEntity> {
}

Service層

package com.example.jsr303.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.jsr303.entity.TestEntity;
import org.springframework.stereotype.Service;


public interface TestService extends IService<TestEntity> {
}

ServiceImpl層

package com.example.jsr303.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.jsr303.dao.TestDao;
import com.example.jsr303.entity.TestEntity;
import com.example.jsr303.service.TestService;
import org.springframework.stereotype.Service;

@Service
public class TestServiceImpl extends ServiceImpl<TestDao, TestEntity> implements TestService {
}

Controller層

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    TestService testService;

    @RequestMapping("/list")
    public List<TestEntity> selectAll(){
     return testService.list();
    }
}

常用的Service接口官方文檔

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot中啟動(dòng)時(shí)如何忽略某項(xiàng)檢測(cè)

    SpringBoot中啟動(dòng)時(shí)如何忽略某項(xiàng)檢測(cè)

    這篇文章主要介紹了SpringBoot中啟動(dòng)時(shí)如何忽略某項(xiàng)檢測(cè),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • 解決RestTemplate 請(qǐng)求url中包含百分號(hào) 會(huì)被轉(zhuǎn)義成25的問題

    解決RestTemplate 請(qǐng)求url中包含百分號(hào) 會(huì)被轉(zhuǎn)義成25的問題

    這篇文章主要介紹了解決RestTemplate 請(qǐng)求url中包含百分號(hào) 會(huì)被轉(zhuǎn)義成25的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。
    2021-10-10
  • 讓IntelliJ IDEA支持.vue文件的方法

    讓IntelliJ IDEA支持.vue文件的方法

    這篇文章主要介紹了讓IntelliJ IDEA支持.vue文件的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-05-05
  • JavaWeb之Servlet注冊(cè)頁面的實(shí)現(xiàn)示例

    JavaWeb之Servlet注冊(cè)頁面的實(shí)現(xiàn)示例

    注冊(cè)頁面是很多網(wǎng)站都會(huì)是使用的到,本文主要介紹了JavaWeb之Servlet注冊(cè)頁面的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • 詳解MybatisPlus3.4版本之后分頁插件的使用

    詳解MybatisPlus3.4版本之后分頁插件的使用

    從Mybatis Plus 3.4.0版本開始,不再使用舊版本的PaginationInterceptor ,而是使用MybatisPlusInterceptor。本文就詳細(xì)的介紹一下兩者的區(qū)別,感興趣的可以了解一下
    2021-11-11
  • Spring Boot中快速操作Mongodb數(shù)據(jù)庫指南

    Spring Boot中快速操作Mongodb數(shù)據(jù)庫指南

    這篇文章主要給大家介紹了關(guān)于Spring Boot中如何快速操作Mongodb的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • Java中將異步調(diào)用轉(zhuǎn)為同步的五種實(shí)現(xiàn)方法

    Java中將異步調(diào)用轉(zhuǎn)為同步的五種實(shí)現(xiàn)方法

    本文介紹了將異步調(diào)用轉(zhuǎn)為同步阻塞模式的五種方法:wait/notify、ReentrantLock+Condition、Future、CountDownLatch和CyclicBarrier,每種方法都有其適用場(chǎng)景和核心機(jī)制,可以根據(jù)具體需求選擇合適的方法,需要的朋友可以參考下
    2025-02-02
  • SpringBoot如何配置文件properties和yml

    SpringBoot如何配置文件properties和yml

    這篇文章主要介紹了SpringBoot如何配置文件properties和yml問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • IntelliJ?IDEA?2022.2.3最新激活圖文教程(親測(cè)有用永久激活)

    IntelliJ?IDEA?2022.2.3最新激活圖文教程(親測(cè)有用永久激活)

    今天給大家分享一個(gè)?IDEA?2022.2.3?的激活破解教程,全文通過文字+圖片的方式講解,手把手教你如何激活破解?IDEA,?只需要幾分鐘即可搞定,對(duì)idea2022.2.3激活碼感興趣的朋友跟隨小編一起看看吧
    2022-11-11
  • Netty分布式NioSocketChannel注冊(cè)到selector方法解析

    Netty分布式NioSocketChannel注冊(cè)到selector方法解析

    這篇文章主要為大家介紹了Netty分布式源碼分析NioSocketChannel注冊(cè)到selector方法的解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-03-03

最新評(píng)論