源码获取:俺的博客首页 "资源" 里下载!
项目介绍
角色:管理员、用户
用户登陆后,主要模块包括主页、个人中心、评论、购物车、我的收藏等功能。
管理员登陆后,主要模块包括主页、个人中心、用户管理、商品分类管理、商品信息管理、系统管理、订单管理等功能
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目;
6.数据库:MySql 5.7/8.0等版本均可;
技术栈
后端:SSM(Spring+SpringMVC+Mybatis)
前端:JSP+CSS+JS+JQUERY+Layui
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
购物车管理控制层:
@Controller
@RequestMapping("/car")
public class CarController {
@Autowired
private CarService carService;
@Autowired
private ItemService itemService;
/**
* 加入购物车
*
* @param request
* @param car
* @return
*/
@RequestMapping("/addcar")
@ResponseBody
public String addcar(HttpServletRequest request, Car car) {
JSONObject json = new JSONObject();
Object userId = request.getSession().getAttribute("userId");
//如果未登录,返回0,提示先登录
if (userId == null) {
json.put(Consts.RES, 0);
return json.toJSONString();
}
//保存到购物车
Item item = itemService.getById(car.getItemId());
car.setUserId(Integer.valueOf(userId.toString()));
String price = item.getPrice();
Double value = Double.valueOf(price);
car.setPrice(value);
// BigDecimal bigDecimal = new BigDecimal(value).setScale(2,BigDecimal.ROUND_UP);
if (item.getZk() != null) {
value = value * item.getZk() / 10;
BigDecimal bigDecimal = new BigDecimal(value).setScale(2, RoundingMode.UP);
car.setPrice(bigDecimal.doubleValue());
}
Integer num = car.getNum();
Double t = value * num;
BigDecimal bigDecimal = new BigDecimal(t).setScale(2, RoundingMode.UP);
Double tDouble = bigDecimal.doubleValue();
car.setTotal(tDouble + "");
carService.insert(car);
json.put(Consts.RES, 1);
return json.toJSONString();
}
/**
* 跳转到购物车页面
* @param model
* @param request
* @return
*/
@RequestMapping("/findBySql")
public String findBySql(Model model, HttpServletRequest request) {
Object userId = request.getSession().getAttribute("userId");
if(userId==null){
return "redirect:/login/uLogin";
}
Integer id = Integer.valueOf(userId.toString());
String sql = "select * from car where user_id="+id+" order by id";
List<Car> carList = carService.listBySqlReturnEntity(sql);
model.addAttribute("list",carList);
return "/car/carview";
}
/**
* 删除购物车
* @param id
* @return
*/
@RequestMapping("/delete")
@ResponseBody
public String delete(Integer id){
carService.deleteById(id);
return "success";
}
}
订单详情控制层:
@Controller
@RequestMapping("/orderDetail")
public class OrderDetailController {
@Autowired
private OrderDetailService orderDetailService;
/**
* 获取订单详情列表
* @param model
* @param orderDetail
* @return
*/
@RequestMapping("/findbysql")
public String OrderDetailList(Model model,OrderDetail orderDetail){
String sql = "select * from order_detail where status = 0 and order_id = "+orderDetail.getOrderId();
Pager<OrderDetail> pagers = orderDetailService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers",pagers);
model.addAttribute("obj",orderDetail);
return "/orderDetail/orderDetailList";
}
}
品类管理控制层:
@Controller
@RequestMapping("/itemCategory")
public class ItemCategoryController extends BaseController {
@Autowired
private ItemCategoryService itemCategoryService;
/**
* 分页查询类目列表
*/
@RequestMapping("/findBySql")
public String findBySql(Model model,ItemCategory itemCategory){
String sql = "select * from item_category where isDelete = 0 and pid is null order by id";
Pager<ItemCategory> pagers = itemCategoryService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers",pagers);
model.addAttribute("obj",itemCategory);
return "itemCategory/itemCategory";
}
/**
*转向添加一级分类页面
* @return
*/
@RequestMapping("/add")
public String addItemCategory(){
return "/itemCategory/add";
}
/**
*转向添加二级分类页面
* @return
*/
@RequestMapping("/add2")
public String addItemCategory2(Model model,Integer pid){
model.addAttribute("pid",pid);
return "/itemCategory/add2";
}
/**
* 跳转到修改类目页面
* @return
*/
@RequestMapping("/update")
public String updateItemCategory(Integer id,Model model){
ItemCategory itemCategory = itemCategoryService.load(id);
model.addAttribute("item",itemCategory);
return "/itemCategory/update";
}
/**
* 跳转到修改二级类目页面
* @return
*/
@RequestMapping("/updateTwo")
public String updateTwoItemCategory(Integer id,Model model){
ItemCategory itemCategory = itemCategoryService.load(id);
model.addAttribute("item",itemCategory);
return "/itemCategory/update2";
}
/**
* 添加一级类目
* @param itemCategory
* @return
*/
@RequestMapping("/exadd")
public String exaddItemCategory(ItemCategory itemCategory){
itemCategory.setIsDelete(0);
itemCategoryService.insert(itemCategory);
return "redirect:/itemCategory/findBySql";
// return "itemCategory/itemCategory";
}
/**
* 添加二级类目
* @param itemCategory
* @return
*/
@RequestMapping("/exadd2")
public String exaddItemCategory2(ItemCategory itemCategory){
itemCategory.setIsDelete(0);
Integer pid = itemCategory.getPid();
itemCategoryService.insert(itemCategory);
return "redirect:/itemCategory/findBySql2.action?pid="+pid;
// return "itemCategory/itemCategory";
}
/**
* 修改一级目录
* @param itemCategory
* @return
*/
@RequestMapping("/exupdate")
public String exupdateItemCategory(ItemCategory itemCategory){
itemCategory.setIsDelete(0);
String i = itemCategory.getName();
itemCategoryService.updateById(itemCategory);
return "redirect:/itemCategory/findBySql.action";
}
/**
* 修改二级目录
* @param itemCategory
* @return
*/
@RequestMapping("/exupdate2")
public String exupdateTwoItemCategory(ItemCategory itemCategory){
itemCategory.setIsDelete(0);
String i = itemCategory.getName();
Integer pid = itemCategory.getPid();
itemCategoryService.updateById(itemCategory);
return "redirect:/itemCategory/findBySql2.action?pid="+pid;
// return "redirect:/itemCategory/findBySql2.action?pid="+pid;
}
/**
* 删除一个类目
* @param id
* @return
*/
@RequestMapping("/delete")
public String deleteItemCategory(Integer id){
//把对应类目的isdelete改为1后更新
ItemCategory itemCategory = itemCategoryService.load(id);
itemCategory.setIsDelete(1);
itemCategoryService.updateById(itemCategory);
//如果类目下有子类目,把对应类目的isdelete改为1后更新
String sql = "update item_category set isDelete=1 where pid="+id;
itemCategoryService.updateBysql(sql);
return "redirect://itemCategory/findBySql.action";
}
/**
* 删除一个二级类目
* @param id
* @return
*/
@RequestMapping("/deleteTwo")
public String deleteTwoItemCategory(Integer id){
//把对应类目的isdelete改为1后更新
ItemCategory itemCategory = itemCategoryService.load(id);
itemCategory.setIsDelete(1);
itemCategoryService.updateById(itemCategory);
return "redirect://itemCategory/findBySql2.action?pid="+itemCategory.getPid();
}
/**
* 查找二级目录
* @param pid
* @param model
* @return
*/
@RequestMapping("findBySql2")
public String findBySql2ItemCategory(Integer pid,Model model){
//查找pid=id的类目
String sql = "select * from item_category where isDelete=0 and pid="+pid;
List<ItemCategory> list = itemCategoryService.listBySqlReturnEntity(sql);
Pager<ItemCategory> pagers = itemCategoryService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers",pagers);
model.addAttribute("ItemCategoryList",list);
model.addAttribute("pid",pid);
return "itemCategory/Sdirectory";
}
}
源码获取:俺的博客首页 "资源" 里下载!