mysql updata 設置動態字段名方式---異常處理

1.因爲是動態獲取的字段名稱,故在更新的時候須要動態的字段名spa

採用以下方式會報錯:code

update  TB_PICTURES
            set 
                #{TITLE}= ' '

 

2.加入判斷的方式,便可動態設置字段名blog

  每個字段,都加入判斷,符合判斷則更新,便可動態設置字段名。class

  注意:每個判斷進去的語句後面必須加逗號,不然一樣會報錯。test

 1 update  TB_PRODUCT
 2             set 
 3                 <if test="PRODUCT_IMG1 != null and PRODUCT_IMG1 != ''">
 4                     PRODUCT_IMG1            = '',
 5                 </if>
 6                 <if test="PARAMETER_IMG1 != null and PARAMETER_IMG1 != ''">
 7                     PARAMETER_IMG1            = '',
 8                 </if>
 9                 <if test="APPLICATION_IMG1 != null and APPLICATION_IMG1 != ''">
10                     APPLICATION_IMG4            = '',
11                 </if>
12                 <if test="APPLICATION_IMG2 != null and APPLICATION_IMG2 != ''">
13                     APPLICATION_IMG2            = '',
14                 </if>
15                 <if test="APPLICATION_IMG3 != null and APPLICATION_IMG3 != ''">
16                     APPLICATION_IMG3            = '',
17                 </if>
18                 <if test="APPLICATION_IMG4 != null and APPLICATION_IMG4 != ''">
19                     APPLICATION_IMG4            = '',
20                 </if>
21                  ID = ID
22             where 
23                 ID = #{ID}
相關文章
相關標籤/搜索