Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use parameterType in Mybatis configuration Mapping File

Shulou Source: shulou.com Published: 2022-06-03 09:06:45 11月15日 Update

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!

Tags: Parameters configuration type data multiple methods comments files interfaces input complexity content time more articles good practical the same the number that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Shulou Information Huawei OPPO Reno