第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

dao和items不清楚

我想知道dao和items里面代碼怎么寫(xiě)的,要不無(wú)從下手,求dao和items的代碼

正在回答

2 回答

package?entity;

//商品類(lèi)
public?class?Items?{

	private?int?id;?//?商品編號(hào)
	private?String?name;?//?商品名稱(chēng)
	private?String?city;?//?產(chǎn)地
	private?int?price;?//?價(jià)格
	private?int?number;?//?庫(kù)存
	private?String?picture;?//?商品圖片

	//保留此不帶參數(shù)的構(gòu)造方法
	public?Items()
	{
		
	}
	
	public?Items(int?id,String?name,String?city,int?price,int?number,String?picture)
	{
		this.id?=?id;
		this.name?=?name;
		this.city?=?city;
		this.picture?=?picture;
		this.price?=?price;
		this.number?=?number;
		
	}
	public?int?getId()?{
		return?id;
	}

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

	public?String?getName()?{
		return?name;
	}

	public?void?setName(String?name)?{
		this.name?=?name;
	}

	public?String?getCity()?{
		return?city;
	}

	public?void?setCity(String?city)?{
		this.city?=?city;
	}

	public?int?getPrice()?{
		return?price;
	}

	public?void?setPrice(int?price)?{
		this.price?=?price;
	}

	public?int?getNumber()?{
		return?number;
	}

	public?void?setNumber(int?number)?{
		this.number?=?number;
	}

	public?String?getPicture()?{
		return?picture;
	}

	public?void?setPicture(String?picture)?{
		this.picture?=?picture;
	}
	
	
	
	@Override
	public?int?hashCode()?{
		//?TODO?Auto-generated?method?stub
		return?this.getId()+this.getName().hashCode();
	}

	@Override
	public?boolean?equals(Object?obj)?{
		//?TODO?Auto-generated?method?stub
		if(this==obj)
		{
			return?true;
		}
		if(obj?instanceof?Items)
		{
			Items?i?=?(Items)obj;
			if(this.getId()==i.getId()&&this.getName().equals(i.getName()))
			{
				return?true;
			}
			else
			{
				return?false;
			}
		}
		else
		{
			return?false;
		}
	}

	public?String?toString()
	{
		return?"商品編號(hào):"+this.getId()+",商品名稱(chēng):"+this.getName();
	}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

package dao;


import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.ArrayList;


import util.DBHelper;


import entity.Items;


//商品的業(yè)務(wù)邏輯類(lèi)

public class ItemsDAO {


// 獲得所有的商品信息

public ArrayList<Items> getAllItems() {

Connection conn = null;

PreparedStatement stmt = null;

ResultSet rs = null;

ArrayList<Items> list = new ArrayList<Items>(); // 商品集合

try {

conn = DBHelper.getConnection();

String sql = "select * from items;"; // SQL語(yǔ)句

stmt = conn.prepareStatement(sql);

rs = stmt.executeQuery();

while (rs.next()) {

Items item = new Items();

item.setId(rs.getInt("id"));

item.setName(rs.getString("name"));

item.setCity(rs.getString("city"));

item.setNumber(rs.getInt("number"));

item.setPrice(rs.getInt("price"));

item.setPicture(rs.getString("picture"));

list.add(item);// 把一個(gè)商品加入集合

}

return list; // 返回集合。

} catch (Exception ex) {

ex.printStackTrace();

return null;

} finally {

// 釋放數(shù)據(jù)集對(duì)象

if (rs != null) {

try {

rs.close();

rs = null;

} catch (Exception ex) {

ex.printStackTrace();

}

}

// 釋放語(yǔ)句對(duì)象

if (stmt != null) {

try {

stmt.close();

stmt = null;

} catch (Exception ex) {

ex.printStackTrace();

}

}

}


}


// 根據(jù)商品編號(hào)獲得商品資料

public Items getItemsById(int id) {

Connection conn = null;

PreparedStatement stmt = null;

ResultSet rs = null;

try {

conn = DBHelper.getConnection();

String sql = "select * from items where id=?;"; // SQL語(yǔ)句

stmt = conn.prepareStatement(sql);

stmt.setInt(1, id);

rs = stmt.executeQuery();

if (rs.next()) {

Items item = new Items();

item.setId(rs.getInt("id"));

item.setName(rs.getString("name"));

item.setCity(rs.getString("city"));

item.setNumber(rs.getInt("number"));

item.setPrice(rs.getInt("price"));

item.setPicture(rs.getString("picture"));

return item;

} else {

return null;

}


} catch (Exception ex) {

ex.printStackTrace();

return null;

} finally {

// 釋放數(shù)據(jù)集對(duì)象

if (rs != null) {

try {

rs.close();

rs = null;

} catch (Exception ex) {

ex.printStackTrace();

}

}

// 釋放語(yǔ)句對(duì)象

if (stmt != null) {

try {

stmt.close();

stmt = null;

} catch (Exception ex) {

ex.printStackTrace();

}

}


}

}

//獲取最近瀏覽的前五條商品信息

public ArrayList<Items> getViewList(String list)

{

System.out.println("list:"+list);

ArrayList<Items> itemlist = new ArrayList<Items>();

int iCount=5; //每次返回前五條記錄

if(list!=null&&list.length()>0)

{

? ?String[] arr = list.split(",");

? ?System.out.println("arr.length="+arr.length);

? ?//如果商品記錄大于等于5條

? ?if(arr.length>=5)

? ?{

? ? ? for(int i=arr.length-1;i>=arr.length-iCount;i--)

? ? ? {


? ? ?itemlist.add(getItemsById(Integer.parseInt(arr[i]))); ?

? ? ? }

? ?}

? ?else

? ?{

? ? for(int i=arr.length-1;i>=0;i--)

? ? {

? ? itemlist.add(getItemsById(Integer.parseInt(arr[i])));

? ? }

? ?}

? ?return itemlist;

}

else

{

return null;

}

}


}


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)