基于javaweb+mysql的ssm网上果蔬商城水果蔬菜商城系统(java+ssm+mysql+tomcat+jsp)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM网上果蔬商城水果蔬菜商城系统(java+ssm+mysql+tomcat+jsp)
一、项目简述
功能: 功能:系统分管理员界面与用户界面 管理员:用户管理,商品类别管理,商品管理,订单管理,公 告管理留言里筲等 向户:房总主册功能,用户登录功能,商品浏览,商品留言评 论,商品购买,商品支付,订单查询等等
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + Fileupload + maven等等。
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMap")
public String listByMap(ItemCategory itemCategory, Model model, HttpServletRequest request, HttpServletResponse response){
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(itemCategory.getName())){
params.put("name", itemCategory.getName());
}
if(!isEmpty(itemCategory.getPid())){
params.put("pid", itemCategory.getPid());
}
if(!isEmpty(itemCategory.getIsDelete())){
params.put("isDelete", itemCategory.getIsDelete());
}
List<ItemCategory> listAll = itemCategoryService.listByMap(params);
model.addAttribute("list", listAll);
return "itemCategory/itemCategory";
}
/*********************************查询列表【分页】***********************************************/
@Autowired
private ItemService itemService;
/**
* 分页查询 返回list对象(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObj")
public String findByObj(ItemCategory itemCategory, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<ItemCategory> pagers = itemCategoryService.findByEntity(itemCategory);
model.addAttribute("pagers", pagers);
}
/**
* 分页查询 返回list json(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
@ResponseBody
public String findByObjByEntityJson(Sc sc, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Sc> pagers = scService.findByEntity(sc);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", sc);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMapJson", method = RequestMethod.POST)
@ResponseBody
public String findByMapJson(Sc sc,HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(sc.getItemId())){
params.put("itemId", sc.getItemId());
}
if(!isEmpty(sc.getUserId())){
params.put("userId", sc.getUserId());
}
//分页查询
Pager<Sc> pagers = scService.findByMap(params);
JSONObject jsonObject = new JSONObject();
@Controller
@RequestMapping("/manage")
public class ManageController extends BaseController {
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private ManageService manageService;
// --------------------------------------- 华丽分割线 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAll")
public String listAll(Manage manage, Model model, HttpServletRequest request, HttpServletResponse response){
List<Manage> listAll = manageService.listAll();
model.addAttribute("list", listAll);
return "manage/manage";
}
/**
* 【不分页=》查询列表=>有条件】
* @return
*/
@RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
@ResponseBody
public String exAddJson(News news, Model model, HttpServletRequest request, HttpServletResponse response) {
newsService.insert(news);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "添加成功");
return jsonObject.toString();
}
/**
* ajax 修改
* @param
* @return
*/
@RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
@ResponseBody
public String exUpdateJson(News news, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
newsService.update(news);
//2.通过主键id修改
//newsService.updateById(news);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "修改成功");
return jsonObject.toString();
}
/**
* ajax 删除
* @return
*/
@RequestMapping(value = "/delete.json", method = RequestMethod.POST)
@ResponseBody
public String exDeleteJson(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
///1.通过主键删除
newsService.deleteById(id);
/*以下是多种删除方式*/
// //2.通过实体条件删除
// newsService.deleteByEntity(news);
// //3.通过参数删除
// //通过map查询
// Map<String,Object> params = new HashMap<String,Object>();
//
// if(!isEmpty(news.getName())){
// if(!isEmpty(itemOrder.getStatus())){
// params.put("status", itemOrder.getStatus());
// }
//
// itemOrderService.deleteByMap(params);
// //4.状态删除
// ItemOrder load = itemOrderService.getById(itemOrder.getId())
// load.setIsDelete(1);
// itemOrderService.update(load);
//5.状态删除
//ItemOrder load = itemOrderService.load(id);
//load.setIsDelete(1);
//itemOrderService.update(load);
return "redirect:/itemOrder/findBySql.action";
}
// --------------------------------------- 华丽分割线 ------------------------------
// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
@ResponseBody
public String listAllJson(ItemOrder itemOrder, HttpServletRequest request, HttpServletResponse response){
List<ItemOrder> listAll = itemOrderService.listAll();
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", itemOrder);
return jsonObject.toString();
}
params.put("orderId", orderDetail.getOrderId());
}
if(!isEmpty(orderDetail.getStatus())){
params.put("status", orderDetail.getStatus());
}
List<OrderDetail> listAll = orderDetailService.listByMap(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", orderDetail);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
@ResponseBody
public String findByObjByEntityJson(OrderDetail orderDetail, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<OrderDetail> pagers = orderDetailService.findByEntity(orderDetail);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", orderDetail);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMapJson", method = RequestMethod.POST)
@ResponseBody
public String findByMapJson(OrderDetail orderDetail,HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(orderDetail.getItemId())){
params.put("itemId", orderDetail.getItemId());
}
if(!isEmpty(orderDetail.getOrderId())){
params.put("orderId", orderDetail.getOrderId());
}
if(!isEmpty(orderDetail.getStatus())){
params.put("status", orderDetail.getStatus());
return "redirect:/item/findBySql.action";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
///1.通过主键删除
//itemService.deleteById(id);
/*以下是多种删除方式*/
// //2.通过实体条件删除
// itemService.deleteByEntity(item);
// //3.通过参数删除
// //通过map查询
// Map<String,Object> params = new HashMap<String,Object>();
//
// if(!isEmpty(item.getName())){
// params.put("name", item.getName());
// }
//
// if(!isEmpty(item.getPrice())){
// params.put("price", item.getPrice());
// }
//
// if(!isEmpty(item.getScNum())){
// params.put("scNum", item.getScNum());
// }
//
// if(!isEmpty(item.getGmNum())){
// params.put("gmNum", item.getGmNum());
// }
//
// if(!isEmpty(item.getUrl1())){
// params.put("url1", item.getUrl1());
// }
//
// if(!isEmpty(item.getUrl2())){
// params.put("url2", item.getUrl2());
// }
//
} catch (Exception e) {
e.printStackTrace();
System.out.println("上传出错");
}
}
}
return "";
}
// --------------------------------------- 华丽分割线 ------------------------------
}
//1.通过实体类修改,可以多传修改条件
ItemCategory byId = itemCategoryService.getById(item.getCategoryIdTwo());
item.setCategoryIdOne(byId.getPid());
if (files.length > 0){
// 0 1 2 3 4
for (int s = 0;s < files.length;s++){
System.out.println("开始");
long startTime=System.currentTimeMillis();
System.out.println("fileName:"+files[s].getOriginalFilename());
String n = UUIDUtils.create();
String path="D:/my/upload/"+n+files[s].getOriginalFilename();
System.out.println("===================================================");
System.out.println(path);
File newFile=new File(path);
//通过CommonsMultipartFile的方法直接写文件(注意这个时候)
files[s].transferTo(newFile);
long endTime=System.currentTimeMillis();
System.out.println("方法二的运行时间:"+String.valueOf(endTime-startTime)+"ms");
System.out.println("*********************************************************");
System.out.println("*********************************************************");
if (s == 0){
item.setUrl1("\\upload\\"+n+files[s].getOriginalFilename());
}
if (s == 1){
item.setUrl2("\\upload\\"+n+files[s].getOriginalFilename());
}
if (s == 2){
item.setUrl3("\\upload\\"+n+files[s].getOriginalFilename());
}
if (s == 3){
item.setUrl4("\\upload\\"+n+files[s].getOriginalFilename());
}
if (s == 4){
item.setUrl5("\\upload\\"+n+files[s].getOriginalFilename());
}
}
}
itemService.updateById(item);
Item byId2 = itemService.getById(item.getId());
//2.通过主键id修改
//itemService.updateById(item);
return "redirect:/item/findBySql.action";
if(!isEmpty(address.getPhone())){
params.put("phone", address.getPhone());
}
if(!isEmpty(address.getArea())){
params.put("area", address.getArea());
}
if(!isEmpty(address.getBm())){
params.put("bm", address.getBm());
}
if(!isEmpty(address.getIsUse())){
params.put("isUse", address.getIsUse());
}
List<Address> listAll = addressService.listByMap(params);
model.addAttribute("list", listAll);
return "address/address";
}
/*********************************查询列表【分页】***********************************************/
/**
* 分页查询 返回list对象(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObj")
public String findByObj(Address address, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Address> pagers = addressService.findByEntity(address);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", address);
return "address/address";
}
/**
* 分页查询 返回list对象(通过对By Sql)
*
* @param request
* @param response
* @return
*/
// params.put("total", car.getTotal());
// }
//
// carService.deleteByMap(params);
// //4.状态删除
// Car load = carService.getById(car.getId())
// load.setIsDelete(1);
// carService.updateById(load);
//5.状态删除
//Car load = carService.load(id);
//load.setIsDelete(1);
//carService.updateById(load);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "删除成功");
return jsonObject.toString();
}
/**
* 单文件上传
* @param file
* @param request
* @param model
* @return
*/
@RequestMapping(value = "/saveFile")
public String saveFile(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, Model model) {
System.out.println("开始");
String path = request.getSession().getServletContext().getRealPath("/upload");
String fileName = file.getOriginalFilename();
System.out.println(path);
File targetFile = new File(path, fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
//保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
/**
* springMvc多文件上传
* @param files
* @param id
* @return
scService.updateById(sc);
//2.通过主键id修改
//scService.updateById(sc);
return "redirect:/sc/findBySql.action";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
///1.通过主键删除
scService.deleteById(id);
/*以下是多种删除方式*/
// //2.通过实体条件删除
// scService.deleteByEntity(sc);
// //3.通过参数删除
// //通过map查询
// Map<String,Object> params = new HashMap<String,Object>();
//
// if(!isEmpty(sc.getItemId())){
// params.put("itemId", sc.getItemId());
// }
//
// if(!isEmpty(sc.getUserId())){
// params.put("userId", sc.getUserId());
// }
//
// scService.deleteByMap(params);
// //4.状态删除
// Sc load = scService.getById(sc.getId())
// load.setIsDelete(1);
// scService.update(load);
//5.状态删除
//Sc load = scService.load(id);
//load.setIsDelete(1);
//scService.update(load);
return "redirect:/sc/findBySql.action";
}
// --------------------------------------- 华丽分割线 ------------------------------
// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
targetFile.mkdirs();
}
//保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
/**
* springMvc多文件上传
* @param files
* @param id
* @return
*/
@RequestMapping(value = "/saveFiles")
public String saveFiles(@RequestParam("file") CommonsMultipartFile[] files,Integer id,HttpServletRequest request){
for(int i = 0;i<files.length;i++){
System.out.println("fileName---------->" + files[i].getOriginalFilename());
if(!files[i].isEmpty()){
int pre = (int) System.currentTimeMillis();
try {
//拿到输出流,同时重命名上传的文件
String filePath = request.getRealPath("/upload");
File f=new File(filePath);
if(!f.exists()){
f.mkdirs();
}
String fileNmae=new Date().getTime() + files[i].getOriginalFilename();
File file=new File(filePath+"/"+pre + files[i].getOriginalFilename());
if(!file.exists()){
file.createNewFile();
}
files[i].transferTo(file);
} catch (Exception e) {
e.printStackTrace();
System.out.println("上传出错");
}
}
}
return "";
}
// --------------------------------------- 华丽分割线 ------------------------------
params.put("total", car.getTotal());
}
//分页查询
Pager<Car> pagers = carService.findByMap(params);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", car);
return "car/car";
}
/**********************************【增删改】******************************************************/
/**
* 跳至添加页面
* @return
*/
@RequestMapping(value = "/add")
public String add() {
return "car/add";
}
/**
* 跳至详情页面
* @return
*/
@RequestMapping(value = "/view")
public String view(Model model,HttpServletRequest request,String code) {
Object attribute = request.getSession().getAttribute("userId");
if (attribute == null){
return "redirect:/login/uLogin";
}
Integer userId = Integer.valueOf(attribute.toString());
model.addAttribute("code", code);
return "car/view";
}
/**
* 添加执行
* @return
*/
@RequestMapping(value = "/exAdd")
@ResponseBody
public String exAdd(Car car, Model model, HttpServletRequest request, HttpServletResponse response) {
Object attribute = request.getSession().getAttribute("userId");
JSONObject js = new JSONObject();
if (attribute == null){
js.put("res", 0);
return js.toJSONString();
* @param
* @return
*/
@RequestMapping(value = "/exAdd", method = RequestMethod.POST)
@ResponseBody
public String exAdd(Message message, Model model, HttpServletRequest request, HttpServletResponse response) {
messageService.insert(message);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "添加成功");
return jsonObject.toString();
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/update")
public String update(Integer id,Model model) {
Message obj = messageService.load(id);
model.addAttribute("obj",obj);
return "message/update";
}
/**
* 添加修改
* @return
*/
@RequestMapping(value = "/exUpdate")
public String exUpdate(Message message, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
messageService.update(message);
//2.通过主键id修改
//messageService.updateById(message);
return "redirect:/message/findByObj";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
///1.通过主键删除
messageService.deleteById(id);
/*以下是多种删除方式*/
// //2.通过实体条件删除
// messageService.deleteByEntity(message);
// //3.通过参数删除
// //通过map查询
// Map<String,Object> params = new HashMap<String,Object>();
//
// if(!isEmpty(message.getName())){
// Map<String,Object> params = new HashMap<String,Object>();
//
// if(!isEmpty(car.getItemId())){
// params.put("itemId", car.getItemId());
// }
//
// if(!isEmpty(car.getUserId())){
// params.put("userId", car.getUserId());
// }
//
// if(!isEmpty(car.getNum())){
// params.put("num", car.getNum());
// }
//
// if(!isEmpty(car.getTotal())){
// params.put("total", car.getTotal());
// }
//
// carService.deleteByMap(params);
// //4.状态删除
// Car load = carService.getById(car.getId())
// load.setIsDelete(1);
// carService.update(load);
//5.状态删除
//Car load = carService.load(id);
//load.setIsDelete(1);
//carService.update(load);
return "redirect:/car/findBySql.action";
}
// --------------------------------------- 华丽分割线 ------------------------------
// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
@ResponseBody
public String listAllJson(Car car, HttpServletRequest request, HttpServletResponse response){
List<Car> listAll = carService.listAll();
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", car);
return jsonObject.toString();
}
if(!isEmpty(itemCategory.getPid())){
params.put("pid", itemCategory.getPid());
}
if(!isEmpty(itemCategory.getIsDelete())){
params.put("isDelete", itemCategory.getIsDelete());
}
//分页查询
Pager<ItemCategory> pagers = itemCategoryService.findByMap(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", itemCategory);
return jsonObject.toString();
}
/**
* ajax 添加
* @param
* @return
*/
@RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
@ResponseBody
public String exAddJson(ItemCategory itemCategory, Model model, HttpServletRequest request, HttpServletResponse response) {
itemCategoryService.insert(itemCategory);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "添加成功");
return jsonObject.toString();
}
/**
* ajax 修改
* @param
* @return
*/
@RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
@ResponseBody
public String exUpdateJson(ItemCategory itemCategory, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
itemCategoryService.updateById(itemCategory);
//2.通过主键id修改
//itemCategoryService.updateById(itemCategory);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "修改成功");
return jsonObject.toString();
}
/**
* ajax 删除
public String exDeleteJson(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
///1.通过主键删除
userService.deleteById(id);
/*以下是多种删除方式*/
// //2.通过实体条件删除
// userService.deleteByEntity(user);
// //3.通过参数删除
// //通过map查询
// Map<String,Object> params = new HashMap<String,Object>();
//
// if(!isEmpty(user.getUserName())){
// params.put("userName", user.getUserName());
// }
//
// if(!isEmpty(user.getPassWord())){
// params.put("passWord", user.getPassWord());
// }
//
// if(!isEmpty(user.getPhone())){
// params.put("phone", user.getPhone());
// }
//
// if(!isEmpty(user.getRealName())){
// params.put("realName", user.getRealName());
// }
//
// if(!isEmpty(user.getSex())){
// params.put("sex", user.getSex());
// }
//
// if(!isEmpty(user.getAddress())){
// params.put("address", user.getAddress());
// }
//
// if(!isEmpty(user.getEmail())){
// params.put("email", user.getEmail());
// }
//
// userService.deleteByMap(params);
// //4.状态删除
// User load = userService.getById(user.getId())
// load.setIsDelete(1);
// userService.updateById(load);
//5.状态删除
//User load = userService.load(id);
//load.setIsDelete(1);
//userService.updateById(load);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "删除成功");
return jsonObject.toString();