基于javaweb+mysql的ssm家具商城系统(java+ssm+jsp+bootstrap+echarts+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM家具商城系统(java+ssm+jsp+bootstrap+echarts+mysql)
项目介绍
本项目分为前后台,前台为普通用户登录,后台为管理员登录;
管理员角色包含以下功能:
管理员登录,类目管理,用户管理,商品管理,订单管理,发货管理,提交发货,公告管理,留言管理,日志查看等功能。
用户角色包含以下功能:
用户登录,用户首页,查看公告,提交留言,查看商品详情,加入购物车,商品结算等功能。
环境需要
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.数据库:MySql 5.7版本; 6.是否Maven项目:是;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jquery+bootstrap+echarts
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/shop 登录 用户账号/密码: user/123456 管理员账号/密码:admin/admin
//拿到输出流,同时重命名上传的文件
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 "";
}
// --------------------------------------- 华丽分割线 ------------------------------
}
package com.neusoft.controller;
// //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.状态删除
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(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.update(load);
//5.状态删除
//User load = userService.load(id);
//load.setIsDelete(1);
//userService.update(load);
return "redirect:/user/findBySql.action";
}
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);
//存储查询条件
model.addAttribute("obj", itemCategory);
return "itemCategory/itemCategory";
}
/**
* 分页查询 返回list对象(通过对By Sql)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findBySql")
public String findBySql(ItemCategory itemCategory, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
String sql = "SELECT * FROM item_category WHERE isDelete = 0 and pid is null";
// if(!isEmpty(itemCategory.getName())){
// sql += " and name like '%"+itemCategory.getName()+"%'";
// }
// if(!isEmpty(itemCategory.getPid())){
// sql += " and pid like '%"+itemCategory.getPid()+"%'";
// }
// if(!isEmpty(itemCategory.getIsDelete())){
// sql += " and isDelete like '%"+itemCategory.getIsDelete()+"%'";
// }
sql += " ORDER BY ID DESC ";
Pager<ItemCategory> pagers = itemCategoryService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", itemCategory);
return "itemCategory/itemCategory";
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
*/
@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) {
// //3.通过参数删除
// //通过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());
// }
//
// orderDetailService.deleteByMap(params);
// //4.状态删除
// OrderDetail load = orderDetailService.getById(orderDetail.getId())
// load.setIsDelete(1);
// orderDetailService.update(load);
//5.状态删除
//OrderDetail load = orderDetailService.load(id);
//load.setIsDelete(1);
//orderDetailService.update(load);
return "redirect:/orderDetail/findBySql.action";
}
// --------------------------------------- 华丽分割线 ------------------------------
// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
@ResponseBody
public String listAllJson(OrderDetail orderDetail, HttpServletRequest request, HttpServletResponse response){
List<OrderDetail> listAll = orderDetailService.listAll();
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", orderDetail);
return jsonObject.toString();
}
}
//分页查询
Pager<Message> pagers = messageService.findByMap(params);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", message);
return "message/message";
}
/**********************************【增删改】******************************************************/
/**
* 跳至添加页面
* @return
*/
@RequestMapping(value = "/add")
public String add() {
return "message/add";
}
/**
* ajax 添加
* @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";
}
// params.put("itemId", comment.getItemId());
// }
//
// if(!isEmpty(comment.getContent())){
// params.put("content", comment.getContent());
// }
//
// if(!isEmpty(comment.getAddTime())){
// params.put("addTime", comment.getAddTime());
// }
//
// commentService.deleteByMap(params);
// //4.状态删除
// Comment load = commentService.getById(comment.getId())
// load.setIsDelete(1);
// commentService.updateById(load);
//5.状态删除
//Comment load = commentService.load(id);
//load.setIsDelete(1);
//commentService.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 "";
* @return
*/
@RequestMapping(value = "/exAdd")
public String exAdd(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response) {
orderDetailService.insert(orderDetail);
return "redirect:/orderDetail/findBySql.action";
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/update")
public String update(Integer id,Model model) {
OrderDetail obj = orderDetailService.load(id);
model.addAttribute("obj",obj);
return "orderDetail/update";
}
/**
* 添加修改
* @return
*/
@RequestMapping(value = "/exUpdate")
public String exUpdate(OrderDetail orderDetail, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
orderDetailService.updateById(orderDetail);
//2.通过主键id修改
//orderDetailService.updateById(orderDetail);
return "redirect:/orderDetail/findBySql.action";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
///1.通过主键删除
orderDetailService.deleteById(id);
/*以下是多种删除方式*/
// //2.通过实体条件删除
// orderDetailService.deleteByEntity(orderDetail);
// //3.通过参数删除
// //通过map查询
// Map<String,Object> params = new HashMap<String,Object>();
//
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);
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntity")
public String listByEntity(Sc sc, Model model, HttpServletRequest request, HttpServletResponse response){
List<Sc> listAll = scService.listAllByEntity(sc);
model.addAttribute("list", listAll);
return "sc/sc";
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMap")
public String listByMap(Sc sc, Model model, 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());
}
List<Sc> listAll = scService.listByMap(params);
model.addAttribute("list", listAll);
return "sc/sc";
}
/*********************************查询列表【分页】***********************************************/
/**
* 分页查询 返回list对象(通过对象)
*
* @param request
* @param response
* @return
@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
@ResponseBody
public String listAllJson(Item item, HttpServletRequest request, HttpServletResponse response){
List<Item> listAll = itemService.listAll();
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", item);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
@ResponseBody
public String listByEntityJson(Item item, HttpServletRequest request, HttpServletResponse response){
List<Item> listAll = itemService.listAllByEntity(item);
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", item);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
@ResponseBody
public String listByMapJson(Item item,HttpServletRequest request, HttpServletResponse response){
//通过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())){
* @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
*/
@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()){
* @throws IllegalStateException
*/
@RequestMapping(value = "/exUpdate")
public String exUpdate(Item item, Model model, @RequestParam("file") CommonsMultipartFile[] files, HttpServletRequest request, HttpServletResponse response) throws IllegalStateException, IOException {
//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";
}
/**
* 分页查询 返回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());
}
//分页查询
Pager<OrderDetail> pagers = orderDetailService.findByMap(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", orderDetail);
return jsonObject.toString();
}
/**
* 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 "";
}
// --------------------------------------- 华丽分割线 ------------------------------
}
package com.neusoft.controller;
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
@ResponseBody
public String listAllJson(Address address, HttpServletRequest request, HttpServletResponse response){
List<Address> listAll = addressService.listAll();
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", address);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
@ResponseBody
public String listByEntityJson(Address address, HttpServletRequest request, HttpServletResponse response){
List<Address> listAll = addressService.listAllByEntity(address);
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", address);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @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
*/
@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);
addressService.insert(address);
return "redirect:/address/my.action";
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/update")
public String update(Integer id,Model model) {
Address obj = addressService.load(id);
model.addAttribute("obj",obj);
return "address/update";
}
/**
* 添加修改
* @return
*/
@RequestMapping(value = "/exUpdate")
public String exUpdate(Address address, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
addressService.updateById(address);
//2.通过主键id修改
//addressService.updateById(address);
return "redirect:/car/view.action";
}
@RequestMapping(value = "/exUpdate2")
public String exUpdate2(Address address, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
addressService.updateById(address);
//2.通过主键id修改
//addressService.updateById(address);
return "redirect:/address/my.action";
}
@RequestMapping(value = "/delete1")
public String delete1(Integer id, 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())){
// params.put("name", news.getName());
// }
//
// if(!isEmpty(news.getContent())){
// params.put("content", news.getContent());
// }
//
// if(!isEmpty(news.getAddTime())){
// params.put("addTime", news.getAddTime());
// }
//
// newsService.deleteByMap(params);
// //4.状态删除
// News load = newsService.getById(news.getId())
// load.setIsDelete(1);
// newsService.update(load);
//5.状态删除
//News load = newsService.load(id);
//load.setIsDelete(1);
//newsService.update(load);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "删除成功");
return jsonObject.toString();
}
/**
public String findByObj(Sc sc, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Sc> pagers = scService.findByEntity(sc);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", sc);
return "sc/sc";
}
/**
* 分页查询 返回list对象(通过对By Sql)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findBySql")
public String findBySql(Sc sc, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Object attribute = request.getSession().getAttribute("userId");
if (attribute == null){
return "redirect:/login/uLogin";
}
JSONObject js = new JSONObject();
Integer userId = Integer.valueOf(attribute.toString());
String sql = "SELECT * FROM sc WHERE 1=1 and user_id="+userId;
if(!isEmpty(sc.getItemId())){
sql += " and itemId like '%"+sc.getItemId()+"%'";
}
if(!isEmpty(sc.getUserId())){
sql += " and userId like '%"+sc.getUserId()+"%'";
}
sql += " ORDER BY ID DESC ";
Pager<Sc> pagers = scService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", sc);
return "sc/my";
}
/**
* 分页查询 返回list对象(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap")
model.addAttribute("list", listAll);
return "comment/comment";
}
/*********************************查询列表【分页】***********************************************/
/**
* 分页查询 返回list对象(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObj")
public String findByObj(Comment comment, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Comment> pagers = commentService.findByEntity(comment);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", comment);
return "comment/comment";
}
/**
* 分页查询 返回list对象(通过对By Sql)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findBySql")
public String findBySql(Comment comment, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
String sql = "SELECT * FROM comment WHERE 1=1 ";
if(!isEmpty(comment.getUserId())){
sql += " and userId like '%"+comment.getUserId()+"%'";
}
if(!isEmpty(comment.getItemId())){
sql += " and itemId like '%"+comment.getItemId()+"%'";
}
if(!isEmpty(comment.getContent())){
sql += " and content like '%"+comment.getContent()+"%'";
}
if(!isEmpty(comment.getAddTime())){
sql += " and addTime like '%"+comment.getAddTime()+"%'";
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAll")
public String listAll(Address address, Model model, HttpServletRequest request, HttpServletResponse response){
List<Address> listAll = addressService.listAll();
model.addAttribute("list", listAll);
return "address/address";
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntity")
public String listByEntity(Address address, Model model, HttpServletRequest request, HttpServletResponse response){
List<Address> listAll = addressService.listAllByEntity(address);
model.addAttribute("list", listAll);
return "address/address";
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMap")
public String listByMap(Address address, Model model, HttpServletRequest request, HttpServletResponse response){
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(address.getName())){
params.put("name", address.getName());
}
if(!isEmpty(address.getPhone())){
params.put("phone", address.getPhone());
}
if(!isEmpty(address.getArea())){
* @return
*/
@RequestMapping(value = "/findByObj")
public String findByObj(Message message, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Message> pagers = messageService.findByEntity(message);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", message);
return "message/message";
}
/**
* 分页查询 返回list对象(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap")
public String findByMap(Message message, Model model, HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(message.getName())){
params.put("name", message.getName());
}
if(!isEmpty(message.getPhone())){
params.put("phone", message.getPhone());
}
if(!isEmpty(message.getContent())){
params.put("content", message.getContent());
}
//分页查询
Pager<Message> pagers = messageService.findByMap(params);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", message);
return "message/message";
}
/**********************************【增删改】******************************************************/
/**
* 跳至添加页面
* @return
*/
@RequestMapping(value = "/add")
List<ItemOrder> yqx = itemOrderService.listBySqlReturnEntity(sql3);
String sql4 = "SELECT * FROM item_order WHERE status = 2 and user_id="+userId;
sql4 += " ORDER BY ID DESC ";
//已发货
List<ItemOrder> yfh = itemOrderService.listBySqlReturnEntity(sql4);
String sql5 = "SELECT * FROM item_order WHERE status = 3 and user_id="+userId;
sql5 += " ORDER BY ID DESC ";
//待评价
List<ItemOrder> dpj = itemOrderService.listBySqlReturnEntity(sql5);
model.addAttribute("all", all);
model.addAttribute("dfh", dfh);
model.addAttribute("yqx", yqx);
model.addAttribute("yfh", yfh);
model.addAttribute("dpj", dpj);
//存储查询条件
model.addAttribute("obj", itemOrder);
return "itemOrder/my";
}
/**
* 分页查询 返回list对象(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap")
public String findByMap(ItemOrder itemOrder, Model model, HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(itemOrder.getItemId())){
params.put("itemId", itemOrder.getItemId());
}
* @return
*/
@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
@ResponseBody
public String findByObjByEntityJson(Address address, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Address> pagers = addressService.findByEntity(address);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", address);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMapJson", method = RequestMethod.POST)
@ResponseBody
public String findByMapJson(Address address,HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(address.getName())){
params.put("name", address.getName());
}
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());
}
//分页查询
Pager<Address> pagers = addressService.findByMap(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", address);
return jsonObject.toString();
}
/**
* ajax 添加
* @param
* @return