Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

为什么MyBatis的官方文档如此粗糙

拿来一份别人的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.imooc.user.mapper.FansMapper">
  <resultMap id="BaseResultMap" type="com.imooc.pojo.Fans">

    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="writer_id" jdbcType="VARCHAR" property="writerId" />
    <result column="fan_id" jdbcType="VARCHAR" property="fanId" />
    <result column="face" jdbcType="VARCHAR" property="face" />
    <result column="fan_nickname" jdbcType="VARCHAR" property="fanNickname" />
    <result column="sex" jdbcType="INTEGER" property="sex" />
    <result column="province" jdbcType="VARCHAR" property="province" />
  </resultMap>
</mapper>

打开
https://mybatis.org/mybatis-3...
官方文档

咦! mapper 这么没有哦! 他是什么意思呀???
id id 这个也么有哦

result又是什么鬼。。。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

结果映射这一块,有个示例代码和你的这个基本相同。

<resultMap id="userResultMap" type="User">
  <id property="id" column="user_id" />
  <result property="username" column="user_name"/>
  <result property="password" column="hashed_password"/>
</resultMap>

id & result下面也都是有的

<id property="id" column="post_id"/>
<result property="subject" column="post_subject"/>

我猜让你感到恼火的主要原因有以下几点:

  1. 对Mybatis不熟悉;
  2. 官方文档用词生硬看不懂;

那咋办呢,我有以下解决方案:

方法一:
从你这namespace可以看出来,这应该是imooc的相关课程教程,可以去imooc平台查找相关课程教程,比如:MyBatis 入门教程

方法二:
官方文档看不懂可以看别人写的博客呀,打开搜索引擎,关键词“Mybatis xml mapper”,立马就能找到一堆博客,如:MyBatis mapper.xml 详解


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...