dao层:
KakaInfoEntity selectById(String idd);
Service层:
public List<KakaInfoEntity> selectById(String [] idd){
List<KakaInfoEntity> kakaInfoEntities=new ArrayList<>();
for(int i=0;i<idd.length;i++){
KakaInfoEntity entity= kakaInfoEntityMapper.selectById(idd[i]);
kakaInfoEntities.add(entity);
}
return kakaInfoEntities;
}
如果
List<KakaInfoEntity> 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"]