muzhao321 2017-08-29 09:10 采纳率: 0%
浏览 783

大神帮看一下这段代码有什么问题 表达什么意思

@Slf4j
@RestController
@RequestMapping("/api/admin/business")
public class AdminBussinesses {
private final BusinessReadService businessReadService;
private final BusinessWriteService businessWriteService;

@Autowired
public AdminBussinesses(BusinessReadService businessReadService, BusinessWriteService businessWriteService){
    this.businessReadService = businessReadService;
    this.businessWriteService = businessWriteService;
}


@RequestMapping("selectById")
public Object selectById(@RequestParam("id")Long id){
    Business business = new Business();
    business.setId(id);
    Response<Paging<Business>> resp = businessReadService.select(business,0,1);
    if (!resp.isSuccess()){
        throw new JsonResponseException(resp.getError());
    }
    return resp.getResult();
}

@RequestMapping("/selectByBusinessNameAndType")
public Paging<Business> select(@RequestParam(value = "pageNo", required = false) Integer pageNo,
                     @RequestParam(value = "size", required = false) Integer size,
                     @RequestParam(value = "businessName", required = false)String businessName,
                     @RequestParam(value = "type", required = false)Integer type){
    if(pageNo == null){
        pageNo = 0;
    }
    if(size == null){
        size = 20;
    }
    if(businessName.equals("")){
        businessName = null;
    }
    Business business = new Business();
    business.setBusinessName(businessName);
    business.setType(type);
    Response<Paging<Business>> resp = businessReadService.select(business, pageNo, size);
    if (!resp.isSuccess()){
        throw new JsonResponseException(500, resp.getError());
    }
    return resp.getResult();
}

@RequestMapping("/insert")
public Boolean insert(@RequestBody Business business){
    Business exit = new Business();
    exit.setType(business.getType());
    exit.setBusinessName(business.getBusinessName());
    Response<Paging<Business>> exitResp = businessReadService.select(exit, 0, 1);
    List<Business> list = exitResp.getResult().getData();
    if (!(list == null || list.size() <= 0)){
        throw new JsonResponseException(500, "同类型不可同名");
    }
    Response<Boolean> resp = businessWriteService.insert(business);
    if (!resp.isSuccess()){
        log.error("failed to insert article by business = {}, cause : ", business, resp.getError());
        throw new JsonResponseException(500, resp.getError());
    }
    return resp.getResult();
}

@RequestMapping("/delete")
public Boolean delete(@RequestParam Business business){
    Response<Boolean> resp = businessWriteService.delete(business);
    if (!resp.isSuccess()){
        log.error("failed to delete article by business = {}, cause : ", business, resp.getError());
        throw new JsonResponseException(500, resp.getError());
    }
    return resp.getResult();
}

@RequestMapping("/deleteById")
public Boolean deleteById(@RequestParam Long id){
    Business business = new Business();
    business.setId(id);
    Response<Boolean> resp = businessWriteService.delete(business);
    if (!resp.isSuccess()){
        log.error("faild to delete article by id = {}, cause : ", business.getId(),resp.getError());
        throw new JsonResponseException(500, resp.getError());
    }
    return resp.getResult();
}


@RequestMapping("/updateById")
public Boolean updateById(@RequestBody Business business){
    Map<String, Object> map = new HashedMap();
    Business change = business;
    business = new Business();
    business.setId(change.getId());
    change.setId(null);
    map.put("business", business);
    map.put("change", change);
    Response<Boolean> resp = businessWriteService.update(map);
    if (!resp.isSuccess()) {
        log.error("failed to update article by business = {}, cause : ", business, resp.getError());
        throw new JsonResponseException(500, resp.getError());
    }
    return resp.getResult();
}

@RequestMapping("/user")
public Object user(){
    User user = UserUtil.getCurrentUser();
    return user;
}

}

  • 写回答

1条回答

  • lambda-fk 2017-08-29 09:17
    关注

    selectById 路径没有 /开始

    @RequestParam Business business 去掉@RequestParam 或者改为 @RequestBody

    每个方法是不是 ajax ,如果是 方法上加 @ResponseBody

    评论

报告相同问题?

悬赏问题

  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?