JPA使用update自定义语句更新多条字段,数据库数据出错

之前使用更新字段,然后插入到数据库的数值一直跟我的输入没有关系,之后发现是自定义的更新语句出错了。

错误代码:

@Transactional
    @Modifying(clearAutomatically = true) //更新快一点的
    @Query(value = "update products set product_num=?1 and sell_num=?2 where product_id=?3", nativeQuery = true)
    public void updateProductInfo(int productnum,int sellnum,int productid);

正确代码:

@Transactional
    @Modifying(clearAutomatically = true) //更新快一点的
    @Query(value = "update products set product_num=?1,sell_num=?2 where product_id=?3", nativeQuery = true)
    public void updateProductInfo(int productnum,int sellnum,int productid);

你可能感兴趣的:(JPA使用update自定义语句更新多条字段,数据库数据出错)