iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >easycode配置成mybatis-plus模板的实现方法
  • 276
分享到

easycode配置成mybatis-plus模板的实现方法

2024-04-02 19:04:59 276人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

本文主要介绍了easycode配置成mybatis-plus模板的实现方法,分享给大家,具体如下: entity.java ##导入宏定义 $!define ##保存文件(宏定义

本文主要介绍了easycode配置成mybatis-plus模板的实现方法,分享给大家,具体如下:

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})#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("表数据库访问层")
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("表服务实现类")
@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};   
  
   
    @ApiOperation("分页查询所有数据")
    @GetMapping
    public R<IPage<$!tableInfo.name>>  selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) {
        return R.ok ($!{serviceName}.page(page, new QueryWrapper<>($!entityName)));
    }

    
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("{id}")
    public R<$!tableInfo.name> selectOne(@PathVariable Serializable id) {
        return R.ok($!{serviceName}.getById(id));
    }

    
    @ApiOperation("新增数据")
    @PostMapping
    public R<Long> insert(@RequestBody $!tableInfo.name $!entityName) {
        boolean rs = $!{serviceName}.save($!entityName);
        return R.ok(rs?$!{entityName}.getId():0);
    }

    
    @ApiOperation("修改数据")
    @PutMapping
    public R<Boolean>  update(@RequestBody $!tableInfo.name $!entityName) {
        return R.ok($!{serviceName}.updateById($!entityName));
    }

    
    @ApiOperation("单条/批量删除数据")
    @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模板的实现方法的文章就介绍到这了,更多相关easycode配置成mybatis-plus模板内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: easycode配置成mybatis-plus模板的实现方法

本文链接: https://www.lsjlt.com/news/134668.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作