mapper的映射文件放在resources目录下,要取同名的,在mybatis官网找到对应的配置复制好
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- namespace属性:用于指定当前的映射文件和哪个接口进行映射,需要指定接口的文件路径,需要标注包的完整路径接口 -->
<mapper namespace="com.example.mapper.UserMapper">
<!--id的值:表示映射接口中方法的名称-->
<!--useGeneratedKeys="true":设置自增
keyProperty="uid":设置自增的名称
-->
<insert id="insert" >
INSERT INTO t_user(username,passwords)
VALUES (#{username},#{passwords})
</insert>
<!-- resultType:表示查询的结果集类型,只需要指定对应映射类的类型并且包含完整包接口-->
<select id="findByUsername" resultType="com.example.entity.User">
SELECT * FROM t_user WHERE username= #{username}
</select>
</mapper>
Result type not match for select id="findByUsername" srcType:
这个表示xml映射文件没配对
前往对应的xml文件加上这个即可
resultType="com.example.entity.User"
resultType:表示查询的结果集类型,只需要指定对应映射类的类型并且包含完整包接口
当出现数据库中的字段跟类的属性的字段不一致时就要用到resultMap对字段名进行匹配