十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
本篇內(nèi)容主要講解“SpringBoot整合Mybatis-Plus代碼生成器實例”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“SpringBoot整合Mybatis-Plus代碼生成器實例”吧!
創(chuàng)新互聯(lián)公司主營京口網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,APP應(yīng)用開發(fā),京口h5微信小程序搭建,京口網(wǎng)站營銷推廣歡迎京口等地區(qū)企業(yè)咨詢
總體步驟 1.springboot搭建(thymeleaf,springmvc,MySQL驅(qū)動)。 2.整合mybatisplus相關(guān)的1個依賴核心包;然后mybatis相關(guān)配置。 3.集成代碼生成器。需要代碼生成器的核心包和代碼生成器要用的模板引擎包。使用官方網(wǎng)站提供的主類(配置數(shù)據(jù)源,配置生成策略)。 4.啟動類上面需要加入@MapperScan,進行mybatis代理接口和mapper/**/*Mapper.xml代理關(guān)系的綁定。 5.啟動測試。 |
pom.xml
4.0.0 org.springframework.boot spring-boot-starter-parent 2.4.5 com.example springboot_jxc_0507 0.0.1-SNAPSHOT springboot_jxc_0507 Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web mysql mysql-connector-java runtime org.projectlombok lombok true com.baomidou mybatis-plus-boot-starter 3.4.2 com.baomidou mybatis-plus-generator 3.4.1 org.apache.velocity velocity-engine-core 2.3 org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok
# thymeleafspring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.check-template-location=truespring.thymeleaf.suffix=.htmlspring.thymeleaf.encoding=utf-8spring.thymeleaf.content-type=text/htmlspring.thymeleaf.mode=HTML5spring.thymeleaf.cache=false |
application.yml
spring: datasource:driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/mybatisplus0507?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=trueusername: rootpassword: rootmybatis-plus: configuration:map-underscore-to-camel-case: true auto-mapping-behavior: full log-impl: org.apache.ibatis.logging.stdout.StdOutImpl mapper-locations: classpath*:mapper/**/*Mapper.xmllogging: level:root: info com.example.springboot_jxc_0507: info
package com.example.mybatisplus_doc_0508.conf;import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;import com.baomidou.mybatisplus.core.toolkit.StringPool;import com.baomidou.mybatisplus.core.toolkit.StringUtils;import com.baomidou.mybatisplus.generator.AutoGenerator;import com.baomidou.mybatisplus.generator.InjectionConfig;import com.baomidou.mybatisplus.generator.config.*;import com.baomidou.mybatisplus.generator.config.po.TableInfo;import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;import java.util.ArrayList;import java.util.List;import java.util.Scanner;/** * @Auther: GongXl * @Date: 2021/5/8 10:04 * @Description: */public class CodeGenerator {/** * |
package com.example.springboot_jxc_0507;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication@MapperScan("com.example.springboot_jxc_0507.jxc.mapper")public class SpringbootJxc0507Application {public static void main(String[] args) {SpringApplication.run(SpringbootJxc0507Application.class, args); } } |
到此,相信大家對“SpringBoot整合Mybatis-Plus代碼生成器實例”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!