mybatis parameterType
时间: 2023-10-11 09:12:07 浏览: 115
MyBatis parameterType is a required attribute in the `<insert>`, `<update>`, `<delete>`, and `<select>` statements. It specifies the Java type of the parameter(s) that are passed to the SQL statement.
The parameterType can be a fully qualified class name or an alias defined in the MyBatis configuration file. It tells MyBatis how to map the input parameters to the placeholders in the SQL statement.
For example, if you have a parameterType of "com.example.User" in your `<insert>` statement, MyBatis will expect a single object of type User to be passed as the parameter when executing that statement.
Here's an example of how to use parameterType in a MyBatis XML mapper file:
```xml
<insert id="insertUser" parameterType="com.example.User">
INSERT INTO users (id, name, age) VALUES (#{id}, #{name}, #{age})
</insert>
```
In this example, the parameterType is set to "com.example.User", and the properties of the User object (`id`, `name`, and `age`) are mapped to the corresponding columns in the `users` table using MyBatis's parameter mapping feature.
It's important to ensure that the parameterType matches the actual type of the parameter passed to the statement, as MyBatis relies on this information for proper mapping and type conversion.
阅读全文