JAVA WEB基础-判断数据库是否有该数据

Posted on 2019-11-05 16:24  som_nico  阅读(632)  评论(0编辑  收藏  举报
@Query(value = "select * from brand where brand_name = :#{#brand.brandName} and id <> :#{#brand.id}",nativeQuery = true)
    List<Brand> findAllByBrandNameNotId(@Param("brand") Brand brand);
List<Brand> list = brandRepository.findAllByBrandNameNotId(brand);
        if (list.size()>0) {
            throw new StatusCodeException(StatusCode.FAILED.getCode(),"品牌名称重复!");
        }