SpringBoot中前台传一个数组 查询多条 后台如何遍历?

dao层:

KakaInfoEntity selectById(String idd);

Service层:

public  List selectById(String [] idd){
       List kakaInfoEntities=new ArrayList<>();
       for(int i=0;i

如果

List kakaInfoEntities=null;

就会抛出空指针异常;

controller:

    @RequestMapping(value = "/selectById", method = RequestMethod.POST, headers = "Accept=application/json")
    public HttpResponseEntity selectById(@RequestBody String[] ids) {

        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        try {
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(kakaService.selectById(ids));
            httpResponseEntity.setMessage("查询成功");
        } catch (Exception e) {
            httpResponseEntity.setCode(Constans.RIGISTER_ERROR_CODE);
            httpResponseEntity.setMessage("查询失败");
        }
        return httpResponseEntity;
    }

前台传入数据类型:

["id","id"]

你可能感兴趣的:(SpringBoot中前台传一个数组 查询多条 后台如何遍历?)