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
Do not specify parameterType
but use @Param
annotation on parameters in mapper:
@Mapper
public interface MyMapper {
void update(@Param("a") A a, @Param("b") B b);
...
}
Then reference them in mapping:
<update id="update" >
UPDATE SOME WHERE x=#{a.x} AND y=#{b.y}
</update>
Use parameterType="map" and @Param annotation.
Method declared in interface:
void mapCategoryAndPage(@Param("categoryLocalId") Long categoryLocalId, @Param("pageLocalId") Long localId);
It is not required that value of @Param annotation must be equal to name of parameter
<insert id="mapCategoryAndPage" parameterType="map">
INSERT INTO
category_page_mapping (
page_local_id,
category_local_id)
VALUES
(#{pageLocalId},
#{categoryLocalId});
</insert>
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.
(Edit) If you need to pass multiple objects there are various options:
Again, please read the manual...