提交报错,没有改代码
0, Size: 0] with root cause
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:657)
at java.util.ArrayList.get(ArrayList.java:433)
at com.imooc.oa.biz.impl.ClaimVoucherBizImpl.submit(ClaimVoucherBizImpl.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy25.submit(Unknown Source)
at com.imooc.oa.controller.ClaimVoucherController.submit(ClaimVoucherController.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.imooc.oa.global.EncodingFilter.doFilter(EncodingFilter.java:21)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
正在回答 回答被采纳积分+1
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.4//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.oa.dao.EmployeeDao">
<resultMap id="employee" type="Employee">
<id property="sn" column="sn" javaType="String"/>
<result property="password" column="password" javaType="String"/>
<result property="name" column="name" javaType="String"/>
<result property="departmentSn" column="department_sn" javaType="String"/>
<result property="post" column="post" javaType="String"/>
<association property="department" column="department_sn" javaType="Department" >
<id property="sn" column="dsn" javaType="String"/>
<result property="name" column="dname" javaType="String"/>
</association>
</resultMap>
<insert id="insert" parameterType="Employee">
insert into employee values(#{sn},#{password},#{name},#{departmentSn},#{post})
</insert>
<update id="update" parameterType="Employee">
update employee set name=#{name},password=#{password},department_sn=#{departmentSn},post=#{post} where sn=#{sn}
</update>
<delete id="delete" parameterType="String">
delete from employee where sn=#{sn}
</delete>
<select id="select" parameterType="String" resultMap="employee">
select e.*,d.sn dsn,d.name dname from employee e left join department d on d.sn=e.department_sn
where e.sn=#{sn}
</select>
<select id="selectAll" resultMap="employee">
select e.*,d.sn dsn,d.name dname from employee e left join department d on d.sn=e.department_sn
</select>
<select id="selectByDepartmentAndPost" resultMap="employee">
select e.*,d.sn dsn,d.name dname from employee e left join department d on d.sn=e.department_sn
where e.sn is not NULL
<if test="dsn!=null">
and e.department_sn=#{dsn}
</if>
<if test="post!=null">
and e.post=#{post}
</if>
</select>
</mapper>
package com.imooc.oa.dao;
import com.imooc.oa.entity.Employee;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository("employeeDao")
public interface EmployeeDao {
void insert(Employee employee);
void update(Employee employee);
void delete(String sn);
Employee select(String sn);
List<Employee> selectAll();
List<Employee> selectByDepartmentAndPost(@Param("dsn") String dsn,@Param("post") String post);
}
你好同学,测试了你的代码是没问题的,出现问题的原因应该是你employee没有返回员工数据,我需要你提供下图标记的两个文件的代码,注意不要将问题粘贴到回复中哦,应该粘贴到回答中,否则会失去代码格式的,祝学习愉快~
package com.imooc.oa.dao;
import com.imooc.oa.entity.ClaimVoucher;
import com.imooc.oa.entity.Employee;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository("claimVoucherDao")
public interface ClaimVoucherDao {
void insert(ClaimVoucher claimVoucher);
void update(ClaimVoucher claimVoucher);
void delete(int id);
ClaimVoucher select(int id);
List<ClaimVoucher> selectByCreateSn(String csn);
List<ClaimVoucher> selectByNextDealSn(String ndsn);
}
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.4//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.oa.dao.ClaimVoucherDao">
<resultMap id="claimVoucher" type="ClaimVoucher">
<id property="id" column="id" javaType="int"/>
<result property="cause" column="cause" javaType="String"/>
<result property="createSn" column="create_sn" javaType="String"/>
<result property="createTime" column="create_time" javaType="java.util.Date"/>
<result property="nextDealSn" column="next_deal_sn" javaType="String"/>
<result property="totalAmount" column="total_amount" javaType="Double"/>
<result property="status" column="status" javaType="String"/>
<association property="creater" column="create_sn" javaType="Employee">
<result property="name" column="cname" javaType="String"/>
<result property="post" column="cpost" javaType="String"/>
</association>
<association property="dealer" column="next_deal_sn" javaType="Employee">
<result property="name" column="dname" javaType="String"/>
<result property="post" column="dpost" javaType="String"/>
</association>
</resultMap>
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="ClaimVoucher">
insert into claim_voucher(cause,create_sn,create_time,next_deal_sn,total_amount,status)
values(#{cause},#{createSn},#{createTime},#{nextDealSn},#{totalAmount},#{status})
</insert>
<update id="update" parameterType="ClaimVoucher">
update claim_voucher set cause=#{cause},next_deal_sn=#{nextDealSn},total_amount=#{totalAmount},status=#{status} where id=#{id}
</update>
<delete id="delete" parameterType="Integer">
delete from claim_voucher where id=#{id}
</delete>
<select id="select" resultMap="claimVoucher" parameterType="Integer">
select cv.*,ce.name cname,ce.post cpost,d.name dname,d.post dpost
from claim_voucher cv
left join employee ce on ce.sn=cv.create_sn
left join employee d on d.sn = cv.next_deal_sn
where cv.id=#{id}
</select>
<select id="selectByCreateSn" resultMap="claimVoucher" parameterType="String">
select cv.*,ce.name cname,ce.post cpost,d.name dname,d.post dpost
from claim_voucher cv
left join employee ce on ce.sn=cv.create_sn
left join employee d on d.sn = cv.next_deal_sn
where cv.create_sn=#{csn} order by cv.create_time desc
</select>
<select id="selectByNextDealSn" resultMap="claimVoucher" parameterType="String">
select cv.*,ce.name cname,ce.post cpost,d.name dname,d.post dpost
from claim_voucher cv
left join employee ce on ce.sn=cv.create_sn
left join employee d on d.sn = cv.next_deal_sn
where cv.next_deal_sn=#{ndsn} order by cv.create_time desc
</select>
</mapper>
你好同学,建议你不要着急,遇到问题只能一点一点试,这也是教同学如何解决bug的方法,另外同学粘贴一下我下图标记的代码,方便我测试一下,你的问题应该是数据库没有返回数据的问题,祝学习愉快~
你好同学,建议你在下图标记的地方打印一下员工对象信息,看是否会有数据呢?祝学习愉快~
老师的源码中102行代码是下图标记的内容,建议你粘贴一下你102行的代码,让我看以下是哪处的代码出现了问题,方便具有针对性的为你解答,祝学习愉快~
你好同学,你可以看一下下图报错提示,异常信息是数组下标越界,出现问题的代码在claimVoucherBizImpl类中的第102行代码中。建议同学检查一下该类中的102行处是否出现了数组下标越界的情况,可以打印一下数据看看,祝学习愉快~
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星