velocity.ueboot.Controller.vm Maven / Gradle / Ivy
/*
* Copyright (c) ${YEAR}
* All rights reserved.
* ${DATE}
*/
package ${controllerPackageName};
import com.ueboot.core.http.response.Response;
import ${controllerPackageName}.vo.*;
import ${entityPackageName}.${entityFullName};
import ${servicePackageName}.${entityName}Service;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* Created on ${DATE}
* @author ${USER}
* @since 3.0.0 by ueboot-generator
*/
@Slf4j
@RestController
@RequestMapping(value = "$requestPath${lowEntityName}")
public class ${entityName}Controller {
@Resource
private ${entityName}Service ${lowEntityName}Service;
@RequiresPermissions("${lowEntityName}:read")
@PostMapping(value = "/page")
public Response> page(@PageableDefault(value = 15, sort = { "id" }, direction = Sort.Direction.ASC)
Pageable pageable, @RequestBody(required = false) ${entityName}FindReq req){
Page<${entityFullName}> entities = ${lowEntityName}Service.findBy(pageable);
Page<${entityName}Resp> body = entities.map(entity -> {
${entityName}Resp resp = new ${entityName}Resp();
BeanUtils.copyProperties(entity, resp);
return resp;
});
return new Response<>(body);
}
@RequiresPermissions("${lowEntityName}:save")
@PostMapping(value = "/save")
public Response save(@RequestBody ${entityName}Req req) {
${entityFullName} entity = null;
if (req.getId() == null) {
entity = new ${entityFullName}();
} else {
entity = ${lowEntityName}Service.get(req.getId());
}
BeanUtils.copyProperties(req, entity);
${lowEntityName}Service.save(entity);
return new Response<>();
}
@RequiresPermissions("${lowEntityName}:delete")
@PostMapping(value = "/delete")
public Response delete(Long[] id) {
${lowEntityName}Service.delete(id);
return new Response<>();
}
@RequiresPermissions("${lowEntityName}:read")
@GetMapping(value = "/{id}")
public Response<${entityName}Resp> get(@PathVariable Long id) {
${entityFullName} entity = ${lowEntityName}Service.get(id);
${entityName}Resp resp = new ${entityName}Resp();
BeanUtils.copyProperties(entity, resp);
return new Response<>(resp);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy