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

What is the difference between # and $in mybatis

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "what is the difference between # and $in mybatis". In daily operation, I believe that many people have doubts about the difference between # and $in mybatis. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "what is the difference between # and $in mybatis"! Next, please follow the editor to study!

Question details

When we concatenate mysql sentences, some bosses usually remind us to pay attention to the use of the # and $symbols:

Id = # {id}, id = ${id}, what's the difference between the two ways of writing?

Question and answer

With the sign of #, you can spell sql statements by using PreparedStatement+ placeholders, which can prevent sql injection and make it more secure.

The problem analysis of the treatment of #

In the source code, the special handling of # {} can be seen in this location.

Then we open the breakpoint inside the parser and see that after parsing, it changes from # {id} to?

Changing it to? At the same time, wrap the id as parameterMapping and add it to the parameterMappings, then get it later, then take the value, and then put the value into the prepareStatement

Step by step down the debug, we go through the Executor (actuator), then go to the TypeHandler, find the corresponding parameter handler, and execute ps.setInt (position, value). Completed the whole process.

Treatment of the $sign

This is very simple.

When SqlSource.getBoundSql () is called to get the sql to be executed, it is replaced by the token parser.

At this point, the study on "what's the difference between # and $in mybatis" 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

Internet Technology

Wechat

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

12
Report