2 muzhao321 muzhao321 于 2017.08.29 17:10 提问

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

@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个回答

fk002008
fk002008   2017.08.29 17:17

selectById 路径没有 /开始

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

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

Sanjay_yww
Sanjay_yww 现在的@RequestMapping就相当于@Controller+@ResponseBody
3 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片