Java mybatis查找找不到字段名

使用mybatis中的resultMap将数据库的company_name字段映射成companyName后,执行多条件查询操作。仍然出现错误:找不到companyName

img

mapper.xml相关设置如下

img

img

测试类代码如下

img

与Mapper.xml对应的接口类如下

img

数据库表如下

img

题主要明白Mybatis的原理,mybatis只是个orm框架,只是在你查询的时候通过映射成想要的对象,但是查询条件里面的字段名必须是数据库里面的字段才可以

那你换成数据库中的字段试试看呢

img

img

感谢大佬帮忙,确实如上面两位大佬说的。

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 你可以看下这个问题的回答https://ask.csdn.net/questions/674166
  • 除此之外, 这篇博客: Mybatis开发要点-resultType和resultMap的区别?中的 2、Mapper.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.mybatis.mapper.TUserMapper">
    
    	<resultMap id="UserResultMap" type="TUser" autoMapping="true">
    		<id column="id" property="id" />
            <result column="userName" property="userName"/>
    		<result column="realName" property="realName" />
    		<result column="sex" property="sex" />
    		<result column="mobile" property="mobile" />
    		<result column="email" property="email" />
    		<result column="note" property="note" />
    		<association property="position" javaType="TPosition" columnPrefix="post_">
    			<id column="id" property="id"/>
    			<result column="name" property="postName"/>
    			<result column="note" property="note"/>
    		</association>
    	</resultMap>
    
    	<select  id="selectTestResultMap" resultMap="UserResultMap" >
    		select
    		    a.id,
    		    userName,
    			realName,
    			sex,
    			mobile,
    			email,
    			a.note,
    			b.id  post_id,
    			b.post_name,
    			b.note post_note
    		from t_user a,
    			t_position b
    		where a.position_id = b.id
    
    	</select>
    
    </mapper>

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^