In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the dynamic SQL of mybatis and the relevant knowledge points about how to configure the connection pool. the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Mybatis dynamic SQL and connection Pool
Mybatis queries based on the parameters passed in.
Select * from users where 1 and name= # {name}
If it's too much, don't write where1=1. Nest if tags outside the if.
Select * from users and name= # {name}
At the same time, and in the first if statement will be omitted!
Range query in mybatis, in
Mybatis range query, such as select * from users where age in (11mem12 13)
Define a wrapper class externally, wrap ages as a property, and take id as an example (define a collection externally to wrap it)
The beginning of the select * from users / / where clause, and or or, will be removed by the where element. The judgment condition here is the Java statement # {id}
SQL statement select field from where id in {?}
The tag is used to traverse the collection, and its properties
Collection represents the collection element (attribute name) to traverse
Open stands for the beginning of the statement
Close stands for the end of the statement
Item represents the name of the variable generated by traversing each element of the collection
Sperator represents a separator between elements
Connection pool
Connection pooling: used in actual development, it can reduce the time it takes us to get connections.
Mybatis connection pooling provides three ways of configuration
Configured in the DataSource property in the main configuration file
The value POOLED of type adopts the connection pool in the traditional javax.sql.DataSource specification.
Although UNPOLLED implements the DataSource standard, it does not use the concept of pooling (Connection object).
JNDI uses the jndi technology provided by the server to get the DataSource object. Note: if it is not the web project and maven's war project, it is not available.
Note: the underlying manipulation of transactions in mybatis is set by manipulating Connection objects.
POOLED: take the connection out of the pool and finally put the connection back in the pool.
UNPOOLED creates a connection and ends the connection (jdbc connection mode)
Dynamic sql and multi-table join query dynamic sql
① where and if tags
② foreach Loop label
Note:
Add ③ in batch
④ selectKey
Join query with multiple tables
① many-to-one query
a)。 When building a table, the foreign key must be built on the long side.
b)。 Create an object property on one end of the entity class on one side of the multi-end.
c)。 Join the sql statement of the query
① select... From Table 1 left join Table 2 on connection conditions. The connection condition is generally the primary key pointed to by the foreign key.
② resultMap
I. general properties of id,result configuration
ii. The association tag configures extra fields, property and javatype attributes. Subtags id and result
How to modify ② many-to-one query
③ one-to-many query
Different from many-to-one queries:
A) when you create an entity class, you create a List attribute on one end, and the List contains objects on more than one side.
B) detailed resultMap configuration
These are all the contents of the article "dynamic SQL of mybatis and how to configure connection pooling". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.