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

easycode配置成mybatis-plus模板的實現(xiàn)方法

 更新時間:2021年09月05日 10:48:28   作者:饒一一  
本文主要介紹了easycode配置成mybatis-plus模板的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文主要介紹了easycode配置成mybatis-plus模板的實現(xiàn)方法,分享給大家,具體如下:

entity.java

##導入宏定義
$!define
##保存文件(宏定義)
#save("/entity", ".java")
##包路徑(宏定義)
#setPackageSuffix("entity")
##自動導入包(全局變量)
$!autoImport
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;


##表注釋(宏定義)
#tableComment("表實體類")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("$!{tableInfo.comment}")
public class $!{tableInfo.name} implements Serializable {

private static final long serialVersionUID = $!tool.serial();

#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})/**
    * ${column.comment}
    */#end
    #if(${column.comment})@ApiModelProperty(value = "${column.comment}")#end
    #if($column.name.equals('id'))@TableId(type = IdType.AUTO)#end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end
}

dao.java

##導入宏定義
$!define
##設置表后綴(宏定義)
#setTableSuffix("Mapper")
##保存文件(宏定義)
#save("/mapper", "Mapper.java")
##包路徑(宏定義)
#setPackageSuffix("mapper")
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;

##表注釋(宏定義)
#tableComment("表數(shù)據(jù)庫訪問層")
public interface $!{tableName} extends BaseMapper<$!tableInfo.name> {

}

server.java

##導入宏定義
$!define
##設置表后綴(宏定義)
#setTableSuffix("Service")
##保存文件(宏定義)
#save("/service", "Service.java")
##包路徑(宏定義)
#setPackageSuffix("service")
import com.baomidou.mybatisplus.extension.service.IService;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;

##表注釋(宏定義)
#tableComment("表服務接口")
public interface $!{tableName} extends IService<$!tableInfo.name> {

}

serverImpl.java

##導入宏定義
$!define
##設置表后綴(宏定義)
#setTableSuffix("ServiceImpl")
##保存文件(宏定義)
#save("/service/impl", "ServiceImpl.java")
##包路徑(宏定義)
#setPackageSuffix("service.impl")
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

##表注釋(宏定義)
#tableComment("表服務實現(xiàn)類")
@Slf4j
@Service
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {

}

controller.java

##導入宏定義
$!define
##設置表后綴(宏定義)
#setTableSuffix("Controller")
##保存文件(宏定義)
#save("/controller", "Controller.java")
##包路徑(宏定義)
#setPackageSuffix("controller")
##定義服務名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
##定義實體對象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;


import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.api.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

##表注釋(宏定義)
#tableComment("表控制層[不建議修改,如果有新增的方法,寫在子類中]")
@RestController
public class $!{tableName} {
  
    /**
     * 服務對象
     */
    @Autowired
    $!{tableInfo.name}Service $!{serviceName};   
  
   /**
     * 分頁查詢所有數(shù)據(jù)
     *
     * @param page 分頁對象
     * @param $!entityName 查詢實體
     * @return 所有數(shù)據(jù)
     */
    @ApiOperation("分頁查詢所有數(shù)據(jù)")
    @GetMapping
    public R<IPage<$!tableInfo.name>>  selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) {
        return R.ok ($!{serviceName}.page(page, new QueryWrapper<>($!entityName)));
    }

    /**
     * 通過主鍵查詢單條數(shù)據(jù)
     *
     * @param id 主鍵
     * @return 單條數(shù)據(jù)
     */
    @ApiOperation("通過主鍵查詢單條數(shù)據(jù)")
    @GetMapping("{id}")
    public R<$!tableInfo.name> selectOne(@PathVariable Serializable id) {
        return R.ok($!{serviceName}.getById(id));
    }

    /**
     * 新增數(shù)據(jù)
     *
     * @param $!entityName 實體對象
     * @return 新增結果
     */
    @ApiOperation("新增數(shù)據(jù)")
    @PostMapping
    public R<Long> insert(@RequestBody $!tableInfo.name $!entityName) {
        boolean rs = $!{serviceName}.save($!entityName);
        return R.ok(rs?$!{entityName}.getId():0);
    }

    /**
     * 修改數(shù)據(jù)
     *
     * @param $!entityName 實體對象
     * @return 修改結果
     */
    @ApiOperation("修改數(shù)據(jù)")
    @PutMapping
    public R<Boolean>  update(@RequestBody $!tableInfo.name $!entityName) {
        return R.ok($!{serviceName}.updateById($!entityName));
    }

    /**
     * 單條/批量刪除數(shù)據(jù)
     *
     * @param idList 主鍵集合
     * @return 刪除結果
     */
    @ApiOperation("單條/批量刪除數(shù)據(jù)")
    @DeleteMapping
    public R<Boolean> delete(@RequestParam("idList") List<Long> idList) {
        return R.ok($!{serviceName}.removeByIds(idList));
    }
}

mapper.xml

##引入mybatis支持
$!mybatisSupport

##設置保存名稱與保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))

##拿到主鍵
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper">

    <resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}BaseResultMap">
#foreach($column in $tableInfo.fullColumn)
        <result property="$!column.name" column="$!column.obj.name"/>
#end
    </resultMap>
</mapper>

修改簽名

到此這篇關于easycode配置成mybatis-plus模板的實現(xiàn)方法的文章就介紹到這了,更多相關easycode配置成mybatis-plus模板內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關文章

  • spring獲取bean的源碼解析

    spring獲取bean的源碼解析

    這篇文章主要介紹了spring獲取bean的源碼解析,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04
  • Spring HandlerInterceptor實現(xiàn)原理代碼解析

    Spring HandlerInterceptor實現(xiàn)原理代碼解析

    這篇文章主要介紹了Spring HandlerInterceptor實現(xiàn)原理代碼解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-10-10
  • Spring Cloud Hystrix異常處理方法詳解

    Spring Cloud Hystrix異常處理方法詳解

    這篇文章主要介紹了Spring Cloud Hystrix異常處理方法詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-01-01
  • java如何導出insert語句并生成sql腳本

    java如何導出insert語句并生成sql腳本

    這篇文章主要介紹了java導出insert語句并生成sql腳本的實例,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • Java 高并發(fā)三:Java內(nèi)存模型和線程安全詳解

    Java 高并發(fā)三:Java內(nèi)存模型和線程安全詳解

    本文主要介紹Java高并發(fā)內(nèi)存模型和線程安全的資料,這里整理詳細的資料及1.原子性 2.有序性 3.可見性 4.Happen-Before 5.線程安全的概念,有需要的小伙伴可以參考下
    2016-09-09
  • SpringBoot整合定時任務的方法

    SpringBoot整合定時任務的方法

    通過 ThreadPoolExecutor 可以實現(xiàn)各式各樣的自定義線程池,而 ScheduledThreadPoolExecutor 類則在自定義線程池的基礎上增加了周期性執(zhí)行任務的功能,這篇文章主要介紹了SpringBoot整合定時任務,需要的朋友可以參考下
    2024-05-05
  • Spring 使用注解方式進行事務管理配置方式

    Spring 使用注解方式進行事務管理配置方式

    本篇文章主要介紹了Spring 使用注解方式進行事務管理配置方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • Java中Klass模型與類加載的詳細機制

    Java中Klass模型與類加載的詳細機制

    這篇文章主要介紹了Java中Klass模型與類加載的詳細機制,java語言是在jvm中運行而jvm是不認識java代碼的我們使用javac編譯的class文件jvm是不認識的 所以有一個類加載的動作 這個動作就是把class字節(jié)碼拼裝成一個klass類型,需要的朋友可以參考下
    2023-08-08
  • Java 位圖法排序的使用方法

    Java 位圖法排序的使用方法

    本篇文章,小編將為大家介紹關于Java 位圖法排序的使用方法,有需要的朋友可以參考一下
    2013-04-04
  • Java實現(xiàn)的爬蟲抓取圖片并保存操作示例

    Java實現(xiàn)的爬蟲抓取圖片并保存操作示例

    這篇文章主要介紹了Java實現(xiàn)的爬蟲抓取圖片并保存操作,涉及Java針對頁面URL訪問、獲取、字符串匹配、文件下載等相關操作技巧,需要的朋友可以參考下
    2018-08-08

最新評論