mybatis查询数据库返回多条数据

JavaBean:

public class ExpressMessage {
	private int id = 0;// 快递单编号
	private String sendName = null;// 发件人姓名
	private String sendTelephone = null;// 发件人电话
	private String sendCompary = null;// 发件人公司
	private String sendAddress = null;// 发件人地址
	private String sendPostcode = null;// 发送人邮编
	private String receiveName = null;// 收件人名称
	private String receiveTelephone = null;// 收件人电话
	private String receiveCompary = null;// 收件人公司
	private String receiveAddress = null;// 收件人地址
	private String receivePostcode = null;// 收件人邮编
	private String ControlPosition = null; // 快递单上添加信息的组件位置(坐标)
	private String expressSize = null; // 快递单的尺寸(大小)

	public ExpressMessage() {
		super();
	}

	public ExpressMessage(int id, String sendName, String sendTelephone, String sendCompary, String sendAddress,
			String sendPostcode, String receiveName, String receiveTelephone, String receiveCompary,
			String receiveAddress, String receivePostcode, String ControlPosition, String expressSize) {
		super();
		this.id=id;
		this.sendName=sendName;
		this.sendTelephone=sendTelephone;
		this.sendCompary=sendCompary;
		this.sendAddress=sendAddress;
		this.sendPostcode=sendPostcode;
		this.receiveName=receiveName;
		this.receiveTelephone=receiveTelephone;
		this.receiveCompary=receiveCompary;
		this.receiveAddress=receiveAddress;
		this.receivePostcode=receivePostcode;
		this.ControlPosition=ControlPosition;
		this.expressSize=expressSize;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getSendName() {
		return sendName;
	}

	public void setSendName(String sendName) {
		this.sendName = sendName;
	}

	public String getSendTelephone() {
		return sendTelephone;
	}

	public void setSendTelephone(String sendTelephone) {
		this.sendTelephone = sendTelephone;
	}

	public String getSendCompary() {
		return sendCompary;
	}

	public void setSendCompary(String sendCompary) {
		this.sendCompary = sendCompary;
	}

	public String getSendAddress() {
		return sendAddress;
	}

	public void setSendAddress(String sendAddress) {
		this.sendAddress = sendAddress;
	}

	public String getSendPostcode() {
		return sendPostcode;
	}

	public void setSendPostcode(String sendPostcode) {
		this.sendPostcode = sendPostcode;
	}

	public String getReceiveName() {
		return receiveName;
	}

	public void setReceiveName(String receiveName) {
		this.receiveName = receiveName;
	}

	public String getReceiveTelephone() {
		return receiveTelephone;
	}

	public void setReceiveTelephone(String recieveTelephone) {
		this.receiveTelephone = recieveTelephone;
	}

	public String getReceiveCompary() {
		return receiveCompary;
	}

	public void setReceiveCompary(String recieveCompary) {
		this.receiveCompary = recieveCompary;
	}

	public String getReceiveAddress() {
		return receiveAddress;
	}

	public void setReceiveAddress(String receiveAddress) {
		this.receiveAddress = receiveAddress;
	}

	public String getReceivePostcode() {
		return receivePostcode;
	}

	public void setReceivePostcode(String receivePostcode) {
		this.receivePostcode = receivePostcode;
	}

	public String getControlPosition() {
		return ControlPosition;
	}

	public void setControlPosition(String controlPosition) {
		ControlPosition = controlPosition;
	}

	public String getExpressSize() {
		return expressSize;
	}

	public void setExpressSize(String expressSize) {
		this.expressSize = expressSize;
	}
	@Override
	public String toString() {
		return "ExpressMessaage [id=" + id + ", sendName=" + sendName + ", sendTelephone=" + sendTelephone + "]";
	}
}

EmployeeMapper:

public Vector<ExpressMessage> queryAllExpress();//这个是重点,返回值一定要写好!!!

EmployeeMapper.xml

<select id="queryAllExpress" resultType="com.zzk.bean.ExpressMessage">
		select
	id,sendName,sendTelephone,sendCompary,sendAddress,sendPostcode,receiveName,recieveTelephone,recieveCompary,receiveAddress,receivePostcode,ControlPosition,expressSize
		from tb_receiveSendMessage
	</select>

应用:

public SqlSessionFactory getSqlSessionFactory() throws IOException {
		String resource = "mybatis-config.xml";
		InputStream inputStream = Resources.getResourceAsStream(resource);
		return new SqlSessionFactoryBuilder().build(inputStream);
	}

	public Vector queryAllExpress() throws IOException {

		SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
		// 1、获取到的SqlSession不会自动提交数据
		SqlSession openSession = sqlSessionFactory.openSession();
		try {
			EmployeeMapper mapper = openSession.getMapper(EmployeeMapper.class);
			// Vector<ExpressMessage> v = new Vector<ExpressMessage>();// 创建动态数组
			ExpressMessage m = new ExpressMessage();
			Vector<ExpressMessage> v = mapper.queryAllExpress();
			System.out.println(v);
			// System.out.println(employee);
			return v;
		} finally {
			openSession.close();
		}
	}

参考链接:
参考博文1
参考博文2
参考博文3
参考博文4
真的就是面向CSDN编程。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值