freemaker模板


controller生成模板 

package ${package.Controller};

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import tech.niua.core.annotation.ApiVersion;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import tech.niua.core.enums.BusinessType;
import tech.niua.common.model.ResultCode;
import tech.niua.common.model.ResultJson;
import java.util.Arrays;
import tech.niua.common.utils.poi.ExcelUtil;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import tech.niua.core.annotation.NoRepeatSubmit;
import tech.niua.core.annotation.Log;



/**
 * <p>
 *  ${table.comment} 控制类
 * </p>
 *
 * @author niua
 * @since ${.now?string("yyyy-MM-dd HH:mm:ss")}
 */
@RestController
@ApiVersion(1)
@RequestMapping("{version}/${entity ?uncap_first}")
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${entity?uncap_first}Service;

    /**
    * 查询列表
    *
    * @param currentPage
    * @param pageSize
    * @param ${entity?uncap_first}
    * @return
    */
    @Log(value = "查询列表", businessType = BusinessType.LIST)
    @PreAuthorize("hasAuthority('/${entity?uncap_first}')")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header")})
    @PostMapping("/list/{currentPage}/{pageSize}")
    public ResultJson index(@PathVariable Integer currentPage, @PathVariable Integer pageSize,@RequestBody  ${entity} ${entity?uncap_first}) {
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
<#list table.fields as field >
<#if (field.propertyName != "id" && field.propertyName != "createTime" && field.propertyName != "updateTime") >
     <#if field.propertyType == "String">
         if(StringUtils.isNotBlank(${entity?uncap_first}.get${field.propertyName?cap_first}())) {
             queryWrapper.like("${field.name}", ${entity?uncap_first}.get${field.propertyName?cap_first}());
         }
     </#if>
    <#if field.propertyName == "deleteFlag">
        queryWrapper.eq("${field.name}", 0);
    </#if>
</#if>
    <#if field.propertyName == "createTime">
        if(${entity?uncap_first}.get${field.propertyName?cap_first}Begin() != null && ${entity?uncap_first}.get${field.propertyName?cap_first}End()  != null ){
            queryWrapper.between("${field.name}", ${entity?uncap_first}.get${field.propertyName?cap_first}Begin(), ${entity?uncap_first}.get${field.propertyName?cap_first}End());
        }
        queryWrapper.orderByDesc("create_time");
    </#if>
</#list>
        IPage<${entity}> pageList = ${entity?uncap_first}Service.page(new Page<>(currentPage, pageSize), queryWrapper);
        return ResultJson.ok(pageList);
    }

    /**
    *根据id查找
    * @param: id
    * @return
    */
    @PreAuthorize("hasAuthority('/${entity?uncap_first}')")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header")})
    @GetMapping("/findById/{id}")
    public ResultJson find${entity}ById(@PathVariable Long id) {
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        <#list table.fields as field >
        <#if field.propertyName == "deleteFlag">
            queryWrapper.eq("${field.name}", 0);
        </#if>
        </#list>
        ${entity} ${entity ?uncap_first} = ${entity ?uncap_first}Service.getOne(queryWrapper);
        if(${entity ?uncap_first} != null){
            return ResultJson.ok(${entity ?uncap_first});
        }
        return ResultJson.failure(ResultCode.BAD_REQUEST);
    }

    /**
    * 添加修改
    * @param ${entity?uncap_first}
    * @return
    */
    @Log(value = "添加修改", businessType = BusinessType.INSERTORUPDATE)
    @PreAuthorize("hasAuthority('/${entity?uncap_first}/saveOrUpdate')")
    @NoRepeatSubmit
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header")})
    @PostMapping("/saveOrUpdate")
    public ResultJson saveOrUpdate(@RequestBody ${entity} ${entity?uncap_first}){
        boolean flag = ${entity?uncap_first}Service.saveOrUpdate(${entity?uncap_first});
        if(flag){
            return ResultJson.ok();
        }
        return ResultJson.failure(ResultCode.NOT_UPDATE);
    }

    /**
    * 删除
    * @param ids
    * @return
    */
    @Log(value = "删除", businessType = BusinessType.DELETE)
    @PreAuthorize("hasAuthority('/${entity?uncap_first}/delete')")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header")})
    @GetMapping("/delete")
    public ResultJson delete(@RequestParam("ids") Long[] ids){
<#assign dt=0>
<#list table.fields as field>
    <#if field.propertyName == "deleteFlag">
        <#assign dt=1>
    </#if>
</#list>
    <#if dt==1>
        UpdateWrapper<${entity}> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id",ids).set("delete_flag",1);
        boolean updateFlag = ${entity?uncap_first}Service.update(null,updateWrapper);
        if(updateFlag){
        return ResultJson.ok(updateFlag);
        }
        return ResultJson.failure(ResultCode.SERVER_ERROR);
    <#else>
        boolean updateFlag = ${entity?uncap_first}Service.removeByIds(Arrays.asList(ids));
        if(updateFlag){
            return Re
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值