Home  >  Forum  >  MyBatis
Post New Query

MyBatis column mapping using annotation with @Select


joined on
November 09,2013
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.
joined on
March 14,2013
Replied on March 18,2015

MyBatis provides  @Results annotation and is used to map java class property and table column.

@Results({
        @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









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us