NutzCN Logo
问答 调用存储过程映射问题
发布于 2194天前 作者 igo44444 1729 次浏览 复制 上一个帖子 下一个帖子
标签:

参照使用手册:

	public TimesInfo queryTimesInfo(int beginIndex, int endIndex, String codeNum, String cnd1, String cnd2) {
		Sql sql = Sqls.fetchEntity("call ticket_times_info(@begin_index,@end_index,@code_num,@cnd1,@cnd2)");

		sql.setEntity(dao.getEntity(TimesInfo.class));
		sql.params().set("begin_index", beginIndex);
		sql.params().set("end_index", endIndex);
		sql.params().set("code_num", codeNum);
		sql.params().set("cnd1", cnd1);
		sql.params().set("cnd2", cnd2);

		dao.execute(sql);
		TimesInfo timesInfolist = sql.getObject(TimesInfo.class);

		return timesInfolist;
	}

实体类:

package com.dodoke.bean;

import org.nutz.dao.entity.annotation.Column;

public class TimesInfo {
	@Column(hump = true)
	private Integer codeNum;
	@Column(hump = true)
	private Integer allShowTimes;
	@Column(hump = true)
	private Integer nonShowTimes;
	@Column(hump = true)
	private Integer timesSum;

	public Integer getCodeNum() {
		return codeNum;
	}

	public void setCodeNum(Integer codeNum) {
		this.codeNum = codeNum;
	}

	public Integer getAllShowTimes() {
		return allShowTimes;
	}

	public void setAllShowTimes(Integer allShowTimes) {
		this.allShowTimes = allShowTimes;
	}

	public Integer getNonShowTimes() {
		return nonShowTimes;
	}

	public void setNonShowTimes(Integer nonShowTimes) {
		this.nonShowTimes = nonShowTimes;
	}

	public Integer getTimesSum() {
		return timesSum;
	}

	public void setTimesSum(Integer timesSum) {
		this.timesSum = timesSum;
	}

}

页面显示Json数据:

[
    {
        "codeNum": 5,
        "allShowTimes": 7,
        "nonShowTimes": 0,
        "timesSum": 7
    }
]

但是在navicat查询窗口中直接跑:

call ticket_times_info(0,20,'5','n5=1','!(n5=1)')

结果是:
|code_num|all_show_times|non_show_times|times_sum|
|5| 11 |9 |20|

10 回复

结果实体类映射错乱,不知道哪里错了

存储过程怎么写的?

CREATE DEFINER=`root`@`%` PROCEDURE `ticket_times_info`(
IN beginIndex int,
IN endIndex int,
IN code_num VARCHAR(100),
IN cnd1 VARCHAR(1000),
IN cnd2 VARCHAR(1000)
)
BEGIN
	
	set @sql1 = concat('SELECT count(*) as all_show_times into @temp0 FROM (SELECT * FROM ticket_info  ORDER BY id DESC LIMIT ?,? ) valid_data WHERE 1=1 and ',cnd1);
	set @a1 = beginIndex;
	set @a2 = endIndex;

	PREPARE statement1 from @sql1;
	EXECUTE statement1 USING @a1,@a2;
	DEALLOCATE PREPARE statement1; 
	
	set @sql2 = concat('SELECT count(*) as all_show_times into @temp1 FROM (SELECT * FROM ticket_info  ORDER BY id DESC LIMIT ?,? ) valid_data WHERE 1=1 and ',cnd2);

	PREPARE statement2 from @sql2;
	EXECUTE statement2 USING @a1,@a2; 
	DEALLOCATE PREPARE statement2; 
	
	SELECT code_num,@temp0 as all_show_times,@temp1 as non_show_times,(@temp0+@temp1) as times_sum;

END

3个结果集了

自定义SqlCallback吧, 看看进入了多少次

@wendal 不是太明白,Navicat执行出来,显示的结果集就1个

自定义个SqlCallback看看嘛

好的 兽哥有参考示例吗 不怎么会写SqlCallback

sql.setCallback

添加回复
请先登陆
回到顶部