@PathVariable使用

public interface ProductInfoRepository extends JpaRepository<ProductInfo, String>{
    List<ProductInfo> findByProductId(String productId);
}

ProductInfoControllermysql

@Autowired 
private ProductInfoRepository productInfoRepository;

@GetMapping("/ProductId/{id}")
public List<ProductInfo> findByProductId(@PathVariable("id")String productId){
    List<ProductInfo> productInfoList = productInfoRepository.findByProductId(productId);
    return productInfoList;
}

application.ymlspring

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: xzh456
    url: jdbc:mysql://localhost:3306/springcloud_sell?characterEncoding=utf-8&useSSL=false
  jpa:
    show-sql: true
相關文章
相關標籤/搜索