In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use parameterType in the Mybatis configuration mapping file. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Mybatis configuration Mapping File parameterType usage
In the configuration of the mybatis mapping API, select,insert,update,delete and other elements all mention the use of parameterType. ParameterType is the input parameter. When configuring, you can configure the corresponding input parameter type. ParameterType has basic data types and complex data type configurations.
1. Basic data type
If there is only one input parameter, its data type can be a basic data type or a self-defined class type. Including int,String,Integer,Date, as follows:
(1) Delete accordingly according to id:
(2) add employees:
two。 Complex data types: contains java entity classes, map
Configurations such as:
Select * from Teacher where c_id=# {id} and sex=# {sex}
The java code is as follows:
Map map=new HasMap (); map.put ("id", "2"); map.put ("sex", "male"); List tList = teacherMapper.selectTeacher (map); for (Teacher entityTemp: tList) {System.out.println (entityTemp.toString ());}
In addition, MyBatis provides a way to use annotations to include multiple parameters. This approach requires adding @ Param annotations to the parameters of the interface
Note here that because this method requires multiple parameters, * there is no way to configure multiple parameters at the same time when configuring Mybatis. In addition, MyBatis also provides a way to use annotations to enter * multiple parameters. This approach requires adding @ Param annotations to the parameters of the interface. * Note that the following two words are exactly the same. But use the first type * / User login (@ Param (value= "name") String name,@Param (value= "password") String password); / / User login (String name,String password)
The configuration is as follows:
Notes for select * from us where name=# {name} and password=# {password} Mybatis parameterType # $symbols
1. If more than one parameter type is passed, and the number of parameters is greater than or equal to 2, do not write parameterType or an error will be reported.
two。 There are two kinds of parsing incoming parameters: # {} and ${}. "#": the parameter you pass in will be parsed as a string, that is, whatever you pass in will be marked with the sign "$": whatever you pass in is what you pass in.
Thank you for reading! This is the end of the article on "how to use parameterType in the Mybatis configuration mapping file". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.