最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

前言

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

話不多說 直接開始

官方文檔

配置實(shí)體類(和自己數(shù)據(jù)庫表對應(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í)測試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 綁定你這個數(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簡化插件-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
<!--        test測試-->
        <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é)

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

相關(guān)文章

  • java獲取ip地址與網(wǎng)絡(luò)接口的方法示例

    java獲取ip地址與網(wǎng)絡(luò)接口的方法示例

    這篇文章主要給大家介紹了關(guān)于利用java如何獲取ip地址與網(wǎng)絡(luò)接口的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01
  • JavaSE-面向?qū)ο?方法重寫)

    JavaSE-面向?qū)ο?方法重寫)

    子類在調(diào)用父類的私有方法中不能直接調(diào)用,但是可以通過get方法進(jìn)行調(diào)用,修改屬性的值可以通過set方法進(jìn)行修改。而子類想要修改父類中的方法可以使用方法重寫進(jìn)行操作。
    2021-08-08
  • java-synchronized 嵌套使用代碼詳解

    java-synchronized 嵌套使用代碼詳解

    本文以synchronized 的同步造成了死鎖為例,介紹了java-synchronized 嵌套使用代碼詳解,同時對鎖和死鎖的概念進(jìn)行了說明,需要的朋友可以了解下。
    2017-09-09
  • Java IO 之文件讀寫簡單實(shí)例

    Java IO 之文件讀寫簡單實(shí)例

    這篇文章主要介紹了Java IO 之文件讀寫簡單實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • 基于Feign使用okhttp的填坑之旅

    基于Feign使用okhttp的填坑之旅

    這篇文章主要介紹了基于Feign使用okhttp的填坑之旅,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-02-02
  • Java常用數(shù)字工具類 大數(shù)乘法、加法、減法運(yùn)算(2)

    Java常用數(shù)字工具類 大數(shù)乘法、加法、減法運(yùn)算(2)

    這篇文章主要為大家詳細(xì)介紹了Java常用數(shù)字工具類,大數(shù)乘法、加法、減法運(yùn)算,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Java 壓縮包解壓實(shí)現(xiàn)代碼

    Java 壓縮包解壓實(shí)現(xiàn)代碼

    Java標(biāo)準(zhǔn)庫(Java SE)提供了對ZIP格式的原生支持,通過java.util.zip包中的類來實(shí)現(xiàn)壓縮和解壓功能,本文將重點(diǎn)介紹如何使用Java來解壓ZIP或RAR壓縮包,感興趣的朋友一起看看吧
    2025-05-05
  • Java線程創(chuàng)建的5種寫法詳解

    Java線程創(chuàng)建的5種寫法詳解

    這段文章詳細(xì)解釋了線程與進(jìn)程的關(guān)系、線程狀態(tài)、線線程創(chuàng)建的幾種寫法、常見面試題以及高耦合與低耦合的概念,通過這些內(nèi)容,讀者可以全面了解線程的基礎(chǔ)知識及其在編程中的應(yīng)用,需要的朋友可以參考下
    2026-05-05
  • 使用SpringBoot+AOP實(shí)現(xiàn)可插拔式日志的示例代碼

    使用SpringBoot+AOP實(shí)現(xiàn)可插拔式日志的示例代碼

    這篇文章主要介紹了使用SpringBoot+AOP實(shí)現(xiàn)可插拔式日志的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • java判斷ip是否為指定網(wǎng)段示例

    java判斷ip是否為指定網(wǎng)段示例

    這篇文章主要介紹了java判斷ip是否為指定網(wǎng)段示例方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-10-10

最新評論

镇沅| 玛纳斯县| 宜兰县| 左权县| 宝鸡市| 桃园市| 贵德县| 双鸭山市| 曲靖市| 昌吉市| 通州市| 綦江县| 清河县| 郎溪县| 大安市| 石景山区| 乌审旗| 兴海县| 安徽省| 随州市| 东兰县| 韶山市| 雷州市| 舞阳县| 奉化市| 荥经县| 富川| 洛宁县| 龙井市| 沿河| 濮阳市| 公主岭市| 普格县| 华亭县| 阳山县| 偃师市| 博罗县| 孟村| 丹棱县| 珲春市| 乌兰察布市|