场景:
service中间调用dao层方法时,出现以下错误,但是sql执行修改数据成功,并没有回滚问题:
十月 31, 2017 2:53:39 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [bigaoread] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Mapper method 'com.bigaoread.platform.dao.beautifulreader.v2.YzActivecontrolMapper.updateActiveId' has an unsupported return type: class com.bigaoread.platform.model.beautifulreader.v2.YzActivecontrol] with root cause
org.apache.ibatis.binding.BindingException: Mapper method 'com.bigaoread.platform.dao.beautifulreader.v2.YzActivecontrolMapper.updateActiveId' has an unsupported return type: class com.bigaoread.platform.model.beautifulreader.v2.YzActivecontrol
at org.apache.ibatis.binding.MapperMethod.rowCountResult(MapperMethod.java:91)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:54)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at com.sun.proxy.$Proxy41.updateActiveId(Unknown Source)
原因:这个是因为dao层的sql执行成功后,返回的类型出现问题。
代码:
service层:
public Map<String, Object> updateActiveId(String newActiveId, String oldActiveId) {
Map<String, Object> resultMap = new HashMap<>();
if(subscribeQrcodeService.isExistActiveId(Long.parseLong(newActiveId))) {
resultMap.put("status", 1);
return resultMap;
}
if(!(null == this.get(Long.parseLong(newActiveId)))) {
resultMap.put("status", 1);
return resultMap;
}
Map<String, Object> updateIdMap = new HashMap<>();
updateIdMap.put("newActiveId", Long.parseLong(newActiveId));
updateIdMap.put("oldActiveId", Long.parseLong(oldActiveId));
yzActivecontrolMapper.updateActiveId(updateIdMap);
resultMap.put("status", 0);
return resultMap;
}
dao层:
YzActivecontrol updateActiveId(Map<String, Object> updateIdMap);
mapper.xml:
<update id="updateActiveId" parameterType="Map">
UPDATE <include refid="tableName"/>
SET id = #{newActiveId}
WHERE id = #{oldActiveId}
</update>
解决:
mapper文件中的update,delete,insert语句是不需要设置返回类型的,它们都是默认返回一个int,所以应该修改dao层接口的方法:
Integer updateActiveId(Map<String, Object> updateIdMap);
或者
void updateActiveId(Map<String, Object> updateIdMap);