MyBatis column mapping using annotation with @Select

Asked on March 18, 2015
In MyBatis XML Mapper, there is a tag as <resultMap>   which maps select query result columns to POJO properties. I am using annotation now in my MyBatis application. There is @Select annotation to perform select query.
Now how to achieve <resultMap> functionality using annotation. 

Please reply.

Replied on March 18, 2015
MyBatis provides  @Results annotation and is used to map java class property and table column.

        @Result(property = "user_id", column = "id"),
        @Result(property = "firstName", column = "first_name"),

@Select("SELECT id, name, district from user WHERE id = #{id}")
User selectUser(int id);

Write Answer

©2023 | Privacy Policy | Contact Us