controller service dao 代码idea模板File Template

本文介绍了基于SpringBoot和MybatisPlus的Web开发中,IDEA的Controller、Service、DAO和Entity等文件模板的使用,详细列举了各个部分的内容,包括分页请求参数。作者欢迎对代码规范有经验的读者提供反馈。
摘要由CSDN通过智能技术生成

1 背景

基于springboot,mybatisplus 的web开发的idea文件模板,包括controller,service,dao,entity等。包含了基本的增删改查操作。

2 Controller

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")

/**
  *@Description      
  *@auther          ${USER}
  *@create          ${YEAR}-${MONTH}-${DAY} ${TIME}
  */ 
@Slf4j
@RequestMapping("/${smallName}")
@RestController
public class ${ClassName}Controller {
    @Resource
    ${ClassName}Service ${smallName}Service;
    @CrossOrigin
    @RequestMapping(value="/list", method = RequestMethod.POST)
    public Object getList(@RequestBody ${ClassName}PageReq ${smallName}PageReq) throws Exception{
        if(${smallName}PageReq.getCurrentPage()!=null&&${smallName}PageReq.getPageSize()!=null) {
            IPage<${ClassName}VO> ${smallName}VOIPage = ${smallName}Service.select${ClassName}Page(${smallName}PageReq);
            return Response.getSuccessResult(${smallName}VOIPage);
        }
        else{
            List<${ClassName}VO> ${smallName}VOList = ${smallName}Service.select${ClassName}List(${smallName}PageReq);
            return Response.getSuccessResult(${smallName}VOList);
        }
    }
    @CrossOrigin
    @RequestMapping(value="/update", method = RequestMethod.PUT)
    public Response<String> update(@RequestBody ${ClassName}VO ${smallName}VO, HttpServletRequest request){

        ${smallName}VO.setOperator(CommonUtils.getCurrentUserName(request));
        boolean result = ${smallName}Service.update(${smallName}VO);
        if(result) {
            log.info("update ${smallName} successful,${smallName}Id:{}  change to {}",${smallName}VO.getId(),${smallName}VO);
            return Response.getSuccessResult("update ${smallName} successful");
        }
        else {
            log.warn("update ${smallName} failed,${smallName}Id:{}",${smallName}VO.getId());
            return Response.getFailResult(CodeEnum.ERR_SYSTEM, "update ${smallName} failed ");
        }
    }
    @CrossOrigin
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    public Response<String> deleteByid(@PathVariable long id, HttpServletRequest request){
        if(id<=0){
            return Response.getFailResult(CodeEnum.ERR_CLIENT,"参数id异常");
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值