这个是什么错误?

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

9回答
好帮手慕珊 2019-06-02 16:25:25

你好!在claim_voucher_detail.jsp页面中,如下面代码所示添加forEach标签。因为转发到该jsp页面前,数据是存储在list中的,并没有claimVoucher这个内容,所以此处直接使用的时候会报错,其实claimVoucher是集合list中的一个值。

http://img1.sycdn.imooc.com//climg/5cf387990001721d09870809.jpg

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 提问者 96年的nash #1
    终于解决了,老师辛苦了,感激不尽~
    2019-06-02 16:51:19
好帮手慕阿满 2019-06-01 18:20:39

同学你好,建议同学在ClaimVoucherController类中的detail方法中,输出一下claimVocher,如:

http://img1.sycdn.imooc.com//climg/5cf2512b000116b808380231.jpg

重启项目,查看是否有输出。

祝:学习愉快~

  • 提问者 96年的nash #1
    没有输出,老师,没有任何输出
    2019-06-01 19:01:02
提问者 96年的nash 2019-06-01 16:12:14
package com.imooc.oa.biz.impl;

import com.imooc.oa.biz.ClaimVoucherBiz;
import com.imooc.oa.dao.ClaimVoucherDao;
import com.imooc.oa.dao.ClaimVoucherItemDao;
import com.imooc.oa.dao.DealRecordDao;
import com.imooc.oa.entity.ClaimVoucher;
import com.imooc.oa.entity.ClaimVoucherItem;
import com.imooc.oa.entity.DealRecord;
import com.imooc.oa.global.Contant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("claimVoucherBiz")
public class ClaimVoucherBizImpl implements ClaimVoucherBiz {
    //注入持久化操作对象
    @Autowired
    private ClaimVoucherDao claimVoucherDao;
    @Autowired
    private ClaimVoucherItemDao claimVoucherItemDao;
    @Autowired
    private DealRecordDao dealRecordDao;

    /**
     * 保存方法
     * PS:被封装成一个事务,故具有原子性
     * @param claimVoucher
     * @param items
     */
    public void save(ClaimVoucher claimVoucher, List<ClaimVoucherItem> items) {
        //设置三个属性
        //1、设置创建时间
        claimVoucher.setCreateTime(new Date());
        //2、设置待处理人 新创建的报销单的创建者一定创建者本人
        claimVoucher.setNextDealSn(claimVoucher.getCreateSn());
        //3、状态
        claimVoucher.setStatus(Contant.CLAIMVOUCHER_CREATED);

        //调用持久化操作对象的insert方法,将其保存到数据库中去
        claimVoucherDao.insert(claimVoucher);

        //后面插入item时,item需要这个id
        for(ClaimVoucherItem item:items){
            //缺少报销单编号
            item.setClaimVoucherId(claimVoucher.getId());
            claimVoucherItemDao.insert(item);
        }
    }

    /**
     * 获取报销单对象
     * @param id
     * @return
     */
    public ClaimVoucher get(int id) {
        return claimVoucherDao.select(id);
    }

    /**
     * 获取报销单对应的条目
     * @param cvid
     * @return
     */
    public List<ClaimVoucherItem> getItems(int cvid) {
        return claimVoucherItemDao.selectByClaimVoucher(cvid);
    }

    /**
     * 获取处理记录
     * @param cvid
     * @return
     */
    public List<DealRecord> getRecords(int cvid) {
        return dealRecordDao.selectByClaimVoucher(cvid);
    }

    /**
     * 获取个人报销单
     * @param sn 员工编号
     * @return
     */
    public List<ClaimVoucher> getForSelf(String sn) {
        return claimVoucherDao.selectByCreateSn(sn);
    }

    public List<ClaimVoucher> getForDeal(String sn) {
        System.out.println("进入了ClaimVoucherBizImpl");
        System.out.println("sn="+sn);
        return claimVoucherDao.selectByNextDealSn(sn);
    }
}
package com.imooc.oa.biz;

import com.imooc.oa.entity.ClaimVoucher;
import com.imooc.oa.entity.ClaimVoucherItem;
import com.imooc.oa.entity.DealRecord;

import java.util.List;

public interface ClaimVoucherBiz {

    /**
     *保存报销单的方法
     * @param claimVoucher 报销单的基本信息
     * @param items  报销单的条目集合
     */
    void save(ClaimVoucher claimVoucher, List<ClaimVoucherItem> items);



    /**
     * 详情界面
     * @param id 报销单编号
     * @return
     */
    ClaimVoucher get(int id);

    /**
     * 获得报销单条目
     * @param cvid 报销单的编号
     * @return
     */
    List<ClaimVoucherItem> getItems(int cvid);

    /**
     * 审核记录
     * @param cvid 报销单编号
     * @return
     */
    List<DealRecord> getRecords(int cvid);

    /**
     * 获取个人报销单
     * @param sn 员工编号
     * @return
     */
    List<ClaimVoucher> getForSelf(String sn);

    /**
     * 获取待处理报销单
     * @param sn 员工编号
     * @return
     */
    List<ClaimVoucher> getForDeal(String sn);
}
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--声明式事务
    为什么要把声明式事务配置在业务层?
    就是在持久化操作对象、业务处理对象、请求处理对象,这几种对象的某些方法封装成一个事务。(事务的四大特征)
    持久化操作对象:一个持久化操作(添加一个报销单记录、删除一个员工信息)
    web层:一次request,用户向服务器发送的一次请求,一次请求可能向你返回若干个业务功能,例如门户网站
    业务层:熟知的一个个功能,例如登录功能,添加员工功能,创建报销单功能。业务层的一个个方法就是体现这一个个功能

    如果把Dao层封装成一个个事务,就太细了。如果把web层的请求封装成一个个事务,就太粗了
    只有把业务层的方法封装成一个个事务 ,才是最合理的。
    因为业务层的一个个功能,要么成功,要么失败,符合事务四大特征的原子性
    所以声明式事务封装到业务层-->

    <!--关联SpringDao-->
    <import resource="spring_dao.xml"></import>

    <!--自动扫描-->
    <context:component-scan base-package="com.imooc.oa.biz"></context:component-scan>


    <!--自动代理-->
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>

    <!--配置声明式事务-->
    <!--1、声明事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--关联数据源-->
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!--2、声明通知-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!--通过属性的方式指定哪些方法我们要做怎样的处理-->
        <tx:attributes>
            <tx:method name="get*" read-only="true"/>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="search*" read-only="true"/>
            <!--下面的方法,必须强制开启事务-->
            <tx:method name="*" propagation="REQUIRED"></tx:method>

        </tx:attributes>
    </tx:advice>
    <!--3、把通知和切入点关联起来-->
    <aop:config>
        <!--声明切入点-->
        <aop:pointcut id="txpc" expression="execution(* com.imooc.oa.biz.*.*(..))"/>
        <!--连接-->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txpc"></aop:advisor>
    </aop:config>



</beans>
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);

    /**
     * 查询某个处理者能够处理的报销单
     * @param ndsn
     * @return
     */
    List<ClaimVoucher> selectByNextDealSn(String ndsn);
}
package com.imooc.oa.dao;

import com.imooc.oa.entity.ClaimVoucherItem;
import com.imooc.oa.entity.Department;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository("claimVoucherItemDao")
public interface ClaimVoucherItemDao {
    void insert(ClaimVoucherItem claimVoucherItem);
    void update(ClaimVoucherItem claimVoucherItem);
    void delete(int id);

    /**
     * 查询某个报销单:根据报销单编号 进行报销单的查询
     * @param cvid
     * @return
     */
    List<ClaimVoucherItem> selectByClaimVoucher(int cvid);
}


提问者 96年的nash 2019-06-01 09:22:58

这log上的反映的错误跟页面的上的错误一样啊,老师能不能快点帮忙解决一下,一个问题等两天了

  • 很抱歉同学,没能解决同学的问题,我们也很着急。从报错信息上看是claimVoucher字段获取为空,这个应该是传参的问题。建议同学描述一下同学具体做的什么操作,点击的那个按钮,该按钮对应的访问路径是什么,是有带有参数等。建议同学详细描述一下。
    2019-06-01 12:00:26
  • 提问者 96年的nash 回复 好帮手慕阿满 #2
    就是点左侧的待报销处理单,就出现这个错误了 路径是local8080/claim_voucher/deal
    2019-06-01 16:33:59
提问者 96年的nash 2019-06-01 09:22:00
01-Jun-2019 09:16:58.834 涓ラ噸 [http-nio-8080-exec-6] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [SpringMVC] in context with path [] threw exception [org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'claimVoucher' cannot be found on null] with root cause
 org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'claimVoucher' cannot be found on null
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:78)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:48)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:84)
	at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:114)
	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:105)
	at org.springframework.web.servlet.tags.EvalTag.doEndTag(EvalTag.java:123)
	at org.apache.jsp.WEB_002dINF.pages.claim_005fvoucher_005fdetail_jsp._jspx_meth_spring_005feval_005f0(claim_005fvoucher_005fdetail_jsp.java:245)
	at org.apache.jsp.WEB_002dINF.pages.claim_005fvoucher_005fdetail_jsp._jspService(claim_005fvoucher_005fdetail_jsp.java:160)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	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:52)
	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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:470)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	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:635)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	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:52)
	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:28)
	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:493)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
	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)


提问者 96年的nash 2019-06-01 09:18:27
 org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'claimVoucher' cannot be found on null
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:78)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:48)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:84)
	at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:114)
	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:105)
	at org.springframework.web.servlet.tags.EvalTag.doEndTag(EvalTag.java:123)
	at org.apache.jsp.WEB_002dINF.pages.claim_005fvoucher_005fdetail_jsp._jspx_meth_spring_005feval_005f0(claim_005fvoucher_005fdetail_jsp.java:245)
	at org.apache.jsp.WEB_002dINF.pages.claim_005fvoucher_005fdetail_jsp._jspService(claim_005fvoucher_005fdetail_jsp.java:160)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	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:52)
	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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:470)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	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:635)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	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:52)
	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:28)
	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:493)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
	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)
好帮手慕阿满 2019-05-31 19:12:07

同学你好,问一下同学是进行到哪一步报的这个错误。另外控制台没有报错,后边的两个log是否报错呢?如:

http://img1.sycdn.imooc.com//climg/5cf10c130001216704770085.jpg

建议同学查看一下,如果有报错,将报错信息贴一下。

祝:学习愉快~

提问者 96年的nash 2019-05-31 13:08:34
<?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>

    <!--向claim_voucher中插入一条记录,还需要向item中插入一条附属信息
    问题:插入时是没办法知道插入时的主键是哪个的  ,故需要得到这个主键-->
    <!--userGenerateKeys打开主键生成的功能 keyProperty:哪一个属性用来保存自动生成的主键-->
    <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>
    <!--查询功能,resultMap,需要关联两个数据表 -->
    <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>
<?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.ClaimVoucherItemDao">
    <resultMap id="claim_voucher_item" type="ClaimVoucherItem">
        <id property="id" column="id" javaType="Integer"/>
        <result property="claimVoucherId" column="claim_voucher_id" javaType="Integer"/>
        <result property="item" column="item" javaType="String"/>
        <result property="amount" column="amount" javaType="Double"/>
        <result property="comment" column="comment" javaType="String"/>
    </resultMap>

    <insert id="insert" parameterType="ClaimVoucherItem">
        insert into claim_voucher_item(claim_voucher_id,item,amount,comment)
        values(#{claimVoucherId},#{item},#{amount},#{comment})
    </insert>
    <update id="update" parameterType="ClaimVoucherItem">
        update  claim_voucher_item set claim_voucher_id=#{claimVoucherId},item=#{item},amount=#{amount},comment=#{comment}
        where id=#{id}
    </update>
    <delete id="delete" parameterType="Integer">
        delete from claim_voucher_item where id=#{id}
    </delete>
    <select id="selectByClaimVoucher" resultMap="claim_voucher_item">
        select * from claim_voucher_item where claim_voucher_id=#{cvid} order by id;
    </select>
</mapper>


好帮手慕阿满 2019-05-31 11:59:30

同学你好,建议同学将控制台的报错贴一下,方便我们查看具体问题。

祝:学习愉快~

  • 提问者 96年的nash #1
    控制台没报错,我在里面加了几个输出信息,这就是截的错误信息
    2019-05-31 13:06:20
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师