In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
The real power of MyBatis is that in the mapping statement, the SQL mapping file has the following top-level elements.
Cache- configure cache cache-ref for a given namespace-reference cache configuration resultMap from other namespaces-used to describe how to load your object sql from the database result set-SQL blocks that can be reused, can also be referenced by other statements-mapping insertion statement update-mapping update statement delete-mapping deletion statement select-mapping query statement
Select
Query statements are one of the most commonly used elements when using MyBatis, and there are a lot of queries for each insert, update, or delete. This is one of the basic principles of MyBatis, and it is also the reason to focus on query and result mapping. Query elements for simple categories are very simple.
For example:
SELECT * FROM PERSON WHERE ID = # {id}
This statement, called selectPerson, takes a parameter of type int (or Integer) and returns an object of type HashMap, where the key is the column name and the value is the corresponding value of the column.
This tells MyBatis to create a PreparedStatement (preprocessing statement) parameter. With JDBC, such a parameter is represented in SQL by a "?" To identify and pass to a new preprocessing statement, like this:
/ / similar JDBC code, not MyBatis String selectPerson = "SELECT * FROM PERSON WHERE ID=?"; PreparedStatement ps = conn.prepareStatement (selectPerson); ps.setInt (1Magi id)
Of course, this requires a lot of separate JDBC code to extract the results and map them to the object instance, which is where MyBatis saves you time. We need an in-depth understanding of parameter and result mappings.
The select element has a number of attributes that you can configure to determine the details of each statement.
The following is an introduction to each parameter:
Id [unique identifier in the namespace, can be used to reference SQL statements] parameterType [type of parameter class passed into the SQL statement] resultTyp [type or alias of the class of the desired type returned in the SQL statement. For a collection, that should be the type that the collection can contain, not the collection itself] resultMap [named reference external resultMap] SELECT * FROM t_user WHERE USER_ID = # {userId} flushCache [set it to true, whenever the statement is called, it will cause the cache to be cleared
Empty. The default value: false] useCache [setting it to true will cause the result of this statement to be cached. Default: true] timeout [driver waits for the database to return the request result and throws the exception time of the
Maximum wait value] fetchSize [number of result rows returned by the driver in each batch] statementType [STATEMENT,PREPARED or CALLABLE, which allows MyBatis to choose to use Statement,PreparedStatement or CallableStatement
Default value: PREPARED] resultSetType [FORWARD_ONLY | SCROLL_SENSITIVE | SCROLL_INSENSITIVE
One of them. Default is not set (driver handles itself)] insert
For insert operations, if the database table structure supports automatic generation of primary key fields, then you can set useGeneratedKeys= "true" and set keyProperty to the target attribute you have already done.
For example:
Insert into Author (username,password,email,bio) values (# {username}, # {password}, # {email}, # {bio}) update
For example:
Update Author setusername = # {username}, password = # {password}, email = # {email}, bio = # {bio} where id = # {id} delete
For example:
Delete from Author where id = # {id}
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.