最后更新
This commit is contained in:
		@@ -1,26 +1,127 @@
 | 
			
		||||
package com.qf.controller;
 | 
			
		||||
 | 
			
		||||
import com.qf.service.CartService;
 | 
			
		||||
import com.qf.service.impl.CartServiceImpl;
 | 
			
		||||
import com.qf.entity.Address;
 | 
			
		||||
import com.qf.entity.User;
 | 
			
		||||
import com.qf.service.AddressService;
 | 
			
		||||
import com.qf.service.impl.AddressServiceImpl;
 | 
			
		||||
import com.qf.utils.Constants;
 | 
			
		||||
import org.apache.commons.beanutils.BeanUtils;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.annotation.WebServlet;
 | 
			
		||||
import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
import javax.servlet.http.HttpSession;
 | 
			
		||||
import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
@WebServlet("/address")
 | 
			
		||||
public class AddressController extends BaseServlet {
 | 
			
		||||
 | 
			
		||||
    public String show(HttpServletRequest request, HttpServletResponse response){
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.查看收货地址
 | 
			
		||||
     */
 | 
			
		||||
    public String show(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
        //1.判断用户是否登录
 | 
			
		||||
        HttpSession session = request.getSession();
 | 
			
		||||
        //获取session中的用户信息
 | 
			
		||||
        User user = (User) session.getAttribute("loginUser");
 | 
			
		||||
        if (user == null) {
 | 
			
		||||
            session.setAttribute("msg", "查看地址必须先登录!");
 | 
			
		||||
            return Constants.FORWARD + "/login.jsp";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //1.获取请求参数
 | 
			
		||||
        //2.获取请求参数
 | 
			
		||||
        int uid = user.getUid();
 | 
			
		||||
 | 
			
		||||
        //2.调用对应的业务逻辑   清空购物车
 | 
			
		||||
        //3.调用对应的业务逻辑
 | 
			
		||||
        AddressService addressService = new AddressServiceImpl();
 | 
			
		||||
        List<Address> addresses = addressService.findAddressByUid(uid);
 | 
			
		||||
 | 
			
		||||
        //3.转发到展示方法中
 | 
			
		||||
        return Constants.FORWARD + "/cart?method=show";
 | 
			
		||||
        //4.将获取到的地址信息转发到共享域中
 | 
			
		||||
        request.setAttribute("list", addresses);
 | 
			
		||||
 | 
			
		||||
        //5.转发到展示方法中
 | 
			
		||||
        return Constants.FORWARD + "/self_info.jsp";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.新增收货地址
 | 
			
		||||
     */
 | 
			
		||||
    public String add(HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException, SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.获取输入的地址信息
 | 
			
		||||
        Map<String, String[]> map = request.getParameterMap();
 | 
			
		||||
 | 
			
		||||
        Address address = new Address();
 | 
			
		||||
        BeanUtils.populate(address, map);
 | 
			
		||||
 | 
			
		||||
        //2.调用业务逻辑进行地址的添加
 | 
			
		||||
        AddressService addressService = new AddressServiceImpl();
 | 
			
		||||
        addressService.saveAddress(address);
 | 
			
		||||
 | 
			
		||||
        //3.转发到展示方法中,重新加载数据
 | 
			
		||||
        return Constants.FORWARD + "/address?method=show";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 3.设置默认收货地址
 | 
			
		||||
     */
 | 
			
		||||
    public String setDefault(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.获取请求参数
 | 
			
		||||
        String aid = request.getParameter("aid");
 | 
			
		||||
 | 
			
		||||
        //2.获取用户uid
 | 
			
		||||
        HttpSession session = request.getSession();
 | 
			
		||||
        User user = (User) session.getAttribute("loginUser");
 | 
			
		||||
        int uid = user.getUid();
 | 
			
		||||
 | 
			
		||||
        //3.调用业务逻辑进行地址修改
 | 
			
		||||
        AddressService addressService = new AddressServiceImpl();
 | 
			
		||||
        addressService.setAddressToDefault(aid, uid);
 | 
			
		||||
 | 
			
		||||
        //4.转发到展示方法
 | 
			
		||||
        return Constants.FORWARD + "/address?method=show";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 4.删除收货地址
 | 
			
		||||
     */
 | 
			
		||||
    public String delete(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.获取请求参数
 | 
			
		||||
        String aid = request.getParameter("aid");
 | 
			
		||||
 | 
			
		||||
        //2.调用业务逻辑进行地址添加
 | 
			
		||||
        AddressService addressService = new AddressServiceImpl();
 | 
			
		||||
        addressService.deleteAddressByAid(aid);
 | 
			
		||||
 | 
			
		||||
        //3.转发到展示方法
 | 
			
		||||
        return Constants.FORWARD + "/address?method=show";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 5.修改收货地址
 | 
			
		||||
     */
 | 
			
		||||
    public String update(HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException, SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.获取修改的数据
 | 
			
		||||
        Map<String, String[]> map = request.getParameterMap();
 | 
			
		||||
 | 
			
		||||
        //转换为 Address 类型方便传输
 | 
			
		||||
        Address address = new Address();
 | 
			
		||||
        BeanUtils.populate(address, map);
 | 
			
		||||
 | 
			
		||||
        //2.调用业务逻辑进行地址修改
 | 
			
		||||
        AddressService addressService = new AddressServiceImpl();
 | 
			
		||||
        addressService.updateByAid(address);
 | 
			
		||||
 | 
			
		||||
        //3.转发到展示方法
 | 
			
		||||
        return Constants.FORWARD + "/address?method=show";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,20 +10,20 @@ import java.io.IOException;
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
 | 
			
		||||
public class BaseServlet extends HttpServlet {
 | 
			
		||||
    //重写service方法,来处理反射的业务逻辑
 | 
			
		||||
    /**
 | 
			
		||||
     * 重写service方法,来处理反射的业务逻辑
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
 | 
			
		||||
        req.setCharacterEncoding("utf-8");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        //1.获取请求参数(标识符)
 | 
			
		||||
        String  methodStr =req.getParameter(Constants.TAG);
 | 
			
		||||
        //我们在这做一个处理。2.如果method没有获取到值!我们就跳转到首页!(标识符异常处理)
 | 
			
		||||
        //2.如果method没有获取到值  就跳转到首页 (标识符异常处理)
 | 
			
		||||
        if (methodStr==null&& methodStr.equals("")){
 | 
			
		||||
            methodStr= Constants.INDEX;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        //3.反射调用对应的业务逻辑方法
 | 
			
		||||
        Class clazz=this.getClass();
 | 
			
		||||
        try {
 | 
			
		||||
 
 | 
			
		||||
@@ -14,11 +14,15 @@ import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
@WebServlet("/cart")
 | 
			
		||||
 | 
			
		||||
public class CartController extends BaseServlet {
 | 
			
		||||
 | 
			
		||||
    //加入购物车
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.加入购物车
 | 
			
		||||
     */
 | 
			
		||||
    public String create(HttpServletRequest request, HttpServletResponse response) throws SQLException, InvocationTargetException, IllegalAccessException {
 | 
			
		||||
 | 
			
		||||
        //1.判断用户是否登录,没有登录跳转到登录页面
 | 
			
		||||
@@ -43,7 +47,9 @@ public class CartController extends BaseServlet {
 | 
			
		||||
        return Constants.FORWARD + "/cartSuccess.jsp";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //查看购物车
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.查看购物车
 | 
			
		||||
     */
 | 
			
		||||
    public String show(HttpServletRequest request, HttpServletResponse response) throws SQLException, InvocationTargetException, IllegalAccessException {
 | 
			
		||||
        //1.判断用户是否登录
 | 
			
		||||
        HttpSession session = request.getSession();
 | 
			
		||||
@@ -68,7 +74,9 @@ public class CartController extends BaseServlet {
 | 
			
		||||
        return Constants.FORWARD + "/cart.jsp";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //购物车中删除物品
 | 
			
		||||
    /**
 | 
			
		||||
     * 3.购物车中删除物品
 | 
			
		||||
     */
 | 
			
		||||
    public String delete(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.获取请求参数
 | 
			
		||||
@@ -82,7 +90,9 @@ public class CartController extends BaseServlet {
 | 
			
		||||
        return Constants.FORWARD + "/cart?method=show";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //购物车中数量更改
 | 
			
		||||
    /**
 | 
			
		||||
     * 4.购物车中数量更改
 | 
			
		||||
     */
 | 
			
		||||
    public String update(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.获取请求参数      cid     商品单价price       商品修改后数量cnum
 | 
			
		||||
@@ -98,7 +108,9 @@ public class CartController extends BaseServlet {
 | 
			
		||||
        return Constants.FORWARD + "/cart?method=show";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //清空购物车
 | 
			
		||||
    /**
 | 
			
		||||
     * 5.清空购物车
 | 
			
		||||
     */
 | 
			
		||||
    public String clear(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.获取请求参数
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,9 @@ import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
@WebServlet("/code")
 | 
			
		||||
public class CodeController extends BaseServlet {
 | 
			
		||||
    public void createCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,8 +11,20 @@ import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
@WebServlet("/product")
 | 
			
		||||
public class ProductController extends BaseServlet {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.商品分页展示
 | 
			
		||||
     *
 | 
			
		||||
     * @param request
 | 
			
		||||
     * @param response
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    public String show(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
        //1.获取请求参数
 | 
			
		||||
        String tid = request.getParameter("tid");
 | 
			
		||||
@@ -34,18 +46,24 @@ public class ProductController extends BaseServlet {
 | 
			
		||||
        return Constants.FORWARD + "/goodsList.jsp";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.商品详情展示
 | 
			
		||||
     *
 | 
			
		||||
     * @param request
 | 
			
		||||
     * @param response
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    public String detail(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
         //1.获取请求参数
 | 
			
		||||
        //1.获取请求参数
 | 
			
		||||
        String pid = request.getParameter("pid");
 | 
			
		||||
        //2.调用业务逻辑
 | 
			
		||||
        ProductService productService = new ProductServiceImpl();
 | 
			
		||||
        //3.声明方法
 | 
			
		||||
        Product product = productService.findProductByPid(pid);
 | 
			
		||||
        //3.响应
 | 
			
		||||
        request.setAttribute("product",product);
 | 
			
		||||
        request.setAttribute("product", product);
 | 
			
		||||
        //4.跳转到对应的商品页面
 | 
			
		||||
        return Constants.FORWARD+"/goodsDetail.jsp";
 | 
			
		||||
        return Constants.FORWARD + "/goodsDetail.jsp";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -22,8 +22,7 @@ public class TypeController extends BaseServlet {
 | 
			
		||||
 | 
			
		||||
        //2.将集合转换为 json 数据
 | 
			
		||||
        Gson gson = new Gson();
 | 
			
		||||
        String json = gson.toJson(types);
 | 
			
		||||
 | 
			
		||||
        return json;
 | 
			
		||||
        return gson.toJson(types);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,12 +3,14 @@ package com.qf.controller;
 | 
			
		||||
import com.qf.entity.User;
 | 
			
		||||
import com.qf.service.UserService;
 | 
			
		||||
import com.qf.service.impl.UserServiceImpl;
 | 
			
		||||
import com.qf.utils.Base64Utils;
 | 
			
		||||
import com.qf.utils.Constants;
 | 
			
		||||
import com.qf.utils.MD5Utils;
 | 
			
		||||
import com.qf.utils.RandomUtils;
 | 
			
		||||
import org.apache.commons.beanutils.BeanUtils;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.annotation.WebServlet;
 | 
			
		||||
import javax.servlet.http.Cookie;
 | 
			
		||||
import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
import javax.servlet.http.HttpSession;
 | 
			
		||||
@@ -16,10 +18,15 @@ import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
@WebServlet("/user")
 | 
			
		||||
public class UserController extends BaseServlet {
 | 
			
		||||
 | 
			
		||||
    //1.查询用户是否存在
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.查询用户是否存在
 | 
			
		||||
     */
 | 
			
		||||
    public String check(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
        //1.获取用户名
 | 
			
		||||
        String username = request.getParameter("username");
 | 
			
		||||
@@ -37,18 +44,17 @@ public class UserController extends BaseServlet {
 | 
			
		||||
        return "0";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //2.注册功能
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.注册功能
 | 
			
		||||
     */
 | 
			
		||||
    public String register(HttpServletRequest request, HttpServletResponse response) {
 | 
			
		||||
        //1.获取到我们的用户信息
 | 
			
		||||
        Map<String, String[]> parameterMap = request.getParameterMap();
 | 
			
		||||
        //定义一个User
 | 
			
		||||
        User user = new User();
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            BeanUtils.populate(user, parameterMap);
 | 
			
		||||
        } catch (IllegalAccessException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (InvocationTargetException e) {
 | 
			
		||||
        } catch (IllegalAccessException | InvocationTargetException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        //2.完善我们用户信息
 | 
			
		||||
@@ -71,14 +77,19 @@ public class UserController extends BaseServlet {
 | 
			
		||||
        return Constants.FORWARD + "/registerSuccess.jsp";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //3.登录功能
 | 
			
		||||
    /**
 | 
			
		||||
     * 3.登录功能
 | 
			
		||||
     */
 | 
			
		||||
    public String login(HttpServletRequest request, HttpServletResponse response) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.获取请求参数
 | 
			
		||||
        String username = request.getParameter("username");
 | 
			
		||||
        String password = request.getParameter("password");
 | 
			
		||||
 | 
			
		||||
        //用户输入的验证码
 | 
			
		||||
        String code = request.getParameter("code");
 | 
			
		||||
        //自动登录标识
 | 
			
		||||
        String auto = request.getParameter("auto");
 | 
			
		||||
 | 
			
		||||
        //2.获取正确的验证码(在session中)
 | 
			
		||||
        HttpSession session = request.getSession();
 | 
			
		||||
@@ -94,6 +105,7 @@ public class UserController extends BaseServlet {
 | 
			
		||||
        //4.调用业务逻辑判断账号密码是否正确(验证码正确的情况下)
 | 
			
		||||
        UserService userService = new UserServiceImpl();
 | 
			
		||||
        User user = userService.login(username, password);
 | 
			
		||||
 | 
			
		||||
        //5.响应
 | 
			
		||||
        if (user == null) {
 | 
			
		||||
            //错误提示
 | 
			
		||||
@@ -103,15 +115,52 @@ public class UserController extends BaseServlet {
 | 
			
		||||
        }
 | 
			
		||||
        //6.进行登录
 | 
			
		||||
        session.setAttribute("loginUser", user);
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
          自动登录
 | 
			
		||||
         */
 | 
			
		||||
        //7.判断是否勾选自动登录
 | 
			
		||||
        if (auto == null) {
 | 
			
		||||
            //将本地浏览器的cookie'清空'
 | 
			
		||||
            //创建一个cookie    常量autoUser,value里面没有值主要是一个覆盖功能
 | 
			
		||||
            Cookie cookie = new Cookie(Constants.AUTO_NAME, "");
 | 
			
		||||
            //表示当前项目下所有的访问资源servlet都可以访问这个cookie
 | 
			
		||||
            cookie.setPath("/");
 | 
			
		||||
            cookie.setMaxAge(0);
 | 
			
		||||
            //写回cookie
 | 
			
		||||
            response.addCookie(cookie);
 | 
			
		||||
        } else {
 | 
			
		||||
            //将cookie存入到本地
 | 
			
		||||
            String content = username + ":" + password;
 | 
			
		||||
            //用Base64转一下码,就无法直接看出来了
 | 
			
		||||
            content = Base64Utils.encode(content);
 | 
			
		||||
            //传入我们的账号密码
 | 
			
		||||
            Cookie cookie = new Cookie(Constants.AUTO_NAME, content);
 | 
			
		||||
            //表示当前项目下所有的访问资源servlet都可以访问这个cookie
 | 
			
		||||
            cookie.setPath("/");
 | 
			
		||||
            //两周
 | 
			
		||||
            cookie.setMaxAge(14 * 24 * 60 * 60);
 | 
			
		||||
            //写回cookie
 | 
			
		||||
            response.addCookie(cookie);
 | 
			
		||||
        }
 | 
			
		||||
        return Constants.FORWARD + "/index.jsp";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //4.注销登录
 | 
			
		||||
    /**
 | 
			
		||||
     * 4.注销登录
 | 
			
		||||
     */
 | 
			
		||||
    public String logOut(HttpServletRequest request, HttpServletResponse response) {
 | 
			
		||||
        //1.清空session中的用户数据
 | 
			
		||||
        HttpSession session = request.getSession();
 | 
			
		||||
        session.removeAttribute("loginUser");
 | 
			
		||||
        //2.提示注销并将页面转发到登录页面
 | 
			
		||||
 | 
			
		||||
        //2.清空和覆盖cookie存储的自动登录信息
 | 
			
		||||
        Cookie cookie = new Cookie(Constants.AUTO_NAME, "");
 | 
			
		||||
        cookie.setPath("/");
 | 
			
		||||
        cookie.setMaxAge(0);
 | 
			
		||||
        response.addCookie(cookie);
 | 
			
		||||
 | 
			
		||||
        //3.提示注销并将页面转发到登录页面
 | 
			
		||||
        request.setAttribute("msg", "注销登录成功!");
 | 
			
		||||
        return Constants.FORWARD + "login.jsp";
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,40 @@
 | 
			
		||||
package com.qf.dao;
 | 
			
		||||
 | 
			
		||||
import com.qf.entity.Address;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public interface AddressDao {
 | 
			
		||||
    /**
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    List<Address> selectAddressByUid(int uid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void insertAddress(Address address) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param aid
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void updateAddressToDefault(String aid, int uid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param aid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void deleteAddressByAid(String aid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void updateByAid(Address address) throws SQLException;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,19 +7,60 @@ import java.math.BigDecimal;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public interface CartDao {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @param pid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     * @throws InvocationTargetException
 | 
			
		||||
     * @throws IllegalAccessException
 | 
			
		||||
     */
 | 
			
		||||
    Cart hasCart(int uid, String pid) throws SQLException, InvocationTargetException, IllegalAccessException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param cart
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void updateCart(Cart cart) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param cart
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void insertCart(Cart cart) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     * @throws InvocationTargetException
 | 
			
		||||
     * @throws IllegalAccessException
 | 
			
		||||
     */
 | 
			
		||||
    List<Cart> selectCartByUid(int uid) throws SQLException, InvocationTargetException, IllegalAccessException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param cid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void deleteCartByCid(String cid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param count
 | 
			
		||||
     * @param cnumbig
 | 
			
		||||
     * @param cid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void updateByCid(BigDecimal count, BigDecimal cnumbig, String cid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void clearCartByUid(String uid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,10 +5,30 @@ import com.qf.entity.Product;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public interface ProductDao {
 | 
			
		||||
    /**
 | 
			
		||||
     * @param tid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    long selectCountByTid(String tid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param page
 | 
			
		||||
     * @param pageSize
 | 
			
		||||
     * @param tid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    List<Product> selectProductByPage(int page, int pageSize, String tid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param pid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    Product selectProductByPid(String pid) throws SQLException;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,14 @@ import com.qf.entity.Type;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public interface TypeDao {
 | 
			
		||||
    //需要一个方法查询数据库类别表,返回Type
 | 
			
		||||
    /**
 | 
			
		||||
     * 需要一个方法查询数据库类别表,返回Type
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    List<Type> selectAll() throws SQLException;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,12 +4,25 @@ import com.qf.entity.User;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
 | 
			
		||||
//数据库访问接口
 | 
			
		||||
/**
 | 
			
		||||
 * 数据库访问接口
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public interface UserDao {
 | 
			
		||||
    //根据用户名查询用户是否存在
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据用户名查询用户是否存在
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    User selectUserByUname(String username) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    //保存数据的方法
 | 
			
		||||
    /**
 | 
			
		||||
     * 保存数据的方法
 | 
			
		||||
     * @param user
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    int insertUser(User user) throws SQLException;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,115 @@
 | 
			
		||||
package com.qf.dao.impl;
 | 
			
		||||
 | 
			
		||||
import com.qf.dao.AddressDao;
 | 
			
		||||
import com.qf.entity.Address;
 | 
			
		||||
import com.qf.utils.C3P0Utils;
 | 
			
		||||
import org.apache.commons.dbutils.QueryRunner;
 | 
			
		||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class AddressDaoImpl implements AddressDao {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 1. 查询地址信息
 | 
			
		||||
     *
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    public List<Address> selectAddressByUid(int uid) throws SQLException {
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
 | 
			
		||||
        //2.编写sql
 | 
			
		||||
        String sql = "select a_id as aid , u_id as uid , a_name as aname ," +
 | 
			
		||||
                "a_phone as aphone , a_detail as adetail , a_state as astate " +
 | 
			
		||||
                "from address where u_id = ? ;";
 | 
			
		||||
 | 
			
		||||
        //3.执行sql
 | 
			
		||||
        return queryRunner.query(sql, new BeanListHandler<>(Address.class), uid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.插入收货地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void insertAddress(Address address) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
 | 
			
		||||
        //2.编写sql
 | 
			
		||||
        String sql = "insert into address (u_id , a_name , a_phone , a_detail , a_state) value ( ? , ? , ? , ? , ? );";
 | 
			
		||||
 | 
			
		||||
        //3.执行sql
 | 
			
		||||
        queryRunner.update(sql, address.getUid(), address.getAname(), address.getAphone(), address.getAdetail(), address.getAstate());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 3.设置默认收货地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param aid
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateAddressToDefault(String aid, int uid) throws SQLException {
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
 | 
			
		||||
        //2.编写sql
 | 
			
		||||
        String sql1 = "update address set a_state=1 where a_id = ? ";
 | 
			
		||||
        String sql2 = "update address set a_state=0 where a_id  != ? and u_id = ?;";
 | 
			
		||||
 | 
			
		||||
        //3.执行sql
 | 
			
		||||
        queryRunner.update(sql1, aid);
 | 
			
		||||
        queryRunner.update(sql2, aid, uid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 4.删除收货地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param aid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void deleteAddressByAid(String aid) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
 | 
			
		||||
        //2.编写sql
 | 
			
		||||
        String sql = "delete from address where a_id = ? ;";
 | 
			
		||||
 | 
			
		||||
        //3.执行sql
 | 
			
		||||
        queryRunner.update(sql, aid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 5.通过aid更改收货地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateByAid(Address address) throws SQLException {
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
 | 
			
		||||
        //2.编写sql
 | 
			
		||||
        String sql = "update address set a_state = ? , a_name = ? , a_phone = ? , a_detail = ? where a_id = ? ;";
 | 
			
		||||
 | 
			
		||||
        //3.执行sql
 | 
			
		||||
        queryRunner.update(sql, address.getAstate(), address.getAname(), address.getAphone(), address.getAdetail(), address.getAid());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,6 @@ import com.qf.entity.Product;
 | 
			
		||||
import com.qf.utils.C3P0Utils;
 | 
			
		||||
import org.apache.commons.beanutils.BeanUtils;
 | 
			
		||||
import org.apache.commons.dbutils.QueryRunner;
 | 
			
		||||
import org.apache.commons.dbutils.handlers.BeanHandler;
 | 
			
		||||
import org.apache.commons.dbutils.handlers.MapHandler;
 | 
			
		||||
import org.apache.commons.dbutils.handlers.MapListHandler;
 | 
			
		||||
 | 
			
		||||
@@ -17,7 +16,20 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class CartDaoImpl implements CartDao {
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.查询购物车
 | 
			
		||||
     *
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @param pid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     * @throws InvocationTargetException
 | 
			
		||||
     * @throws IllegalAccessException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public Cart hasCart(int uid, String pid) throws SQLException, InvocationTargetException, IllegalAccessException {
 | 
			
		||||
        //cart-->product 间接查询,多表查询
 | 
			
		||||
@@ -40,8 +52,6 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
//        Product product = queryRunner.query(sql, new BeanHandler<Product>(Product.class), uid, pid);
 | 
			
		||||
//        Cart cart = queryRunner.query(sql, new BeanHandler<Cart>(Cart.class), uid, pid);
 | 
			
		||||
        Product product = new Product();
 | 
			
		||||
        Cart cart = new Cart();
 | 
			
		||||
 | 
			
		||||
@@ -54,6 +64,12 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
        return cart;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.更新购物车
 | 
			
		||||
     *
 | 
			
		||||
     * @param cart
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateCart(Cart cart) throws SQLException {
 | 
			
		||||
 | 
			
		||||
@@ -67,6 +83,12 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
        queryRunner.update(sql, cart.getCnum(), cart.getCcount(), cart.getCid());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 3.加入购物车
 | 
			
		||||
     *
 | 
			
		||||
     * @param cart
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void insertCart(Cart cart) throws SQLException {
 | 
			
		||||
 | 
			
		||||
@@ -81,6 +103,15 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 4.通过uid查询购物车
 | 
			
		||||
     *
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     * @throws InvocationTargetException
 | 
			
		||||
     * @throws IllegalAccessException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Cart> selectCartByUid(int uid) throws SQLException, InvocationTargetException, IllegalAccessException {
 | 
			
		||||
 | 
			
		||||
@@ -94,7 +125,7 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
                "c.u_id as uid, c.c_count as ccount, c.c_num as cnum " +
 | 
			
		||||
                "from product p join cart c on p.p_id = c.p_id where c.u_id = ? ;";
 | 
			
		||||
 | 
			
		||||
        //3.执行sql
 | 
			
		||||
        //3.整合成为 list 集合
 | 
			
		||||
        List<Map<String, Object>> list = queryRunner.query(sql, new MapListHandler(), uid);
 | 
			
		||||
 | 
			
		||||
        //判空
 | 
			
		||||
@@ -113,7 +144,7 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
            BeanUtils.populate(cart, map);
 | 
			
		||||
            BeanUtils.populate(product, map);
 | 
			
		||||
 | 
			
		||||
            //手动将 product 关联到 Cart
 | 
			
		||||
            //将 product 关联到 Cart
 | 
			
		||||
            cart.setProduct(product);
 | 
			
		||||
            //添加数据到 carts
 | 
			
		||||
            carts.add(cart);
 | 
			
		||||
@@ -122,6 +153,12 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
        return carts;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 5.删除购物车中单项物品
 | 
			
		||||
     *
 | 
			
		||||
     * @param cid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void deleteCartByCid(String cid) throws SQLException {
 | 
			
		||||
 | 
			
		||||
@@ -135,6 +172,15 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
        queryRunner.update(sql, cid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 6.更新购物车中单项物品
 | 
			
		||||
     *
 | 
			
		||||
     * @param count
 | 
			
		||||
     * @param cnumbig
 | 
			
		||||
     * @param cid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateByCid(BigDecimal count, BigDecimal cnumbig, String cid) throws SQLException {
 | 
			
		||||
 | 
			
		||||
@@ -148,6 +194,13 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
        queryRunner.update(sql, count, cnumbig, cid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 7.清除购物车
 | 
			
		||||
     *
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void clearCartByUid(String uid) throws SQLException {
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
@@ -159,5 +212,4 @@ public class CartDaoImpl implements CartDao {
 | 
			
		||||
        //3.执行sql
 | 
			
		||||
        queryRunner.update(sql, uid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -11,51 +11,65 @@ import org.apache.commons.dbutils.handlers.ScalarHandler;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class ProductDaoImpl implements ProductDao {
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.查询
 | 
			
		||||
     *
 | 
			
		||||
     * @param tid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public long selectCountByTid(String tid) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
 | 
			
		||||
        //2.编写sql
 | 
			
		||||
        String sql = "select count(1) from product where t_id=?;";
 | 
			
		||||
        String sql = "select count(1) from product where t_id = ? ; ";
 | 
			
		||||
        Object result = queryRunner.query(sql, new ScalarHandler<>(), tid);
 | 
			
		||||
 | 
			
		||||
        Object result = queryRunner.query(sql, new ScalarHandler(), tid);
 | 
			
		||||
 | 
			
		||||
        Long total = (Long) result;
 | 
			
		||||
 | 
			
		||||
        return total;
 | 
			
		||||
        return (Long) result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param page
 | 
			
		||||
     * @param pageSize
 | 
			
		||||
     * @param tid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Product> selectProductByPage(int page, int pageSize, String tid) throws SQLException {
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
 | 
			
		||||
        //2.编写sql
 | 
			
		||||
        String sql = "select p_id as pid ,t_id as tid ,p_name as pname ,p_time as ptime ," +
 | 
			
		||||
                "p_image as pimage ,p_state as pstate ,p_info as pinfo ,p_price as pprice " +
 | 
			
		||||
                "from product where t_id=? limit ?,?;";
 | 
			
		||||
        String sql = "select p_id as pid , t_id as tid , p_name as pname , p_time as ptime , " +
 | 
			
		||||
                "p_image as pimage , p_state as pstate , p_info as pinfo , p_price as pprice " +
 | 
			
		||||
                "from product where t_id = ? limit ? , ? ;";
 | 
			
		||||
 | 
			
		||||
        //3.
 | 
			
		||||
        List<Product> list = queryRunner.query(sql, new BeanListHandler<Product>(Product.class), tid, (page - 1) * pageSize, pageSize);
 | 
			
		||||
 | 
			
		||||
        return list;
 | 
			
		||||
        return queryRunner.query(sql, new BeanListHandler<>(Product.class), tid, (page - 1) * pageSize, pageSize);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param pid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public Product selectProductByPid(String pid) throws SQLException {
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
 | 
			
		||||
        //2.编写sql
 | 
			
		||||
        String sql = "select p_id as pid ,t_id as tid ,p_name as pname ,p_time as ptime ," +
 | 
			
		||||
                "p_image as pimage ,p_state as pstate ,p_info as pinfo ,p_price as pprice " +
 | 
			
		||||
                "from product where p_id=?;";
 | 
			
		||||
        String sql = "select p_id as pid , t_id as tid , p_name as pname , p_time as ptime , " +
 | 
			
		||||
                "p_image as pimage , p_state as pstate , p_info as pinfo , p_price as pprice " +
 | 
			
		||||
                "from product where p_id = ? ; ";
 | 
			
		||||
 | 
			
		||||
        //3.
 | 
			
		||||
        Product product = queryRunner.query(sql,new BeanHandler<Product>(Product.class),pid);
 | 
			
		||||
 | 
			
		||||
        return product;
 | 
			
		||||
        return queryRunner.query(sql, new BeanHandler<>(Product.class), pid);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,14 @@ import org.apache.commons.dbutils.handlers.BeanListHandler;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class TypeDaoImpl implements TypeDao {
 | 
			
		||||
    /**
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Type> selectAll() throws SQLException {
 | 
			
		||||
        //1.创建 QueryRunner对象
 | 
			
		||||
@@ -19,8 +26,6 @@ public class TypeDaoImpl implements TypeDao {
 | 
			
		||||
        String sql = "select t_id as tid ,t_name as tname ,t_info as tinfo from type limit 5;";
 | 
			
		||||
 | 
			
		||||
        //3.执行sql语句
 | 
			
		||||
        List<Type> list = queryRunner.query(sql, new BeanListHandler<Type>(Type.class));
 | 
			
		||||
 | 
			
		||||
        return list;
 | 
			
		||||
        return queryRunner.query(sql, new BeanListHandler<>(Type.class));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,36 +6,47 @@ import com.qf.utils.C3P0Utils;
 | 
			
		||||
import org.apache.commons.dbutils.QueryRunner;
 | 
			
		||||
import org.apache.commons.dbutils.handlers.BeanHandler;
 | 
			
		||||
 | 
			
		||||
import javax.management.Query;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class UserDaoImpl implements UserDao {
 | 
			
		||||
    //根据用户名查询用户是否存在
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.根据用户名查询用户是否存在
 | 
			
		||||
     *
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public User selectUserByUname(String username) throws SQLException {
 | 
			
		||||
        //1.创建一个QueryRunner 对象,传入我们对应的连接池
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
        //2.编写sql语句完成查询操作
 | 
			
		||||
        String sql = "select u_id as uid ,u_name as username , u_password as upassword ," +
 | 
			
		||||
                "u_sex as usex ,u_status as ustatus ,u_code as code, u_email as email ," +
 | 
			
		||||
                "u_role as urole from user where u_name=?;";
 | 
			
		||||
        String sql = "select u_id as uid , u_name as username , u_password as upassword , " +
 | 
			
		||||
                "u_sex as usex , u_status as ustatus , u_code as code , u_email as email , " +
 | 
			
		||||
                "u_role as urole from user where u_name = ? ; ";
 | 
			
		||||
        //3.执行sql
 | 
			
		||||
        User user = queryRunner.query(sql, new BeanHandler<User>(User.class), username);
 | 
			
		||||
        return user;
 | 
			
		||||
        return queryRunner.query(sql, new BeanHandler<>(User.class), username);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //保存数据的方法
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.保存数据的方法
 | 
			
		||||
     *
 | 
			
		||||
     * @param user
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public int insertUser(User user) throws SQLException {
 | 
			
		||||
        //1.创建一个QueryRunner对象,传入我们对应的连接池
 | 
			
		||||
        QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
 | 
			
		||||
 | 
			
		||||
        //2.编写sql
 | 
			
		||||
        String sql = "insert into user(u_name ,u_password,u_sex,u_status, " +
 | 
			
		||||
                "u_code ,u_email,u_role) value(?,?,?,?,?,?,?);";
 | 
			
		||||
        String sql = "insert into user( u_name , u_password , u_sex , u_status , " +
 | 
			
		||||
                "u_code , u_email , u_role ) value ( ? , ? , ? , ? , ? , ? , ? ) ; ";
 | 
			
		||||
        //执行sql
 | 
			
		||||
        int rows = queryRunner.update(sql, user.getUsername(), user.getUpassword(), user.getUsex(),
 | 
			
		||||
                user.getUstatus(), user.getCode(), user.getEmail(), user.getUrole());
 | 
			
		||||
        return rows;
 | 
			
		||||
        return queryRunner.update(sql, user.getUsername(), user.getUpassword(), user.getUsex(), user.getUstatus(), user.getCode(), user.getEmail(), user.getUrole());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,43 @@
 | 
			
		||||
package com.qf.service;
 | 
			
		||||
 | 
			
		||||
import com.qf.entity.Address;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public interface AddressService {
 | 
			
		||||
    /**
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    List<Address> findAddressByUid(int uid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void saveAddress(Address address) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param aid
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void setAddressToDefault(String aid, int uid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param aid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void deleteAddressByAid(String aid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void updateByAid(Address address) throws SQLException;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,14 +6,45 @@ import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public interface CartService {
 | 
			
		||||
    /**
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @param pid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     * @throws InvocationTargetException
 | 
			
		||||
     * @throws IllegalAccessException
 | 
			
		||||
     */
 | 
			
		||||
    void createCart(int uid, String pid) throws SQLException, InvocationTargetException, IllegalAccessException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     * @throws InvocationTargetException
 | 
			
		||||
     * @throws IllegalAccessException
 | 
			
		||||
     */
 | 
			
		||||
    List<Cart> findAll(int uid) throws SQLException, InvocationTargetException, IllegalAccessException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param cid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void deleteCartByCid(String cid) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param cid
 | 
			
		||||
     * @param price
 | 
			
		||||
     * @param cnum
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void updateCartByCid(String cid, String price, String cnum) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    void clearCartByUid(String uid) throws SQLException;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,23 @@ import com.qf.entity.Product;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public interface ProductService {
 | 
			
		||||
    /**
 | 
			
		||||
     * @param tid
 | 
			
		||||
     * @param page
 | 
			
		||||
     * @param pageSize
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    PageBean<Product> findPage(String tid, int page, int pageSize) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param pid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    Product findProductByPid(String pid) throws SQLException;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,17 @@ import com.qf.entity.Type;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public interface TypeService {
 | 
			
		||||
 | 
			
		||||
    //查询返回所有类别表中对应的type信息
 | 
			
		||||
    /**
 | 
			
		||||
     * 查询返回所有类别表中对应的type信息
 | 
			
		||||
     *
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    List<Type> findAll() throws SQLException;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,14 +4,36 @@ import com.qf.entity.User;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public interface UserService {
 | 
			
		||||
 | 
			
		||||
    //查询用户名是否存在
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.查询用户名是否存在
 | 
			
		||||
     *
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    boolean checkedUser(String username) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    //注册业务逻辑
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.注册业务逻辑
 | 
			
		||||
     *
 | 
			
		||||
     * @param user
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    int registerUser(User user) throws SQLException;
 | 
			
		||||
 | 
			
		||||
    //登录的业务逻辑
 | 
			
		||||
    /**
 | 
			
		||||
     * 3.登录的业务逻辑
 | 
			
		||||
     *
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @param password
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    User login(String username, String password) throws SQLException;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,76 @@
 | 
			
		||||
package com.qf.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.qf.dao.AddressDao;
 | 
			
		||||
import com.qf.dao.impl.AddressDaoImpl;
 | 
			
		||||
import com.qf.entity.Address;
 | 
			
		||||
import com.qf.service.AddressService;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class AddressServiceImpl implements AddressService {
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.新增收货地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Address> findAddressByUid(int uid) throws SQLException {
 | 
			
		||||
        AddressDao addressDao = new AddressDaoImpl();
 | 
			
		||||
        return addressDao.selectAddressByUid(uid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.插入收货地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void saveAddress(Address address) throws SQLException {
 | 
			
		||||
        AddressDao addressDao = new AddressDaoImpl();
 | 
			
		||||
        addressDao.insertAddress(address);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 3.设置默认收货地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param aid
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setAddressToDefault(String aid, int uid) throws SQLException {
 | 
			
		||||
        AddressDao addressDao = new AddressDaoImpl();
 | 
			
		||||
        addressDao.updateAddressToDefault(aid, uid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 4.删除收货地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param aid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void deleteAddressByAid(String aid) throws SQLException {
 | 
			
		||||
        AddressDao addressDao = new AddressDaoImpl();
 | 
			
		||||
        addressDao.deleteAddressByAid(aid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 5.修改收货地址
 | 
			
		||||
     *
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateByAid(Address address) throws SQLException {
 | 
			
		||||
        AddressDao addressDao = new AddressDaoImpl();
 | 
			
		||||
        addressDao.updateByAid(address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,8 +13,19 @@ import java.math.BigDecimal;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class CartServiceImpl implements CartService {
 | 
			
		||||
     //1.向购物车中添加物品
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.向购物车中添加物品
 | 
			
		||||
     *
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @param pid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     * @throws InvocationTargetException
 | 
			
		||||
     * @throws IllegalAccessException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void createCart(int uid, String pid) throws SQLException, InvocationTargetException, IllegalAccessException {
 | 
			
		||||
        //1.判断商品是否已经存在
 | 
			
		||||
@@ -43,24 +54,43 @@ public class CartServiceImpl implements CartService {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //2.根据uid查询所有商品
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.根据uid查询所有商品
 | 
			
		||||
     *
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     * @throws InvocationTargetException
 | 
			
		||||
     * @throws IllegalAccessException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Cart> findAll(int uid) throws SQLException, InvocationTargetException, IllegalAccessException {
 | 
			
		||||
 | 
			
		||||
        CartDao cartDao = new CartDaoImpl();
 | 
			
		||||
        //1.根据用户 id 查询对应购物车里面的商品
 | 
			
		||||
        List<Cart> carts = cartDao.selectCartByUid(uid);
 | 
			
		||||
        return carts;
 | 
			
		||||
        return cartDao.selectCartByUid(uid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //3.根据cid删除购物车中物品
 | 
			
		||||
    /**
 | 
			
		||||
     * 3.根据cid删除购物车中物品
 | 
			
		||||
     *
 | 
			
		||||
     * @param cid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void deleteCartByCid(String cid) throws SQLException {
 | 
			
		||||
        CartDao cartDao = new CartDaoImpl();
 | 
			
		||||
        cartDao.deleteCartByCid(cid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //4.购物车修改数量
 | 
			
		||||
    /**
 | 
			
		||||
     * 4.购物车修改数量
 | 
			
		||||
     *
 | 
			
		||||
     * @param cid
 | 
			
		||||
     * @param price
 | 
			
		||||
     * @param cnum
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateCartByCid(String cid, String price, String cnum) throws SQLException {
 | 
			
		||||
 | 
			
		||||
@@ -74,15 +104,17 @@ public class CartServiceImpl implements CartService {
 | 
			
		||||
        //3.数据库中修改
 | 
			
		||||
        CartDao cartDao = new CartDaoImpl();
 | 
			
		||||
        cartDao.updateByCid(count, cnumbig, cid);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //5.清空购物车
 | 
			
		||||
    /**
 | 
			
		||||
     * 5.清空购物车
 | 
			
		||||
     *
 | 
			
		||||
     * @param uid
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void clearCartByUid(String uid) throws SQLException {
 | 
			
		||||
 | 
			
		||||
        CartDao cartDao = new CartDaoImpl();
 | 
			
		||||
        cartDao.clearCartByUid(uid);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,26 +9,38 @@ import com.qf.service.ProductService;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class ProductServiceImpl implements ProductService {
 | 
			
		||||
    /**
 | 
			
		||||
     * @param tid
 | 
			
		||||
     * @param page
 | 
			
		||||
     * @param pageSize
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public PageBean<Product> findPage(String tid, int page, int pageSize) throws SQLException {
 | 
			
		||||
        ProductDao productDao = new ProductDaoImpl();
 | 
			
		||||
        //1.查询有多少条数据
 | 
			
		||||
        long count = productDao.selectCountByTid(tid);
 | 
			
		||||
 | 
			
		||||
        //
 | 
			
		||||
        List<Product> list = productDao.selectProductByPage(page, pageSize, tid);
 | 
			
		||||
 | 
			
		||||
        return new PageBean<Product>(list, page, pageSize, count);
 | 
			
		||||
        return new PageBean<>(list, page, pageSize, count);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param pid
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public Product findProductByPid(String pid) throws SQLException {
 | 
			
		||||
        //1.先到数据库中进行商品查询
 | 
			
		||||
        ProductDao productDao = new ProductDaoImpl();
 | 
			
		||||
        //2.定义一个productdao里面对应的方法,返回product
 | 
			
		||||
        Product product = productDao.selectProductByPid(pid);
 | 
			
		||||
        //3.返回product信息
 | 
			
		||||
        return product;
 | 
			
		||||
 | 
			
		||||
        //2.定义productdao里面对应的方法,返回product
 | 
			
		||||
        return productDao.selectProductByPid(pid);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,13 +8,19 @@ import com.qf.service.TypeService;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class TypeServiceImpl implements TypeService {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Type> findAll() throws SQLException {
 | 
			
		||||
        //这里调用TypeDao接口(Dao层)
 | 
			
		||||
        TypeDao typeDao = new TypeDaoImpl();
 | 
			
		||||
        List<Type> types = typeDao.selectAll();
 | 
			
		||||
        return types;
 | 
			
		||||
        return typeDao.selectAll();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,17 @@ import com.qf.utils.MD5Utils;
 | 
			
		||||
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author 小灰灰呀
 | 
			
		||||
 */
 | 
			
		||||
public class UserServiceImpl implements UserService {
 | 
			
		||||
    //查询用户名是否存在
 | 
			
		||||
    /**
 | 
			
		||||
     * 1.查询用户名是否存在
 | 
			
		||||
     *
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean checkedUser(String username) throws SQLException {
 | 
			
		||||
 | 
			
		||||
@@ -17,24 +26,30 @@ public class UserServiceImpl implements UserService {
 | 
			
		||||
        UserDao userDao = new UserDaoImpl();
 | 
			
		||||
        User user = userDao.selectUserByUname(username);
 | 
			
		||||
 | 
			
		||||
        //处理返回值
 | 
			
		||||
        if (user != null) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //没有查询到
 | 
			
		||||
        return false;
 | 
			
		||||
        //没有查询到 处理返回值
 | 
			
		||||
        return user != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //注册业务逻辑
 | 
			
		||||
    /**
 | 
			
		||||
     * 2.注册业务逻辑
 | 
			
		||||
     *
 | 
			
		||||
     * @param user
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public int registerUser(User user) throws SQLException {
 | 
			
		||||
        UserDao userDao = new UserDaoImpl();
 | 
			
		||||
        int row = userDao.insertUser(user);
 | 
			
		||||
        return row;
 | 
			
		||||
        return userDao.insertUser(user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //登录的业务逻辑
 | 
			
		||||
    /**
 | 
			
		||||
     * 3.登录的业务逻辑
 | 
			
		||||
     *
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @param password
 | 
			
		||||
     * @throws SQLException
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public User login(String username, String password) throws SQLException {
 | 
			
		||||
        //1.密码加密处理(数据库中密码已加密处理)便于比较
 | 
			
		||||
 
 | 
			
		||||
@@ -155,13 +155,15 @@ public class PaymentUtil {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static String toHex(byte input[]) {
 | 
			
		||||
		if (input == null)
 | 
			
		||||
		if (input == null) {
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
		StringBuffer output = new StringBuffer(input.length * 2);
 | 
			
		||||
		for (int i = 0; i < input.length; i++) {
 | 
			
		||||
			int current = input[i] & 0xff;
 | 
			
		||||
			if (current < 16)
 | 
			
		||||
			if (current < 16) {
 | 
			
		||||
				output.append("0");
 | 
			
		||||
			}
 | 
			
		||||
			output.append(Integer.toString(current, 16));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user