78 lines
3.2 KiB
Plaintext
78 lines
3.2 KiB
Plaintext
package ${entity.controllerPackage};
|
|
|
|
import cn.lili.common.utils.PageUtil;
|
|
import cn.lili.common.enums.ResultUtil;
|
|
import cn.lili.common.vo.PageVO;
|
|
import cn.lili.common.vo.SearchVO;
|
|
import cn.lili.common.vo.ResultMessage;
|
|
import ${entity.entityPackage}.${entity.className};
|
|
import ${entity.servicePackage}.${entity.className}Service;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import lombok.RequiredArgsConstructor;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
* @author ${entity.author}
|
|
*/
|
|
@RestController
|
|
@Api(tags = "${entity.description}接口")
|
|
@RequestMapping("/lili/${entity.classNameLowerCase}")
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public class ${entity.className}Controller {
|
|
|
|
private final ${entity.className}Service ${entity.classNameLowerCase}Service;
|
|
|
|
@GetMapping(value = "/{id}")
|
|
@ApiOperation(value = "查看${entity.description}详情")
|
|
public ResultMessage<${entity.className}> get(@PathVariable ${entity.primaryKeyType} id){
|
|
|
|
${entity.className} ${entity.classNameLowerCase} = ${entity.classNameLowerCase}Service.getById(id);
|
|
return new ResultUtil<${entity.className}>().setData(${entity.classNameLowerCase});
|
|
}
|
|
|
|
@GetMapping
|
|
@ApiOperation(value = "分页获取${entity.description}")
|
|
public ResultMessage<IPage<${entity.className}>> getByPage(${entity.className} entity,
|
|
SearchVO searchVo,
|
|
PageVO page){
|
|
IPage<${entity.className}> data = ${entity.classNameLowerCase}Service.page(PageUtil.initPage(page),PageUtil.initWrapper(entity, searchVo));
|
|
return new ResultUtil<IPage<${entity.className}>>().setData(data);
|
|
}
|
|
|
|
@PostMapping
|
|
@ApiOperation(value = "新增${entity.description}")
|
|
public ResultMessage<${entity.className}> save(${entity.className} ${entity.classNameLowerCase}){
|
|
|
|
if(${entity.classNameLowerCase}Service.save(${entity.classNameLowerCase})){
|
|
return new ResultUtil<${entity.className}>().setData(${entity.classNameLowerCase});
|
|
}
|
|
return new ResultUtil<${entity.className}>().setErrorMsg("未知异常,请稍后重试");
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
@ApiOperation(value = "更新${entity.description}")
|
|
public ResultMessage<${entity.className}> update(@PathVariable String id, ${entity.className} ${entity.classNameLowerCase}){
|
|
if(${entity.classNameLowerCase}Service.updateById(${entity.classNameLowerCase})){
|
|
return new ResultUtil<${entity.className}>().setData(${entity.classNameLowerCase});
|
|
}
|
|
return new ResultUtil<${entity.className}>().setErrorMsg("未知异常,请稍后重试");
|
|
}
|
|
|
|
@DeleteMapping(value = "/{ids}")
|
|
@ApiOperation(value = "删除${entity.description}")
|
|
public ResultMessage<Object> delAllByIds(@PathVariable List ids){
|
|
|
|
${entity.classNameLowerCase}Service.removeByIds(ids);
|
|
return ResultUtil.success("成功删除");
|
|
}
|
|
}
|