1 写sql语句的时候起别名

select id,u_name uname ,u_age age from emp;   则会将数据库中的u_name 映射为实体类中uname属性上

在MyBatis的全局配置文件中开启驼峰命名规则  可以将数据库中的下划线映射为驼峰命名  注意 数据库中的下划线必须是挨着的

  <settings>

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

</settings>

在Mapper映射文件中使用resultMap来自定义高级映射

 <select >

  select * from emp where id=#{id}

</select >

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

   <!--映射主键-->

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

    <!--映射其他列  property中就对应实体类中的属性名-->

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

</resultMap>

相关文章:

  • 2022-12-23
  • 2021-04-04
  • 2021-06-14
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2023-01-15
猜你喜欢
  • 2021-07-10
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
相关资源
相似解决方案