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

MybatisPlus 自定義.vm模板的生成

 更新時(shí)間:2024年03月18日 14:54:25   作者:王卷卷.  
為更加快捷方便的開發(fā)代碼,使用MybatisPlus的代碼自動(dòng)生成功能,將一些繁瑣的操作自動(dòng)生成,本文主要介紹了MybatisPlus 自定義.vm模板的生成,感興趣的可以了解一下

官方手冊(cè)

Mybatis-Plus:

代碼生成器(新) | MyBatis-Plus

代碼生成器配置新 | MyBatis-Plus

依賴

<!--引入MybatisPlus-->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.3.1</version>
</dependency>
<!--代碼生成器-->
<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>mybatis-plus-generator</artifactId>
  <version>3.5.3.1</version>
</dependency>
<!--代碼生成器:模板引擎依賴 Velocity-->
<dependency>
  <groupId>org.apache.velocity</groupId>
  <artifactId>velocity</artifactId>
  <version>1.7</version>
</dependency>

代碼生成器配置

package com.xin.sbvms.utils;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;

import java.sql.Types;
import java.util.Collections;

/**
 * @author WangXin
 * @description MyBatis-Plus代碼生成器
 * @date 2024/03/17 22:02
 **/
public class CodeGenerator {
    public static void main(String[] args) {
        mpGenerator();
    }

    private static void mpGenerator() {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/sbvms?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai", "root", "123456")
                .globalConfig(builder -> {
                    builder.author("WangXin") // 設(shè)置作者
                            // .enableSwagger() // 開啟 swagger 模式
                            .outputDir("D:\\Code\\Java\\SBV-MS\\src\\main\\java\\"); // 指定輸出目錄
                })
                .dataSourceConfig(builder -> builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
                    int typeCode = metaInfo.getJdbcType().TYPE_CODE;
                    if (typeCode == Types.SMALLINT) {
                        // 自定義類型轉(zhuǎn)換
                        return DbColumnType.INTEGER;
                    }
                    return typeRegistry.getColumnType(metaInfo);

                }))
                .packageConfig(builder -> {
                    builder.parent("com.xin.sbvms") // 設(shè)置父包名
                            .moduleName(null) // 設(shè)置父包模塊名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D:\\Code\\Java\\SBV-MS\\src\\main\\resources\\mapper\\")); // 設(shè)置mapperXml生成路徑
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder().enableLombok(); // 開啟lombok功能
                    builder.entityBuilder().enableFileOverride(); // 覆蓋已生成文件
                    builder.controllerBuilder().enableFileOverride().
                            enableRestStyle(); // 開啟Rest風(fēng)格
                    builder.serviceBuilder().enableFileOverride();
                    builder.mapperBuilder().enableFileOverride();
                    builder.addInclude("sys_user") // 設(shè)置需要生成的表名
                            .addTablePrefix("t_", "sys_"); // 設(shè)置過濾表前綴
                })
                .templateConfig(builder -> {
                    builder.controller("/templates/myController.java") // 指定自定義模板路徑,注意不要帶上.ftl/.vm, 會(huì)根據(jù)使用的模板引擎自動(dòng)識(shí)別
                            .build(); // 指定模板
                })
                // .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默認(rèn)的是Velocity引擎模板
                .execute();
    }
}

controller模板

  • 模板存放路徑:resources/templates/myController.java.vm
  • 包名:${package.Entity}
  • 類名:${entity} 如 User
  • 表面:${table.entityPath} 如 user
package ${package.Controller};


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};

#if(${restControllerStyle})
import org.springframework.web.bind.annotation.RestController;
#else
import org.springframework.stereotype.Controller;
#end
#if(${superControllerClassPackage})
import ${superControllerClassPackage};
#end

/**
 * $!{table.comment} 前端控制器
 *
 * @author ${author}
 * @since ${date}
 */
#if(${restControllerStyle})
@RestController
#else
@Controller
#end
@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
#if(${kotlin})
class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end

#else
    #if(${superControllerClass})
    public class ${table.controllerName} extends ${superControllerClass} {
    #else
    public class ${table.controllerName} {
    #end

@Resource
private ${table.serviceName} ${table.entityPath}Service;

// 新增或者更新
@PostMapping("/add")
public boolean save(@RequestBody ${entity} ${table.entityPath}){
        return ${table.entityPath}Service.saveOrUpdate(${table.entityPath});
        }

@DeleteMapping("/{id}")
public Boolean delete(@PathVariable Integer id){
        return ${table.entityPath}Service.removeById(id);
        }

@PostMapping("/del/batch")
public boolean deleteBatch(@RequestBody List<Integer> ids){
        return ${table.entityPath}Service.removeByIds(ids);
        }

@GetMapping
public List<${entity}> findAll(){
        return ${table.entityPath}Service.list();
        }

@GetMapping("/{id}")
public ${entity} findOne(@PathVariable Integer id){
        return ${table.entityPath}Service.getById(id);
        }

@GetMapping("/page")
public Page<${entity}> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return ${table.entityPath}Service.page(new Page<>(pageNum,pageSize),queryWrapper);
        }

        }

#end

Bug

自定義controller.java.vm 不生效

在生成器代碼【CodeGenerator】中添加下面代碼,引入自定義模板【myController.java.vm】

.templateConfig(builder -> {
                    builder.controller("/templates/myController.java") // 指定自定義模板路徑,注意不要帶上.ftl/.vm, 會(huì)根據(jù)使用的模板引擎自動(dòng)識(shí)別
                            .build(); // 指定模板
                })

到此這篇關(guān)于MybatisPlus 自定義.vm模板的生成的文章就介紹到這了,更多相關(guān)MybatisPlus 自定義.vm模板內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java實(shí)現(xiàn)攝像頭截圖功能

    java實(shí)現(xiàn)攝像頭截圖功能

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)攝像頭截圖功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • 四步輕松搞定java web每天定時(shí)執(zhí)行任務(wù)

    四步輕松搞定java web每天定時(shí)執(zhí)行任務(wù)

    本篇文章主要介紹了四步輕松搞定java web每天定時(shí)執(zhí)行任務(wù),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • java&javascript自定義加密數(shù)據(jù)傳輸代碼示例

    java&javascript自定義加密數(shù)據(jù)傳輸代碼示例

    這篇文章主要介紹了java&javascript自定義加密數(shù)據(jù)傳輸代碼示例,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-11-11
  • spring注解@Service注解的使用解析

    spring注解@Service注解的使用解析

    這篇文章主要介紹了spring注解@Service注解的使用解析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • 關(guān)于SpringBoot接收json格式的Demo案例

    關(guān)于SpringBoot接收json格式的Demo案例

    這篇文章主要介紹了關(guān)于SpringBoot接收json格式的Demo案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • Java進(jìn)階之FileUpload完成上傳的實(shí)例

    Java進(jìn)階之FileUpload完成上傳的實(shí)例

    這篇文章主要介紹了 Java進(jìn)階之FileUpload完成上傳的實(shí)例的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • javacv視頻抽幀的實(shí)現(xiàn)過程詳解(附代碼)

    javacv視頻抽幀的實(shí)現(xiàn)過程詳解(附代碼)

    這篇文章主要介紹了javacv視頻抽幀的實(shí)現(xiàn)過程詳解(附代碼),視頻抽幀可以做一些處理,比如水印,去水印等操作,然后再合成視頻,需要的朋友可以參考下
    2019-07-07
  • Scala遞歸函數(shù)調(diào)用自身

    Scala遞歸函數(shù)調(diào)用自身

    這篇文章主要介紹了Scala遞歸函數(shù),Scala遞歸函數(shù)是一種函數(shù)可以調(diào)用自身的函數(shù),直到滿足某個(gè)特定的條件為止。在函數(shù)式編程的語言中,遞歸函數(shù)起著重要的作用,因?yàn)樗梢杂脕肀硎狙h(huán)或迭代的邏輯
    2023-04-04
  • Spring Cloud 系列之負(fù)載均衡 Ribbon的示例代碼

    Spring Cloud 系列之負(fù)載均衡 Ribbon的示例代碼

    Ribbon 是 Netflix 發(fā)布的負(fù)載均衡器,它有助于控制 HTTP 和 TCP 客戶端的行為。這篇文章主要介紹了Spring Cloud 系列之負(fù)載均衡 Ribbon的示例代碼,需要的朋友可以參考下
    2020-11-11
  • 查看SpringBoot和JDK版本對(duì)應(yīng)關(guān)系的方法

    查看SpringBoot和JDK版本對(duì)應(yīng)關(guān)系的方法

    在進(jìn)行一些自主學(xué)習(xí)的時(shí)候,發(fā)現(xiàn)使用maven方式創(chuàng)建的SpringBoot項(xiàng)目啟動(dòng)失敗,最終發(fā)現(xiàn)是SpringBoot版本和JDK版本不對(duì)應(yīng)導(dǎo)致的,所以本文就給大家介紹了如何查看SpringBoot和JDK版本的對(duì)應(yīng)關(guān)系,需要的朋友可以參考下
    2024-03-03

最新評(píng)論

黎川县| 嵊州市| 和政县| 房产| 辽宁省| 武夷山市| 孝感市| 新安县| 龙陵县| 桃园县| 株洲市| 湘西| 长乐市| 南雄市| 夏邑县| 玉门市| 临夏县| 汉阴县| 弥勒县| 宁乡县| 南陵县| 建水县| 海宁市| 蓝山县| 通城县| 栖霞市| 佛坪县| 株洲县| 苏尼特右旗| 临桂县| 如皋市| 聂拉木县| 鱼台县| 邢台市| 金沙县| 三门县| 郑州市| 东港市| 封开县| 富民县| 山西省|