Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of Update dynamic SQL comma by MyBatis

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how MyBatis solves the problem of Update dynamic SQL comma". In daily operation, I believe many people have doubts about how to solve the problem of Update dynamic SQL comma in MyBatis. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the question of "how to solve the problem of Update dynamic SQL comma by MyBatis". Next, please follow the editor to study!

Update dynamic SQL comma problem

The most important project encountered the following situation: dynamic splicing of Update is needed in MyBatis. Since I was busy catching up with the project, I wrote it as follows, only to find that there was an exception in the system. If I wrote in this way, id=null would make an error.

UPDATE TABLE SET id= # {id,jdbcType=INTEGER}, name = # {name,jdbcType=VARCHAR} where id= # {id,jdbcType=INTEGER}

So I looked up the API and official documents of Mybatis online and found the following

Solution UPDATE TABLE id= # {id,jdbcType=INTEGER}, name = # {name,jdbcType=VARCHAR}, where id= # {id,jdbcType=INTEGER}

Node label:

The main function of trim is that you can add some prefixes (prefix) to the content contained in Trim or some suffixes (suffix) after the content contained in Trim.

You can also ignore some content in the first part of the content contained in Trim (prefixOverrides), or ignore some content in the end of the content contained in Trim (suffixOverrides).

This line of code means: add set in front of it and remove the last comma!

Note method 2: put the contents of the update condition tag in the tag

Mapper (Update) comma position update t_role name=# {name}, msg=# {msg}, type=# {type}, creator_id=# {creator_id}, level=# {level} where id=# {id}

Use can intelligently remove the last comma, very convenient!

At this point, the study on "how MyBatis solves the problem of Update dynamic SQL commas" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report