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

idea使用Mybatis逆向工程插件詳情

 更新時(shí)間:2022年01月25日 15:48:08   作者:游王子  
這篇文章主要介紹了idea使用Mybatis逆向工程插件詳情,首先使用mybatis連接數(shù)據(jù)庫(kù)接著添加連接的mysql的信息,測(cè)試鏈接等過(guò)程,更多過(guò)程了解請(qǐng)參考下面文章的詳細(xì)內(nèi)容

一、使用mybatis連接數(shù)據(jù)庫(kù)

添加連接的mysql的信息,測(cè)試鏈接成功即可。

二、安裝Better-Mybatis-Generator插件

安裝成功后,在需要生成的表上右鍵選擇mybatis-generator。

添加要生成的一些配置。

點(diǎn)擊OK,第一次生成會(huì)彈出窗口,需要輸入數(shù)據(jù)庫(kù)的帳號(hào)密碼??梢钥吹缴稍摫韺?duì)應(yīng)的mapper接口、實(shí)體類(lèi)和sql

三、關(guān)于example類(lèi)詳解

1、example成員變量

mybatis-generator會(huì)為每個(gè)字段產(chǎn)生Criterion,為底層的mapper.xml創(chuàng)建動(dòng)態(tài)sql。如果表的字段比較多,產(chǎn)生的example類(lèi)會(huì)十分龐大。理論上通過(guò)example類(lèi)可以構(gòu)造你想到的任何篩選條件。

?//作用:升序還是降序
?//參數(shù)格式:字段+空格+asc(desc)
?protected String orderByClause; ?
?//作用:去除重復(fù)
?//true是選擇不重復(fù)記錄,false,反之
?protected boolean distinct;
?//自定義查詢(xún)條件
?//Criteria的集合,集合中對(duì)象是由or連接
?protected List<Criteria> oredCriteria;
?// 分頁(yè)的顯示條數(shù)
?private Integer limit;
?// 分頁(yè)的起始下標(biāo) ??
?private Long offset;
?//內(nèi)部類(lèi)Criteria包含一個(gè)Cretiron的集合,
?//每一個(gè)Criteria對(duì)象內(nèi)包含的Cretiron之間是由 ?AND連接的
?public static class Criteria extends GeneratedCriteria {
? protected Criteria() {super();}
?}
?//是mybatis中逆向工程中的代碼模型
?protected abstract static class GeneratedCriteria {......}
?//是最基本,最底層的Where條件,用于字段級(jí)的篩選
?public static class Criterion {......}

2、example使用

在MybatisDemoApplicationTests類(lèi)中進(jìn)行測(cè)試:

package org.ywz.test;
?
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.ywz.dao.StudentDao;
import org.ywz.pojo.Student;
import org.ywz.pojo.StudentExample;
?
import java.util.List;
?
/**
?* Example類(lèi)使用說(shuō)明
?*/
@SpringBootTest
class MybatisDemoApplicationTests {
? ? @Autowired
? ? private StudentDao studentDao;
?
? ? @Test
? ? void contextLoads() {
? ? ? ? StudentExample studentExample = new StudentExample();
?
? ? ? ? // 查詢(xún)數(shù)據(jù)的總條數(shù) 類(lèi)似于:select count(*) from student
? ? ? ? long l = studentDao.countByExample(studentExample);
? ? ? ? System.out.println("---------------總條數(shù)----------------");
? ? ? ? System.out.println("數(shù)據(jù)庫(kù)的總條數(shù):" + l);
? ? ? ? System.out.println("----------------and條件---------------");
? ? ? ? // where條件查詢(xún)或多條件查詢(xún)
? ? ? ? Student student = new Student();
? ? ? ? student.setName("王五");
? ? ? ? student.setSex("男");
? ? ? ? selectAndCondition(student);
? ? ? ? System.out.println("---------------or條件----------------");
? ? ? ? selectOrCondition(student);
? ? ? ? System.out.println("-----------------模糊查詢(xún)--------------");
? ? ? ? student.setName("王");
? ? ? ? selectLikeCondition(student);
? ? ? ? System.out.println("-----------------分頁(yè)查詢(xún)--------------");
? ? ? ? selectLimit();
? ? }
?
? ? /**
? ? ?* where條件查詢(xún)或多條件查詢(xún)
? ? ?* 類(lèi)似于:select * from student where name={#student.name} and sex={#student.sex} order by score asc;
? ? ?*
? ? ?* @param student
? ? ?*/
? ? private void selectAndCondition(Student student) {
? ? ? ? StudentExample studentExample = new StudentExample();
? ? ? ? StudentExample.Criteria criteria = studentExample.createCriteria();
? ? ? ? studentExample.setOrderByClause("score asc"); //升序
? ? ? ? studentExample.setDistinct(false); //不去重
? ? ? ? if (StringUtils.isNotBlank(student.getName())) {
? ? ? ? ? ? criteria.andNameEqualTo(student.getName());
? ? ? ? }
? ? ? ? if (StringUtils.isNotBlank(student.getSex())) {
? ? ? ? ? ? criteria.andSexEqualTo(student.getSex());
? ? ? ? }
? ? ? ? List<Student> students = studentDao.selectByExample(studentExample);
? ? ? ? students.forEach(System.out::println);
? ? }
?
? ? /**
? ? ?* 類(lèi)似于:select * from student where name={#student.name} or sex={#student.sex} ;
? ? ?*
? ? ?* @param student
? ? ?*/
? ? private void selectOrCondition(Student student) {
? ? ? ? StudentExample studentExample = new StudentExample();
? ? ? ? StudentExample.Criteria criteria1 = studentExample.createCriteria();
? ? ? ? StudentExample.Criteria criteria2 = studentExample.createCriteria();
? ? ? ? if (StringUtils.isNotBlank(student.getName())) {
? ? ? ? ? ? criteria1.andNameEqualTo(student.getName());
? ? ? ? }
? ? ? ? if (StringUtils.isNotBlank(student.getSex())) {
? ? ? ? ? ? criteria2.andSexEqualTo(student.getSex());
? ? ? ? }
? ? ? ? studentExample.or(criteria2);
? ? ? ? List<Student> students = studentDao.selectByExample(studentExample);
? ? ? ? students.forEach(System.out::println);
? ? }
?
? ? /**
? ? ?* 類(lèi)似于:select * from student where name like %{#student.name}%
? ? ?*
? ? ?* @param student
? ? ?*/
? ? private void selectLikeCondition(Student student) {
? ? ? ? StudentExample studentExample = new StudentExample();
? ? ? ? StudentExample.Criteria criteria = studentExample.createCriteria();
? ? ? ? if (StringUtils.isNotBlank(student.getName())) {
? ? ? ? ? ? criteria.andNameLike("%" + student.getName() + "%");
? ? ? ? }
? ? ? ? List<Student> students = studentDao.selectByExample(studentExample);
? ? ? ? students.forEach(System.out::println);
? ? }
?
? ? /**
? ? ?* 類(lèi)似于:select * from student limit offset,limit
? ? ?*/
? ? public void selectLimit() {
? ? ? ? StudentExample studentExample = new StudentExample();
? ? ? ? studentExample.setOffset(2l);
? ? ? ? studentExample.setLimit(5);
? ? ? ? List<Student> students = studentDao.selectByExample(studentExample);
? ? ? ? students.forEach(System.out::println);
? ? }
}

運(yùn)行結(jié)果:

 官方文檔:MyBatis Generator Core – Example Class Usage Notes 

到此這篇關(guān)于idea使用Mybatis逆向工程插件詳情的文章就介紹到這了,更多相關(guān)idea使用Mybatis逆向工程插件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java中內(nèi)存溢出和內(nèi)存泄漏如何解決

    Java中內(nèi)存溢出和內(nèi)存泄漏如何解決

    ?內(nèi)存溢出?和?內(nèi)存泄漏?是兩種常見(jiàn)的內(nèi)存管理問(wèn)題,它們都會(huì)對(duì)程序的性能產(chǎn)生負(fù)面影響,本文主要介紹了Java中的內(nèi)存溢出和內(nèi)存泄漏問(wèn)題解決,感興趣的可以了解一下
    2024-12-12
  • Java讀取數(shù)據(jù)庫(kù)表的示例代碼

    Java讀取數(shù)據(jù)庫(kù)表的示例代碼

    這篇文章主要介紹了Java讀取數(shù)據(jù)庫(kù)表,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-05-05
  • Java環(huán)境中MyBatis與Spring或Spring MVC框架的集成方法

    Java環(huán)境中MyBatis與Spring或Spring MVC框架的集成方法

    和MyBatis類(lèi)似,Spring或者Spring MVC框架在Web應(yīng)用程序的運(yùn)作中同樣主要負(fù)責(zé)處理數(shù)據(jù)庫(kù)事務(wù),這里我們就來(lái)看一下Java環(huán)境中MyBatis與Spring或Spring MVC框架的集成方法
    2016-06-06
  • JAVA基礎(chǔ)--如何通過(guò)異常處理錯(cuò)誤

    JAVA基礎(chǔ)--如何通過(guò)異常處理錯(cuò)誤

    這篇文章主要介紹了JAVA中如何通過(guò)異常處理錯(cuò)誤,文中講解非常細(xì)致,代碼幫助大家更好的理解,感興趣的朋友可以了解下
    2020-06-06
  • 一個(gè)簡(jiǎn)單JDK版動(dòng)態(tài)代理

    一個(gè)簡(jiǎn)單JDK版動(dòng)態(tài)代理

    這篇文章主要為大家詳細(xì)介紹了一個(gè)簡(jiǎn)單JDK版動(dòng)態(tài)代理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • 詳解Spring注解 @Configuration

    詳解Spring注解 @Configuration

    @Configuration 是 Spring 中的一個(gè)注解,它用于標(biāo)記一個(gè)類(lèi)為配置類(lèi),通過(guò)配置類(lèi)可以定義和組裝 Spring Bean,并且支持高度靈活的配置方式。本問(wèn)詳細(xì)介紹了Spring注解 @Configuration,感興趣的小伙伴可以參考一下
    2023-04-04
  • Mybatis模糊查詢(xún)和動(dòng)態(tài)sql語(yǔ)句的用法

    Mybatis模糊查詢(xún)和動(dòng)態(tài)sql語(yǔ)句的用法

    今天小編就為大家分享一篇關(guān)于Mybatis模糊查詢(xún)和動(dòng)態(tài)sql語(yǔ)句的用法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-03-03
  • Java協(xié)程編程之Loom

    Java協(xié)程編程之Loom

    這篇文章主要介紹了Java協(xié)程編程Loom的方法,需要的朋友請(qǐng)看下文
    2021-08-08
  • Spring事務(wù)管理零基礎(chǔ)入門(mén)

    Spring事務(wù)管理零基礎(chǔ)入門(mén)

    事務(wù)的作用就是為了保證用戶(hù)的每一個(gè)操作都是可靠的,事務(wù)中的每一步操作都必須成功執(zhí)行,只要有發(fā)生異常就?回退到事務(wù)開(kāi)始未進(jìn)行操作的狀態(tài)。事務(wù)管理是Spring框架中最為常用的功能之一,我們?cè)谑褂肧pring?Boot開(kāi)發(fā)應(yīng)用時(shí),大部分情況下也都需要使用事務(wù)
    2022-10-10
  • SpringBoot整合RestTemplate用法的實(shí)現(xiàn)

    SpringBoot整合RestTemplate用法的實(shí)現(xiàn)

    本篇主要介紹了RestTemplate中的GET,POST,PUT,DELETE、文件上傳和文件下載6大常用的功能,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-08-08

最新評(píng)論