java face questions MyBatis entity classes in the attribute table and field names in different solutions

1 write sql statement ever since aliases

select id, u_name uname, u_age age from emp; u_name will be mapped to the database entity class attributes uname

open hump naming MyBatis in the global configuration file   can be mapped database underlined camelCase underscore Note that the database must be next to the

  <settings>

          <setting name="mapUnderscoreToCamelCase"  value="true"/>   

</settings>

in resultMap Mapper mapping file to customize the advanced mapping

 <select id="select01" resultMap="MyMap">

  select * from emp where id=#{id}

</select >

<resultMap  type="com.atguigu.com.entities.emp"  id="MyMap"

   <! - mapping the primary key ->

    <id column="id"  property="id"/>

    <! - other columns mapped to the corresponding attribute in the property named entity class ->

<result  column="e_name"  property="ename"/>

</resultMap>

Guess you like

Origin www.cnblogs.com/weiikun/p/10988066.html