ssm 集成开发时出现时单元测试Mapper 注入不进去的情况的解决方法
第一步:检查相应的是否构建了spring的容器环境
UserMapper userMapper = context.getBean(UserMapper.class);
或者写一个基类直接继承 例如:
最后
最后测试相应的dao:
如果还有问题就是xxxMapper.xml文件的问题
第一步:检查xxxMapper.xml文件的名称是否和xxxMapper.java 在同一个目录下(同一个包下)
第二步:检查xxx.xml 中的namespace是否和xxxMapper.java 的包路径.xxxMapper相同
第三步:检查接口中对应的方法的输入类型和输出类型是否和xxxMapper.xml中的一致
例如我的AdminInfoMapper.xml:
<insert id="addAdmin" parameterType="com.kk.pojo.AdminInfo" >insert into admin_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name!=null and name !=''">
name,
</if>
<if test="sex!=null and sex !=''">
sex,
</if>
<if test="age!=null and age !=''">
age,
</if>
<if test="address!=null and address !=''">
address,
</if>
<if test="idCard!=null and idCard !=''">
id_card,
</if>
<if test="phone!=null and phone !=''">
phone,
</if>
<if test="picture!=null and picture !=''">
picture,
</if>
<if test="workplace!=null and workplace !=''">
workplace,
</if>
<if test="createtime!=null and createtime !=''">
createtime,
</if>
<if test="updatetime!=null and updatetime !=''">
updatetime,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name!=null and name !=''">
#{name},
</if>
<if test="sex!=null and sex !=''">
#{sex},
</if>
<if test="age!=null and age !=''">
#{age},
</if>
<if test="address!=null and address !=''">
#{address},
</if>
<if test="idCard!=null and idCard !=''">
#{idCard},
</if>
<if test="phone!=null and phone !=''">
#{name},
</if>
<if test="picture!=null and picture !=''">
#{picture},
</if>
<if test="workplace!=null and workplace !=''">
#{workplace},
</if>
<if test="createtime!=null and createtime !=''">
#{createtime},
</if>
<if test="updatetime!=null and updatetime !=''">
#{updatetime},
</if>
</trim>
</insert>
按照我的方法问题基本会解决