• 大小: 2.3MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-09
  • 语言: Java
  • 标签:

资源简介

商品购物车模块的开发,java web,mysql数据库,mvc思想,有工程说明 代码详细地址:https://blog.csdn.net/qq_36631076/article/details/80401975

资源截图

代码片段和文件信息

package com.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import com.model.Good;
import com.mysql.jdbc.PreparedStatement;
import com.util.DBHelper;

/*
 * 2018.4.16
 * 业务逻辑类:用于操纵数据库
 */
public class GoodDao {


//获取所有的商品信息
public ArrayList getAllGoods() 
{
Connection conn=null;
PreparedStatement prep=null;
ResultSet rs=null;
ArrayList result=new ArrayList();

try {
conn=DBHelper.getConnection();
String sql=“select * from good“;
prep=(PreparedStatement) conn.prepareStatement(sql);
rs=prep.executeQuery();

while(rs.next())
{
Good good=new Good();
good.setId(rs.getInt(“id“));
good.setName(rs.getString(“name“));
good.setPrice(rs.getDouble(“price“));
good.setInfor(rs.getString(“infor“));
good.setImage(rs.getString(“image“));
result.add(good);
}
return result;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

//根据商品的id获取数据
public Good getGoodById(int id){
Connection conn=null;
PreparedStatement prep=null;
ResultSet rs=null;
Good good=new Good();

try {
conn=DBHelper.getConnection();
String sql=“select * from good where id=?“;
prep=(PreparedStatement) conn.prepareStatement(sql);
prep.setInt(1 id);
rs=prep.executeQuery();

if(rs.next())
{
good.setId(rs.getInt(“id“));
good.setName(rs.getString(“name“));
good.setPrice(rs.getDouble(“price“));
good.setInfor(rs.getString(“infor“));
good.setImage(rs.getString(“image“));
}
return good;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

//获取最近浏览的前五条商品信息
public ArrayList getViewList(String list)
{
//在控制台输出一下我们的list:测试用
System.out.println(“list:“+list);

//返回的结果集
ArrayList itemlist = new ArrayList();

//每次返回前五条记录
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--)
       {
        System.out.println(“当前list的数字:“+arr[i]);
        itemlist.add(getGoodById(Integer.parseInt(arr[i])));  
       }
    }
    else
    {
     for(int i=arr.length-1;i>=0;i--)
     {
     System.out.println(“当前list的数字:“+arr[i]);
     itemlist.add(getGoodById(Integer.parseInt(arr[i])));
     }
    }
    return itemlist;
}
else
{
return null;
}

}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        1093  2018-04-27 15:39  ServletShoppingDemo\.classpath
     文件        1069  2018-04-27 15:39  ServletShoppingDemo\.project
     文件         564  2018-04-27 15:39  ServletShoppingDemo\.settings\.jsdtscope
     文件         364  2018-04-27 15:39  ServletShoppingDemo\.settings\org.eclipse.jdt.core.prefs
     文件         516  2018-04-27 15:39  ServletShoppingDemo\.settings\org.eclipse.wst.common.component
     文件         414  2018-04-27 15:39  ServletShoppingDemo\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2018-04-27 15:39  ServletShoppingDemo\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2018-04-27 15:39  ServletShoppingDemo\.settings\org.eclipse.wst.jsdt.ui.superType.name
     文件        1910  2018-04-27 17:41  ServletShoppingDemo\WebRoot\Good.sql
     文件          39  2018-04-27 15:39  ServletShoppingDemo\WebRoot\meta-INF\MANIFEST.MF
     文件        3616  2018-05-22 08:27  ServletShoppingDemo\WebRoot\WEB-INF\classes\com\dao\GoodDao.class
     文件        2420  2018-05-22 08:27  ServletShoppingDemo\WebRoot\WEB-INF\classes\com\model\Cart.class
     文件        2054  2018-05-22 08:27  ServletShoppingDemo\WebRoot\WEB-INF\classes\com\model\Good.class
     文件        1276  2018-05-22 08:27  ServletShoppingDemo\WebRoot\WEB-INF\classes\com\servlet\CartServlet.class
     文件        1255  2018-05-22 08:31  ServletShoppingDemo\WebRoot\WEB-INF\classes\com\util\DBHelper.class
     文件     1004840  2018-04-16 15:29  ServletShoppingDemo\WebRoot\WEB-INF\lib\mysql-connector-java-5.1.46-bin.jar
     文件     1004838  2018-04-16 15:29  ServletShoppingDemo\WebRoot\WEB-INF\lib\mysql-connector-java-5.1.46.jar
     文件        1292  2018-05-22 08:51  ServletShoppingDemo\WebRoot\addGood.jsp
     文件          49  2018-04-16 09:03  ServletShoppingDemo\WebRoot\blank.gif
     文件        3456  2018-05-22 10:33  ServletShoppingDemo\WebRoot\cart.jsp
     文件       13341  2018-05-21 09:41  ServletShoppingDemo\WebRoot\details.jsp
     文件         926  2018-05-21 09:35  ServletShoppingDemo\WebRoot\detlete.jsp
     文件          42  2018-04-16 09:03  ServletShoppingDemo\WebRoot\iecss.css
     文件        1804  2018-04-16 09:03  ServletShoppingDemo\WebRoot\iepngfix.htc
     文件        6529  2018-04-16 08:56  ServletShoppingDemo\WebRoot\images\1.gif
     文件        3835  2018-04-16 08:56  ServletShoppingDemo\WebRoot\images\2.gif
     文件        6052  2018-04-16 08:56  ServletShoppingDemo\WebRoot\images\3.gif
     文件       21361  2018-04-16 15:50  ServletShoppingDemo\WebRoot\images\4.jpg
     文件       24972  2018-04-16 15:50  ServletShoppingDemo\WebRoot\images\5.jpg
     文件       23445  2018-04-16 15:50  ServletShoppingDemo\WebRoot\images\6.jpg
     文件      122368  2018-04-16 08:56  ServletShoppingDemo\WebRoot\images\Thumbs.db
............此处省略70个文件信息

评论

共有 条评论