【EasyCode代码生成模板】

po.java.vm

##导入宏定义
$!{define.vm}

##保存文件(宏定义)
#save("/future-dao/src/main/java/com/platform/future/dao/po/$!tool.firstLowerCase($tableInfo.name)", ".java")

##包路径
package com.platform.future.dao.po.$!tool.firstLowerCase($tableInfo.name);

##自动导入包(全局变量)

import com.platform.common.mybatis.entity.DataEntity;
import lombok.Data;

##表注释(宏定义)
#tableComment("表实体类")

@Data
public class $!{tableInfo.name} extends DataEntity<$!{tableInfo.name}> {
    #set($excludeFields = ["id", "createUser", "createTime", "updateUser", "updateTime"])
    #foreach($column in $tableInfo.fullColumn)
        #if(!$excludeFields.contains($column.name))
            private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
        #end
    #end
}    

dto.java.vm

##导入宏定义
$!{define.vm}

##保存文件(宏定义)
#save("/future-admin-api/src/main/java/com/platform/future/admin/api/dto/$!tool.firstLowerCase($tableInfo.name)", "DTO.java")

##包路径
package com.platform.future.admin.api.dto.$!tool.firstLowerCase($tableInfo.name);

##自动导入包(全局变量)

import com.platform.future.dao.po.demo.$!{tableInfo.name};
import lombok.Data;

##表注释(宏定义)
#tableComment("接受参数实体类")

@Data
public class $!{tableInfo.name}DTO extends $!{tableInfo.name} {
  
}    

mapper.java.vm

##导入宏定义
$!{define.vm}

##保存文件(宏定义)
#save("/future-dao/src/main/java/com/platform/future/dao/mapper/$!tool.firstLowerCase($tableInfo.name)", "Mapper.java")

##包路径
package com.platform.future.dao.mapper.$!tool.firstLowerCase($tableInfo.name);

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.platform.future.dao.po.$!tool.firstLowerCase($tableInfo.name).${tableInfo.name};
import org.apache.ibatis.annotations.Mapper;

##表注释(宏定义)
#tableComment("数据访问")
@Mapper
public interface ${tableInfo.name}Mapper extends BaseMapper<${tableInfo.name}> {
}    

mapper.xml.vm

##引入mybatis支持
$!{mybatisSupport.vm}

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/future-dao/src/main/java/com/platform/future/dao/mapper/xml/$!{tableInfo.name}"))

##拿到主键
#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="com.platform.future.dao.mapper.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name}Mapper">

    <resultMap type="com.platform.future.dao.po.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name}" id="$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)
        <result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
        insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($foreach.hasNext), #end#end)
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
        insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($foreach.hasNext), #end#end)
        </foreach>
        on duplicate key update
         #foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($foreach.hasNext), #end#end
    </insert>

</mapper>


service.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("Service")

##保存文件(宏定义)
#save("/future-api/src/main/java/com/platform/future/api/service/$!tool.firstLowerCase($tableInfo.name)", "Service.java")

##包路径(宏定义)
#setPackageSuffix("com.platform.future.api.service.$!tool.firstLowerCase($tableInfo.name)")

import com.baomidou.mybatisplus.extension.service.IService;
import com.platform.future.dao.po.$!tool.firstLowerCase($tableInfo.name).$!tableInfo.name;

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

}

serviceImpl.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl")

##保存文件(宏定义)
#save("/future-api/src/main/java/com/platform/future/api/service/impl/$!tool.firstLowerCase($tableInfo.name)", "ServiceImpl.java")

##包路径(宏定义)
#setPackageSuffix("com.platform.future.api.service.impl.$!tool.firstLowerCase($tableInfo.name)")

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.future.api.service.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name}Service;
import com.platform.future.dao.mapper.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name}Mapper;
import com.platform.future.dao.po.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name};
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

##表注释(宏定义)
#tableComment("表服务实现类")
@AllArgsConstructor
@Service("$!tool.firstLowerCase($tableInfo.name)Service")
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {

}

controller.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("Controller")

##保存文件(宏定义)
#save("/future-api/src/main/java/com/platform/future/api/controller/$!tool.firstLowerCase($tableInfo.name)", "Controller.java")

##包路径(宏定义)
#setPackageSuffix("com.platform.future.api.controller.$!tool.firstLowerCase($tableInfo.name)")

##定义服务名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))

##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))

// import com.platform.common.security.annotation.AuthIgnore;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.common.core.util.R;
import com.platform.future.dao.po.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name};
import com.platform.future.api.service.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable;
import java.util.List;

##表注释(宏定义)
#tableComment("表控制层")
@AllArgsConstructor
@RestController
@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)")
public class $!{tableName}{
    /**
     * 服务对象
     */
    private final $!{tableInfo.name}Service $!{serviceName};

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param $!entityName 查询实体
     * @return 所有数据
     */
    @GetMapping
    public R selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) {
        return R.ok(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName)));
    }
    
    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    // @AuthIgnore
    @GetMapping("list")
    public R list() {
        return R.ok(this.$!{serviceName}.list());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.$!{serviceName}.getById(id));
    }

    /**
     * 新增数据
     *
     * @param $!entityName 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R insert(@RequestBody $!tableInfo.name $!entityName) {
        return R.ok(this.$!{serviceName}.save($!entityName));
    }

    /**
     * 修改数据
     *
     * @param $!entityName 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody $!tableInfo.name $!entityName) {
        return R.ok(this.$!{serviceName}.updateById($!entityName));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(this.$!{serviceName}.removeByIds(idList));
    }
}



adminservice.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("Service")

##保存文件(宏定义)
#save("/future-admin-api/src/main/java/com/platform/future/admin/api/service/$!tool.firstLowerCase($tableInfo.name)", "Service.java")

##包路径(宏定义)
#setPackageSuffix("com.platform.future.admin.api.service.$!tool.firstLowerCase($tableInfo.name)")

import com.baomidou.mybatisplus.extension.service.IService;
import com.platform.future.dao.po.$!tool.firstLowerCase($tableInfo.name).$!tableInfo.name;

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

}

adminserviceImpl.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl")

##保存文件(宏定义)
#save("/future-admin-api/src/main/java/com/platform/future/admin/api/service/impl/$!tool.firstLowerCase($tableInfo.name)", "ServiceImpl.java")

##包路径(宏定义)
#setPackageSuffix("com.platform.future.admin.api.service.impl.$!tool.firstLowerCase($tableInfo.name)")

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.future.admin.api.service.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name}Service;
import com.platform.future.dao.mapper.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name}Mapper;
import com.platform.future.dao.po.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name};
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

##表注释(宏定义)
#tableComment("表服务实现类")
@RequiredArgsConstructor
@Service("$!tool.firstLowerCase($tableInfo.name)AdminService")
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {

}


admincontroller.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("Controller")

##保存文件(宏定义)
#save("/future-admin-api/src/main/java/com/platform/future/admin/api/controller/$!tool.firstLowerCase($tableInfo.name)", "Controller.java")

##包路径(宏定义)
#setPackageSuffix("com.platform.future.admin.api.controller.$!tool.firstLowerCase($tableInfo.name)")

##定义服务名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))

##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))

// import com.platform.common.security.annotation.AuthIgnore;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.common.core.util.R;
import com.platform.future.dao.po.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name};
import com.platform.future.admin.api.service.$!tool.firstLowerCase($tableInfo.name).$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;

##表注释(宏定义)
#tableComment("表控制层")
@AllArgsConstructor
@RestController
@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)")
public class $!{tableName}{
    /**
     * 服务对象
     */
    private final $!{tableInfo.name}Service $!{serviceName};

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param $!entityName 查询实体
     * @return 所有数据
     */
    @GetMapping
    public R selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) {
        return R.ok(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName)));
    }
    
    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    // @AuthIgnore
    @GetMapping("list")
    public R list() {
        return R.ok(this.$!{serviceName}.list());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.$!{serviceName}.getById(id));
    }

    /**
     * 新增数据
     *
     * @param $!entityName 实体对象
     * @return 新增结果
     */
    @PostMapping
    @PreAuthorize("@pms.hasPermission('$!{tableInfo.name.toUpperCase()}_ADD', '$!{tableInfo.name.toUpperCase()}_EDIT')")
    public R insert(@RequestBody $!tableInfo.name $!entityName) {
        return R.ok(this.$!{serviceName}.save($!entityName));
    }

    /**
     * 修改数据
     *
     * @param $!entityName 实体对象
     * @return 修改结果
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('$!{tableInfo.name.toUpperCase()}_EDIT')")
    public R update(@RequestBody $!tableInfo.name $!entityName) {
        return R.ok(this.$!{serviceName}.updateById($!entityName));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('$!{tableInfo.name.toUpperCase()}_DELETE')")
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(this.$!{serviceName}.removeByIds(idList));
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值