ssm 整合開發時出現時單元測試Mapper 注入不進去的情況的解決方法
阿新 • • 發佈:2019-02-08
第一步:檢查相應的是否構建了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>
按照我的方法問題基本會解決
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>
按照我的方法問題基本會解決