All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.Controller.ftl Maven / Gradle / Ivy

The newest version!
package ${basePackage}.${moduleName}.controller;

import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
<#if hasProvideServer=true>
import ${basePackage}.api.api.${moduleName}.${apiName}Api;
import ${basePackage}.api.dto.${moduleName}.${dtoName}DTO;
import ${basePackage}.api.vo.${moduleName}.${voName}VO;
<#else>
import ${basePackage}.common.dto.${moduleName}.${dtoName}DTO;
import ${basePackage}.common.vo.${moduleName}.${voName}VO;

<#if hasOrm=true>
import ${basePackage}.common.model.${moduleName}.${poName};

import ${basePackage}.${moduleName}.service.${serviceName}Service;
import import top.zenyoung.boot.controller.BaseController;
import top.zenyoung.common.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ${controllerName}Controller
 *
 * @author generator
 * date ${date?string("yyyy-MM-dd")}
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/${sourceName}s")
<#if hasProvideServer=true>
public class ${controllerName}Controller extends BaseController implements ${apiName}Api {
<#else>
public class ${controllerName}Controller extends BaseController {

    private final ${serviceName}Service service;

    <#if hasProvideServer=true && hasBaseApi=true>
    @Override
    
    public ResultVO<${voName}VO> add(final ${dtoName}DTO dto){
        <#if hasOrm=true>
        ${poName} po = service.mapping(dto, ${poName}.class);
        po = service.add(po);
        return success(service.mapping(po, ${voName}VO.class));
        <#else>
        ///TODO:
        return success();
        
    }

    <#if hasProvideServer=true && hasBaseApi=true>
    @Override
    
    public ResultVO<${voName}VO> get(final ${idType} id){
        if(Objects.isNull(id)){
           return failed();
        }
        <#if hasOrm=true>
        final ${poName} po = service.getById(id);
        return success(service.mapping(po, ${voName}VO.class));
        <#else>
        ///TODO:
        return success();
        
    }

    <#if hasProvideServer=true && hasBaseApi=true>
    @Override
    
    public ResultVO update(final ${idType} id, final ${dtoName}DTO dto){
        <#if hasOrm=true>
        final ${poName} po = service.mapping(dto, ${poName}.class);
        service.modify(id, po);
        return success();
        <#else>
        ///TODO:
        return success();
        
    }

    <#if hasProvideServer=true && hasBaseApi=true>
    @Override
    
    public ResultVO delete(final ${idType}[] ids){
        if(Objects.isNull(ids)){
           return failed();
        }
        <#if hasOrm=true>
        service.delete(Lists.newArrayList(ids));
        <#else>
        ///TODO:
        
        return success();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy