亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我怎樣才能修改mysql更新方法?

我怎樣才能修改mysql更新方法?

富國滬深 2023-09-27 10:39:36
我想從 dto 列表更新 mysql 表,但有一些例外,比如語法問題,這是我的代碼:@Override  @Transactional  public void updateCustomCategory(List<ItemDto> itemDtoList) {    if (CollectionUtils.isNotEmpty(itemDtoList)) {      for (ItemDto itemDto : itemDtoList) {        Long l1CustomCategoryId = itemDto.getL1CustomCatId();        Long l2CustomCategoyId = itemDto.getL2CustomCatId();        StringBuilder query =                new StringBuilder(                        "update ItemDto item set item.l1CustomCategoryId = :l1CustomCategoryId and item.l2CustomCategoryId = :l2CustomCategoyId where itemId = :itemId");        Query q = this.em.createQuery(query.toString());        q.setParameter("l1CustomCategoryId", l1CustomCategoryId);        q.setParameter("l2CustomCategoyId", l2CustomCategoyId);        q.setParameter("itemId", itemDto.getItemId());        q.executeUpdate();      }    }  }和例外情況如下:    org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: and near line 1, column 108 [update com.shopee.data.dto.brandseller.item.ItemDto item set item.l1CustomCategoryId = :l1CustomCategoryId and item.l2CustomCategoryId = :l2CustomCategoyId where itemId = :itemId]        at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]        at org.hibernate.hql.internal.ast.ErrorTracker.throwQueryException(ErrorTracker.java:93) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:296) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:188) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile
查看完整描述

1 回答

?
MMMHUHU

TA貢獻1834條經驗 獲得超8個贊

您不使用ANDwith SET,而是用逗號分隔它們。正確的語法是

SET item.l1CustomCategoryId = :l1CustomCategoryId, item.l2CustomCategoryId = :l2CustomCategoyId


查看完整回答
反對 回復 2023-09-27
  • 1 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號