MyBatis 传参错误……

我想要在JSP中通过两个date传参到action,然后想通过两个日期查询出表里的内容,但是参数传递到serviceImp的时候就卡住了……还是个小白所以很多不懂的(╥╯^╰╥)……相关代码全部贴出来了……希望大大们能解答一下……

我个人感觉可能是mapper里面没有对两个参数进行注解,但是我不懂怎么改……

先贴出报错……

严重: Servlet.service() for servlet [springmvc] in context with path [/MedicalExaminationSystem] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'payDate' not found. Available parameters are [0, 1, param1, param2]] with root cause

org.apache.ibatis.binding.BindingException:** Parameter 'payDate' not found. Available parameters are [0, 1, param1, param2]**
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:165)
ache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:44)

//action类
@Controller

public class ReportAction {

@Autowired
IReportService Service;

@RequestMapping("/getPayM") // 通过两个日期查询两个日期内的金额
public ModelAndView GetPayMoney(Date date1, Date date2) {
    ModelAndView modelAndView = new ModelAndView("Report");
    System.out.println("开始日期=" + date1);
    System.out.println("结束日期=" + date2);

    TPayMoney list = Service.querySumMoney(date1, date2);
    System.out.println("跳转信息发送到界面" + list);
    if (list != null) {// 判断不为空跳转
        System.out.println("返回");
        modelAndView.addObject(list);
        return modelAndView;
    } else {
        return modelAndView;
    }
}

}

//service接口
public interface IReportService {
public TPayMoney querySumMoney(Date date1,Date date2);

}

//servic实现类
@Service
public class ReportServiceImp implements IReportService{
@Autowired
private TPayMoneyMapper payMoneyMapper;

@Override
public TPayMoney querySumMoney(Date date1, Date date2) {
    System.out.println("ipm date1"+date1);
    System.out.println("ipm date2"+date2);//还可以读取到

    TPayMoney list = payMoneyMapper.selectByDate(date1, date2);
    System.out.println("出的来么"+list);//这里就读不出来了
    if (list != null) {
        return list;
    }
    return null;
}

}

//bean类
public class TPayMoney {

private BigDecimal payId;

private BigDecimal batId;

private BigDecimal payAccount;

private BigDecimal payPays;

private String payState;

private Date payDate;

public BigDecimal getPayId() {
    return payId;
}

public void setPayId(BigDecimal payId) {
    this.payId = payId;
}

public BigDecimal getBatId() {
    return batId;
}

public void setBatId(BigDecimal batId) {
    this.batId = batId;
}

public BigDecimal getPayAccount() {
    return payAccount;
}

public void setPayAccount(BigDecimal payAccount) {
    this.payAccount = payAccount;
}

public BigDecimal getPayPays() {
    return payPays;
}

public void setPayPays(BigDecimal payPays) {
    this.payPays = payPays;
}

public String getPayState() {
    return payState;
}

public void setPayState(String payState) {
    this.payState = payState == null ? null : payState.trim();
}

public Date getPayDate() {
    return payDate;
}

public void setPayDate(Date payDate) {
    this.payDate = payDate;
}

}

//mapper
@Repository
public interface TPayMoneyMapper {

//用时间查询内容
TPayMoney selectByDate(Date date1,Date date2);

}

//mapper.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">


<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Tue Sep 26 14:09:25 CST 2017.
-->







<!--   查询两个日期之间的数据 -->
<select id="selectByDate" parameterType="com.great.entity.TPayMoney" resultMap="BaseResultMap">
select 
<include refid="Base_Column_List" />
from TBL_PAYMONEY
where to_char(TBL_PAYMONEY.pay_date,'yyyy-mm-dd') between '#{payDate}' and '#{payDate}';
</select>
    </mapper>


    最后一个数据库
    /*==============================================================*/

/* Table: tbl_paymoney 付款表 /
/
==============================================================*/
create table tbl_paymoney (
pay_id NUMBER(20) not null,
bat_id NUMBER(20),
pay_account NUMBER(10,2),
pay_pays NUMBER(10,2),
pay_state VARCHAR2(20),
pay_date DATE,
constraint PK_TBL_PAYMONEY primary key (pay_id)
);

comment on table tbl_paymoney is '付款表';
comment on column tbl_paymoney.pay_id is '付款ID';
comment on column tbl_paymoney.bat_id is '批次ID';
comment on column tbl_paymoney.pay_account is '赊账';
comment on column tbl_paymoney.pay_pays is '已付款金额';
comment on column tbl_paymoney.pay_state is '状态';
comment on column tbl_paymoney.pay_date is '日期';

5个回答

你传的明明是date1和date2,为什么会写成payDate呢? = =

你对变量取值的时候要和你mapper里面穿的参数名字一样啊。。。

alan3494
alan3494 修改了还是报错……报错的内容还是一样的T_T
2 年多之前 回复

Parameter 'payDate' not found. 参数丢失

//用时间查询内容
TPayMoney selectByDate(Date date1,Date date2);

}
这里接口传的参数是 date1,date2,但是你对应的sql中


select

from TBL_PAYMONEY
where to_char(TBL_PAYMONEY.pay_date,'yyyy-mm-dd') between '#{payDate}' and '#{payDate}';

    引用的是payDate,系统根本没有这个参数,你怎么引用?
    改成 where to_char(TBL_PAYMONEY.pay_date,'yyyy-mm-dd') between '#{date1}' and '#{date2}';
    也许有效果
alan3494
alan3494 修改了还是报错……报错的内容还是一样的T_T
2 年多之前 回复

sql传参就错了吧,

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问