乐优商城项目总结day(8)
@PostMapping
public ResponseEntity<Void> saveBrand(Brand brand, @RequestParam(value = "cids") List<Long> cids) {
brandService.saveBrand(brand, cids);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
SpringMvc能够自动将字符串"id1,id2,id3,..."
自动转化成List<T>
public void saveBrand(Brand brand, List<Long> cids) {
brand.setId(null);
int count = brandDao.insert(brand);
if(count != 1) {
throw new LyException(ExceptionEnum.BRAND_SAVE_ERROR);
}
cids.stream().forEach(cid -> {
int ct = brandDao.insertCategoryBrand(cid, brand.getId());
if(ct != 1) {
throw new LyException(ExceptionEnum.BRAND_SAVE_ERROR);
}
});
}
通用mapper进行insert添加实体类后,如果实体类的主键带有自增策略ÿ