How can I pass multiple parameters and use them?

前端 未结 3 1917
执笔经年
执笔经年 2021-02-07 05:41

Hi I\'m new to myBatis.

I\'m using MyBatis and Spring with mybatis-spring.

How can I pass two different types of objects as parameters, and how can I use their p

3条回答
  •  野性不改
    2021-02-07 06:31

    I would suggest reading the MyBatis documentation - it is pretty comprehensive and accurate.

    Lets take an example: updating a customer's name from a com.mycompany.Customer POJO instance, which has a getFirstName() getter.

    1. Pass an instance of your Customer class as the parameter
    2. Set the parameterType= "com.mycompany.Customer". But check out the alias facility - then you can use the shorthand version parameterType="Customer"
    3. Use the standard MyBatis syntax in the SQL: ... set FIRST_NAME = #{firstName}

    (Edit) If you need to pass multiple objects there are various options:

    1. Pass a map containing the multiple objects
    2. Create a utility class the aggregates your multiple classes, and pass this as the parameter.

    Again, please read the manual...

提交回复
热议问题