MybatisPuls-VM模板

package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;
    #if(${restControllerStyle})
    import org.springframework.web.bind.annotation.RestController;
    #else
    import org.springframework.stereotype.Controller;
    #end
    #if(${superControllerClassPackage})
    import ${superControllerClassPackage};
    #end
import org.springframework.web.bind.annotation.*;
import com.kairuidata.thework.model.ResponseMessage;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kairuidata.thework.utils.JwtTokenUtils;


import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
 * <p>
 * $!{table.comment} 前端控制器
 * </p>
 *
 * @author Lin
 * @since ${date}
 */
@Api(tags = "${table.comment}接口")
    #if(${restControllerStyle})
    @RestController
    #else
    @Controller
    #end
@RequestMapping("/api/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
#if(${kotlin})
class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end

#else
    #if(${superControllerClass})
    public class ${table.controllerName} extends ${superControllerClass} {
    #else
    public class ${table.controllerName} {
    #end

    @Autowired
    private ${table.serviceName} ${table.entityPath}Service;
    @Autowired
    private HttpServletRequest request;

    @ApiOperation("添加")
    @PostMapping("/add${entity}")
    public ResponseMessage<${entity}> add${entity}(@RequestBody ${entity} ${table.entityPath}){

            ${table.entityPath}.setUserId(JwtTokenUtils.getUserId(request));
            if(${table.entityPath}Service.save(${table.entityPath})){
            return ResponseMessage.success("添加成功");
            }
            return ResponseMessage.success("添加失败");
            }



    @ApiOperation("根据id删除")
    @PostMapping("/deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "${table.entityPath}Id", value = "id", dataTypeClass = Integer.class,required = true)
    })
    public ResponseMessage<${entity}> deleteById(@RequestBody JSONObject jsonParam){

            Integer ${table.entityPath}Id = jsonParam.getInt("${table.entityPath}Id");

            if(${table.entityPath}Service.removeById(${table.entityPath}Id)){
            return ResponseMessage.success("删除成功");
            }
            return ResponseMessage.success("删除失败");
            }

    @ApiOperation("根据id查询")
    @PostMapping("/selectById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "${table.entityPath}Id", value = "id", dataTypeClass = Integer.class,required = true)
    })
    public ResponseMessage<${entity}> selectById(@RequestBody JSONObject jsonParam){

        Integer ${table.entityPath}Id = jsonParam.getInt("${table.entityPath}Id");
        
        ${entity} ${table.entityPath}=${table.entityPath}Service.getById(${table.entityPath}Id);

            return ResponseMessage.success(${table.entityPath});
        }

    @ApiOperation("根据id更新")
    @PostMapping("/updateById")
    @ApiImplicitParams({
             @ApiImplicitParam(name = "${table.entityPath}Id", value = "id", dataTypeClass = Integer.class,required = true)
    })
    public ResponseMessage<${entity}> updateById(@RequestBody ${entity} ${table.entityPath}){

            if(${table.entityPath}Service.updateById(${table.entityPath})){
            return ResponseMessage.success("修改成功");
            }
            return ResponseMessage.success("修改失败");
            }
            
    @ApiOperation("查询集合")
    @PostMapping("/selectList")
    public ResponseMessage<List<${entity}>> selectList() {

              List<${entity}> ${table.entityPath} = ${table.entityPath}Service.list(new QueryWrapper<${entity}>()
               .lambda()
               .eq(${entity}::, )
               .orderByDesc(${entity}::getCreateDate));

        return ResponseMessage.success(${table.entityPath});
    }
            
            
        @ApiOperation("分页查询")
        @PostMapping("/selectPage")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "current", value = "当前页", dataTypeClass = Integer.class, required = true)
        })
        public ResponseMessage<PageEntity> selectMyTicket(@RequestBody JSONObject jsonParam) {
    
            Integer current = jsonParam.getInt("current", 1);
    
            int userId = JwtTokenUtils.getUserId(request);
    
            Page<${entity}> ${table.entityPath}Page = new Page<>(current, 15);
            Page<${entity}> type2 = ${table.entityPath}Service.page(${table.entityPath}Page, new QueryWrapper<${entity}>()
                    .lambda()
                    .eq(${entity}::getUserId, userId)
                    .orderByDesc(${entity}::getCreateDate));
            List<${entity}> records = type2.getRecords();
    
            PageEntity pageEntity = new PageEntity(type2.getCurrent(), type2.getSize(), type2.getTotal(), records);
    
            return ResponseMessage.success(pageEntity);
        }

                       }
#end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值