基于javaweb+mysql的甜品冰淇淋奶茶店网上订餐系统(前台、后台)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
分为前台和后台管理
前台用户可以注册、登录、查看商品列表与商品详情、加入购物车、下单购买等
后台管理员可以管理用户、商品、分类、订单等
前台
后台
技术框架
JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) MySQL jQuery Bootstrap JavaScript CSS
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
/**
* 通过分类搜索
* @param typeid
* @param page
* @param size
* @return
*/
public List<Goods> getListByType(int typeid, int page, int size) {
return typeid > 0 ? goodDao.getListByType(typeid, size * (page-1), size) : goodDao.getList(size * (page-1), size);
}
/**
* 获取数量
* @param typeid
* @return
*/
public long getTotalByType(int typeid){
return typeid > 0 ? goodDao.getTotalByType(typeid) : goodDao.getTotal();
}
/**
* 通过id获取
* @param productid
* @return
*/
}
/**
* 添加
* @param admin
*/
public Integer add(Admins admin) {
admin.setPassword(SafeUtil.encode(admin.getPassword()));
return adminDao.insert(admin);
}
/**
* 更新
* @param user
*/
public boolean update(Admins admin) {
* @param row
* @return
*/
public List<Orders> getList(byte status, int page, int row) {
List<Orders> orderList = orderDao.getListByStatus(status, row * (page-1), row);
for(Orders order : orderList) {
order.setItemList(this.getItemList(order.getId()));
}
return orderList;
}
/**
* 获取总数
* @return
*/
public int getTotal(byte status) {
return (int)orderDao.getTotalByStatus(status);
}
/**
return goods;
}
/**
* 添加
* @param product
*/
public Integer add(Goods good) {
return goodDao.insert(good);
}
/**
* 修改
* @param product
* @return
*/
public boolean update(Goods good) {
return goodDao.updateById(good) > 0;
}
/**
* 删除商品
* 先删除此商品的推荐信息
* @param product
session.removeAttribute("user");
session.removeAttribute("order");
return "/index/login.jsp";
}
/**
* 查看购物车
* @return
*/
@RequestMapping("/cart")
public String cart(Model model) {
model.addAttribute("typeList", typeService.getList());
return "/index/cart.jsp";
}
/**
request.setAttribute("goodList", goodService.getListByType(typeid, page, rows));
request.setAttribute("pageTool", PageUtil.getPageTool(request, goodService.getTotalByType(typeid), page, rows));
return "/index/goods.jsp";
}
/**
* 商品详情
* @return
*/
@RequestMapping("/detail")
public String detail(int goodid, HttpServletRequest request){
request.setAttribute("good", goodService.get(goodid));
request.setAttribute("typeList", typeService.getList());
return "/index/detail.jsp";
}
/**
* 搜索
* @return
*/
@RequestMapping("/search")
public String search(String name, @RequestParam(required=false, defaultValue="1")int page, HttpServletRequest request) {
if (Objects.nonNull(name) && !name.trim().isEmpty()) {
*/
public Orders deleteIndentItem(Orders order, Goods good) {
List<Items> itemList = order.getItemList();
itemList = itemList==null ? new ArrayList<Items>() : itemList;
// 如果购物车已有此项目, 数量清零
boolean noneThis = true;
int itemAmount = 0;
List<Items> resultList = new ArrayList<Items>();
for (Items item : itemList) {
if (item.getGoodId() == good.getId()) {
itemAmount = item.getAmount();
noneThis = false;
continue;
}
resultList.add(item);
}
return null;
}
order.setItemList(resultList);
// 如果当前购物车没有项目, 直接返回
if (noneThis) {
return order;
}
order.setTotal(order.getTotal() - good.getPrice() * itemAmount);
order.setAmount(order.getAmount() - itemAmount);
return order;
}
/**
* 保存订单
* @param order
*/
public int save(Orders order) {
order.setStatus(Orders.STATUS_UNPAY);
order.setSystime(new Date());
orderDao.insert(order);
int orderid = order.getId();
for(Items item : order.getItemList()){
return image1;
}
public void setImage1(String image1) {
this.image1 = image1 == null ? null : image1.trim();
}
public String getImage2() {
return image2;
}
public void setImage2(String image2) {
this.image2 = image2 == null ? null : image2.trim();
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public String getIntro() {
return intro;
}
/**
* 管理员修改自己密码
*
* @return
*/
@RequestMapping("/adminReset")
public String adminReset(Admins admin, HttpServletRequest request) {
request.setAttribute("flag", 5);
if (adminService.get(admin.getId()).getPassword().equals(SafeUtil.encode(admin.getPassword()))) {
admin.setPassword(SafeUtil.encode(admin.getPasswordNew()));
adminService.update(admin);
request.setAttribute("admin", admin);
request.setAttribute("msg", "修改成功!");
}else {
request.setAttribute("msg", "原密码错误!");
}
return "/admin/admin_reset.jsp";
}
@Service // 注解为service层spring管理bean
@Transactional // 注解此类所有方法加入spring事务, 具体设置默认
public class OrderService {
@Autowired
private OrdersDao orderDao;
@Autowired
private ItemsDao itemDao;
@Autowired
private GoodService goodService;
/**
* 创建订单
* @param good
* @return
*/
/**
* 获取总数
* @return
*/
public int getTotal(byte status) {
return (int)orderDao.getTotalByStatus(status);
}
/**
* 订单发货
* @param id
* @return
*/
public boolean dispose(int id) {
Orders order = orderDao.selectById(id);
order.setStatus(Orders.STATUS_SEND);
return orderDao.updateByIdSelective(order) > 0;
}
/**
* 订单完成
* @param id
* @return
*/
public boolean finish(int id) {
Orders order = orderDao.selectById(id);
// 以上为mybatis generator自动生成接口, 具体实现在mapper.xml中
// ------------------------------------------------------------
// 以下方法使用mybatis注解实现
/**
* 获取列表
* @param page
* @param size
* @return
*/
@Select("select * from goods order by id desc limit #{begin}, #{size}")
public List<Goods> getList(@Param("begin")int begin, @Param("size")int size);
/**
* 获取总数
* @return
#{typeId,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByIdSelective" parameterType="com.entity.Goods" >
update goods
<set >
<if test="name != null" >
name = #{name,jdbcType=VARCHAR},
</if>
<if test="cover != null" >
cover = #{cover,jdbcType=VARCHAR},
</if>
<if test="image1 != null" >
image1 = #{image1,jdbcType=VARCHAR},
</if>
@RequestParam(required=false, defaultValue="1") int page) {
request.setAttribute("flag", 3);
request.setAttribute("page", page);
request.setAttribute("status", status);
request.setAttribute("goodList", goodService.getList(status, page, rows));
request.setAttribute("pageTool", PageUtil.getPageTool(request, goodService.getTotal(status), page, rows));
return "/admin/good_list.jsp";
}
/**
* 产品添加
*
* @return
*/
@RequestMapping("/goodAdd")
public String goodAdd(HttpServletRequest request) {