Skip to content

Commit

Permalink
前端页面整合初步完成,接下来进行展示工作
Browse files Browse the repository at this point in the history
  • Loading branch information
Dodozhou committed Dec 17, 2016
1 parent f14e221 commit 8862268
Show file tree
Hide file tree
Showing 93 changed files with 4,236 additions and 11,122 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/star/estore/dao/ProductDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.star.estore.domain.Order;
import com.star.estore.domain.OrderItem;
import com.star.estore.domain.Product;
import com.star.estore.domain.User;
import com.star.estore.utils.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
Expand All @@ -17,9 +18,10 @@
public class ProductDao {
public void addProduct(Product p) throws SQLException {
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "insert into products values(?,?,?,?,?,?,?)";
String sql = "insert into products values(?,?,?,?,?,?,?,?,?,?,?,?)";
runner.update(sql,p.getId(),p.getName(),p.getPrice(),p.getCategory(),
p.getPnum(),p.getImgurl(),p.getDescription());
p.getPnum(),p.getImgurl(),p.getDescription(),p.getDealps(),
p.isDiscount(),p.getQQ(),p.getPhone(), p.getOwner());
}

public List<Product> findAll() throws SQLException {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/star/estore/dao/PurchaseDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.star.estore.dao;

import com.star.estore.domain.Purchase;
import com.star.estore.utils.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
* Created by hp on 2016/12/16.
*/
public class PurchaseDao {

public void add(Purchase p) throws SQLException {
QueryRunner runner=new QueryRunner(DataSourceUtils.getDataSource());
String sql="insert into purchase values(null,?,?,?,?,?,?,?,?)";
runner.update(sql,p.getName(),p.getDescription(),p.getDealps(),p.getPrice(),
p.getCategory(),p.getOwner(),p.getQQ(),p.getPhone());
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/star/estore/dao/UserDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@ public User findUserByActiveCode(String activecode) throws SQLException {
String sql = "select * from users where activecode=?";
return runner.query(sql,new BeanHandler<User>(User.class),activecode);
}

public User findUserById(int id) {
QueryRunner runner=new QueryRunner(DataSourceUtils.getDataSource());
String sql="select * from users where id=?";
User user=null;
try {
user=runner.query(sql,new BeanHandler<User>(User.class),id);
} catch (SQLException e) {
System.out.println("根据id查找用户失败,可能是id不存在");
e.printStackTrace();
}
return user;
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/star/estore/domain/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,52 @@ public class Product implements Serializable {
// 在获取销售榜单信息时使用
private int totalSaleNum; // 总销售数量

private String dealps;
private boolean discount;
private String QQ;
private String phone;
private int owner;

public int getOwner() {
return owner;
}

public void setOwner(int owner) {
this.owner = owner;
}

public String getDealps() {
return dealps;
}

public void setDealps(String dealps) {
this.dealps = dealps;
}

public boolean isDiscount() {
return discount;
}

public void setDiscount(boolean discount) {
this.discount = discount;
}

public String getQQ() {
return QQ;
}

public void setQQ(String QQ) {
this.QQ = QQ;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getId() {
return id;
}
Expand Down
90 changes: 90 additions & 0 deletions src/main/java/com/star/estore/domain/Purchase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.star.estore.domain;

/**
* Created by hp on 2016/12/16.
*/
public class Purchase {
private int id;//求购物品的编号
private String name;//求购物品名称
private String description;//求购物品描述
private String dealps;//交易地点
private int price;//期望价格
private String category;//求购物品的类别,方便查询
private int owner;//求购信息发布者
private String QQ;//联系方式
private String phone;

public String getQQ() {
return QQ;
}

public void setQQ(String QQ) {
this.QQ = QQ;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

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 getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getDealps() {
return dealps;
}

public void setDealps(String dealps) {
this.dealps = dealps;
}

public int getPrice() {
return price;
}

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

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public int getOwner() {
return owner;
}

public void setOwner(int owner) {
this.owner = owner;
}


}
18 changes: 18 additions & 0 deletions src/main/java/com/star/estore/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ public class User {
private int state; // 是否激活
private String activecode; // 激活码 UUID获取
private Timestamp updatetime; // 更新时间
private String QQ;
private String phone;

public String getQQ() {
return QQ;
}

public void setQQ(String QQ) {
this.QQ = QQ;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public int getId() {
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ProductServiceImpl implements ProductService{
@Override
public void add(User user, Product product) throws PrivilegeException, Exception {
ProductDao dao = new ProductDao();
product.setOwner(user.getId());
dao.addProduct(product);
}
//查找所有商品
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/star/estore/service/PurchaseService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.star.estore.service;

import com.star.estore.annotation.PrivilegeInfo;
import com.star.estore.domain.Product;
import com.star.estore.domain.Purchase;
import com.star.estore.domain.User;
import com.star.estore.exception.PrivilegeException;

import java.util.List;

/**
* Created by hp on 2016/12/4.
*/
public interface PurchaseService {
//添加求购
public void add(User user, Purchase purchase) throws Exception;

//查找求购信息
public List<Product> findAll() throws Exception;

//根据关键字查找求购信息
public Product findByInfo(String keyword) throws Exception;

}
33 changes: 33 additions & 0 deletions src/main/java/com/star/estore/service/PurchaseServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.star.estore.service;

import com.star.estore.dao.ProductDao;
import com.star.estore.dao.PurchaseDao;
import com.star.estore.domain.Product;
import com.star.estore.domain.Purchase;
import com.star.estore.domain.User;
import com.star.estore.exception.PrivilegeException;

import java.util.List;

/**
* Created by hp on 2016/12/4.
*/
public class PurchaseServiceImpl implements PurchaseService{

@Override
public void add(User user, Purchase purchase) throws Exception {
PurchaseDao dao = new PurchaseDao();
purchase.setOwner(user.getId());
dao.add(purchase);
}

@Override
public List<Product> findAll() throws Exception {
return null;
}

@Override
public Product findByInfo(String keyword) throws Exception {
return null;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/star/estore/web/AddProductServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
User user = (User) request.getSession().getAttribute("user");
try {
service.add(user,product);
response.sendRedirect(request.getContextPath()+"/index.jsp");
response.sendRedirect(request.getContextPath()+"/publish.jsp");
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/star/estore/web/filter/AutoLoginFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void doFilter(ServletRequest request, ServletResponse response,
String contextPath = req.getContextPath();
String path = uri.substring(contextPath.length());

if (!("/regist.jsp".equalsIgnoreCase(path)
|| "/login".equalsIgnoreCase(path) || "/regist"
if (!("/page.jsp".equalsIgnoreCase(path)
|| "/login".equalsIgnoreCase(path) || "/page"
.equalsIgnoreCase(path))) {
// 符合条件的是可以进行自动登录操作的.

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/star/estore/web/servlet/ProductServlet.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.star.estore.web.servlet;

import com.google.gson.Gson;
import com.star.estore.dao.UserDao;
import com.star.estore.domain.Product;
import com.star.estore.domain.User;
import com.star.estore.factory.ProductServiceFactory;
import com.star.estore.service.ProductService;
import com.star.estore.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
Expand Down Expand Up @@ -38,10 +41,17 @@ public void findById(HttpServletRequest request,
try {
ProductService service = ProductServiceFactory.getInstance();
Product p = service.findById(id);

int owner_id=p.getOwner();
UserDao dao=new UserDao();
User owner=dao.findUserById(owner_id);
if (owner==null){
response.getWriter().write("非常抱歉,根据id查找该商品的拥有者失败!");
return;
}
request.setAttribute("p", p);
request.setAttribute("owner",owner);

request.getRequestDispatcher("/productInfo.jsp").forward(request,
request.getRequestDispatcher("/goods_details.jsp").forward(request,
response);

} catch (SQLException e) {
Expand Down
Loading

0 comments on commit 8862268

Please sign in to comment.