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

@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(),"品牌名称重复!");
        }
原文地址:https://www.cnblogs.com/Kohinur/p/11799295.html