提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
提示:这里可以添加本文要记录的大概内容:
提示:以下是本篇文章正文内容,下面案例可供参考
一、运行效果
二、部分代码
1.登录部分
代码如下(示例):
public Users login(String userName, String userPass) {
List<Users> userList = userMapper.findUserByName(userName);
for (Users users : userList) {
if(users.getUserPass().equals(userPass)){
return users;
}
}
return null;
}
2.读入数据
代码如下(示例):
//下订单
@RequestMapping("takeOrder")
public String takeOrder(Integer[] goodslist,Integer addr,Model model,HttpServletRequest request){
List<Cart> cartList=new ArrayList<Cart>();
List<OrderDetail> detailList=new ArrayList<OrderDetail>();
Double totalPrice=0D;
for (Integer i : goodslist) {
Cart cart = cartService.findCartById(i);
totalPrice+=cart.getCartNum()*cart.getCartGoods().getGoodsPrice();
cartList.add(cart);
OrderDetail detail=new OrderDetail(cart.getCartGoods(), cart.getCartGoods().getGoodsPrice()*cart.getCartNum(), cart.getCartNum());
detailList.add(detail);
}
HttpSession session = request.getSession();
Users user=(Users) session.getAttribute("user");
Date orderDate=new Date();
Address address = addressService.findAddresById(addr);
String a=address.getAddrProvince()+address.getAddrCity()+address.getAddrArea()+address.getAddrDetail();
Order order=new Order(user, orderDate, totalPrice, 1, address.getAddrNickname(), address.getAddrPhone(), a);
order.setDetailList(detailList);
Order takeOrder = orderService.takeOrder(order);
for (Cart c : cartList) {
Goods goods = goodsService.findById(c.getCartGoods().getGoodsId());
goods.setGoodsNum(goods.getGoodsNum()-c.getCartNum());
goods.setGoodsVolume(goods.getGoodsVolume()+c.getCartNum());
goodsService.update(goods);
cartService.deleteCart(c.getCartId());
}
model.addAttribute("order",takeOrder);
List<Guess> guessList = guessService.findGuessGoodsByUserId(user.getUserId(), 4);
model.addAttribute("guessList", guessList);
return "userview/takeorder";
}
该处使用的url网络请求的数据。
总结
如有疑问可私聊博主或评论区留下联系方式。