10

【笔记】MyBatis将Mysql字段名和Java属性名映射

 2 years ago
source link: https://feiju12138.github.io/2022/09/25/MyBatis%E5%B0%86Mysql%E5%AD%97%E6%AE%B5%E5%90%8D%E5%92%8CJava%E5%B1%9E%E6%80%A7%E5%90%8D%E6%98%A0%E5%B0%84/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【笔记】MyBatis将Mysql字段名和Java属性名映射

2022-09-25 Java后端学习指北

1

MyBatis将Mysql字段名和Java属性名映射

在sql映射xml中配置映射

  • 在sql映射xml中配置文件中,利用<resultMap></resultMap>标签配置Mysql字段名和Java属性名的映射
  • 在其他需要返回值的标签属性中,不使用ResultType,改用ResultMap,值为<resultMap></resultMap>的id属性

src/main/resources/UserMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.Mapper.UserMapper">

<resultMap id="UserResultMap" type="com.pojo.User">
<result column="user_name" property="userName" />
</resultMap>

<select id="selectAll" resultMap="UserResultMap">
select * from user
</select>

</mapper>

哔哩哔哩——黑马程序员

</article


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK