作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
本项目为小程序商城系统前后台,前台为普通会员用户登录,后台为管理员登录;
程序功能:
1.小程序前台:用户注册登录、首页、轮播图、新品推荐、分类、购物车、我的订单。
2.网站后台:管理员登录、用户管理、商品类别管理、商品管理、订单管理、公告管理;
环境需要
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项目: 否;
技术栈
1. 后端:spring+struts+hibernate
2. 前端:JSP+css+javascript+jquery
使用说明
后台运行:
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中config/jdbc.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080/shop
管理员:admin/111111
前台小程序运行:
1.使用微信开发者工具导入项目;
2.导入成功后编译运行;
3.运行成功后登录账号;
普通用户:ceshi/111111
运行截图
前台小程序
后管页面
文章来源:https://www.toymoban.com/news/detail-499578.html
相关代码
信息管理控制器
@Controller
@RequestMapping("/message")
public class MessageController extends BaseController {
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private MessageService messageService;
// --------------------------------------- 华丽分割线 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAll")
public String listAll(Message message, Model model, HttpServletRequest request, HttpServletResponse response){
List<Message> listAll = messageService.listAll();
model.addAttribute("list", listAll);
return "message/message";
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntity")
public String listByEntity(Message message, Model model, HttpServletRequest request, HttpServletResponse response){
List<Message> listAll = messageService.listAllByEntity(message);
model.addAttribute("list", listAll);
return "message/message";
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMap")
public String listByMap(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());
}
List<Message> listAll = messageService.listByMap(params);
model.addAttribute("list", listAll);
return "message/message";
}
/*********************************查询列表【分页】***********************************************/
/**
* 分页查询 返回list对象(通过对象)
*
* @param request
* @param response
* @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")
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";
}
/**
* 添加修改
* @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())){
// params.put("name", message.getName());
// }
//
// if(!isEmpty(message.getPhone())){
// params.put("phone", message.getPhone());
// }
//
// if(!isEmpty(message.getContent())){
// params.put("content", message.getContent());
// }
//
// messageService.deleteByMap(params);
// //4.状态删除
// Message load = messageService.getById(message.getId())
// load.setIsDelete(1);
// messageService.update(load);
//5.状态删除
//Message load = messageService.load(id);
//load.setIsDelete(1);
//messageService.update(load);
return "redirect:/message/findByObj";
}
// --------------------------------------- 华丽分割线 ------------------------------
// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
@ResponseBody
public String listAllJson(Message message, HttpServletRequest request, HttpServletResponse response){
List<Message> listAll = messageService.listAll();
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", message);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
@ResponseBody
public String listByEntityJson(Message message, HttpServletRequest request, HttpServletResponse response){
List<Message> listAll = messageService.listAllByEntity(message);
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", message);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
@ResponseBody
public String listByMapJson(Message message,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());
}
List<Message> listAll = messageService.listByMap(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", message);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
@ResponseBody
public String findByObjByEntityJson(Message message, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Message> pagers = messageService.findByEntity(message);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", message);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMapJson", method = RequestMethod.POST)
@ResponseBody
public String findByMapJson(Message message,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);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", message);
return jsonObject.toString();
}
/**
* ajax 添加
* @param
* @return
*/
@RequestMapping(value = "/exAddJson", method = RequestMethod.POST)
@ResponseBody
public String exAddJson(Message message, Model model, HttpServletRequest request, HttpServletResponse response) {
messageService.insert(message);
JSONObject jsonObject = new JSONObject();
jsonObject.put("message", "添加成功");
return jsonObject.toString();
}
/**
* ajax 修改
* @param
* @return
*/
@RequestMapping(value = "/exUpdate.json", method = RequestMethod.POST)
@ResponseBody
public String exUpdateJson(Message message, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
messageService.update(message);
//2.通过主键id修改
//messageService.updateById(message);
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.通过主键删除
messageService.deleteById(id);
/*以下是多种删除方式*/
// //2.通过实体条件删除
// messageService.deleteByEntity(message);
// //3.通过参数删除
// //通过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());
// }
//
// messageService.deleteByMap(params);
// //4.状态删除
// Message load = messageService.getById(message.getId())
// load.setIsDelete(1);
// messageService.update(load);
//5.状态删除
//Message load = messageService.load(id);
//load.setIsDelete(1);
//messageService.update(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
*/
@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 "";
}
// --------------------------------------- 华丽分割线 ------------------------------
}
信息管理控制器
@Controller
@RequestMapping("/news")
public class NewsController extends BaseController {
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private NewsService newsService;
// --------------------------------------- 华丽分割线 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAll")
public String listAll(News news, Model model, HttpServletRequest request, HttpServletResponse response){
List<News> listAll = newsService.listAll();
model.addAttribute("list", listAll);
return "news/news";
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntity")
public String listByEntity(News news, Model model, HttpServletRequest request, HttpServletResponse response){
List<News> listAll = newsService.listAllByEntity(news);
model.addAttribute("list", listAll);
return "news/news";
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMap")
public String listByMap(News news, Model model, HttpServletRequest request, HttpServletResponse response){
//通过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());
}
List<News> listAll = newsService.listByMap(params);
model.addAttribute("list", listAll);
return "news/news";
}
/*********************************查询列表【分页】***********************************************/
/**
* 分页查询 返回list对象(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObj")
public String findByObj(News news, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<News> pagers = newsService.findByEntity(news);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", news);
return "news/news";
}
@RequestMapping(value = "/list")
public String list(News news, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<News> pagers = newsService.findByEntity(news);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", news);
return "news/list";
}
/**
* 分页查询 返回list对象(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap")
public String findByMap(News news, Model model, HttpServletRequest request, HttpServletResponse response) {
//通过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());
}
//分页查询
Pager<News> pagers = newsService.findByMap(params);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", news);
return "news/news";
}
/**********************************【增删改】******************************************************/
/**
* 跳至添加页面
* @return
*/
@RequestMapping(value = "/add")
public String add() {
return "news/add";
}
/**
* 添加执行
* @return
*/
@RequestMapping(value = "/exAdd")
public String exAdd(News news, Model model, HttpServletRequest request, HttpServletResponse response) {
news.setAddTime(new Date());
newsService.insert(news);
return "redirect:/news/findByObj";
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/update")
public String update(Integer id,Model model) {
News obj = newsService.load(id);
model.addAttribute("obj",obj);
return "news/update";
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/view")
public String view(Integer id,Model model) {
News obj = newsService.load(id);
model.addAttribute("obj",obj);
return "news/view";
}
/**
* 添加修改
* @return
*/
@RequestMapping(value = "/exUpdate")
public String exUpdate(News news, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
newsService.updateById(news);
//2.通过主键id修改
//newsService.updateById(news);
return "redirect:/news/findByObj";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(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);
return "redirect:/news/findByObj";
}
// --------------------------------------- 华丽分割线 ------------------------------
// --------------------------------------- 【下面是ajax操作的方法。】 ------------------------------
/*********************************查询列表【不分页】***********************************************/
/**
* 【不分页 => 查询列表 => 无条件】
* @Title: listAll
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listAllJson", method = RequestMethod.POST)
@ResponseBody
public String listAllJson(News news, HttpServletRequest request, HttpServletResponse response){
List<News> listAll = newsService.listAll();
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", news);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByEntity
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByEntityJson", method = RequestMethod.POST)
@ResponseBody
public String listByEntityJson(News news, HttpServletRequest request, HttpServletResponse response){
List<News> listAll = newsService.listAllByEntity(news);
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", news);
return jsonObject.toString();
}
/**
* 【不分页=》查询列表=>有条件】
* @Title: listByMap
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @return 设定文件
* @author
* @return String 返回类型
* @throws
*/
@RequestMapping(value = "/listByMapJson", method = RequestMethod.POST)
@ResponseBody
public String listByMapJson(News news,HttpServletRequest request, HttpServletResponse response){
//通过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());
}
List<News> listAll = newsService.listByMap(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("list", listAll);
jsonObject.put("obj", news);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObjJson", method = RequestMethod.POST)
@ResponseBody
public String findByObjByEntityJson(News news, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<News> pagers = newsService.findByEntity(news);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", news);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMapJson", method = RequestMethod.POST)
@ResponseBody
public String findByMapJson(News news,HttpServletRequest request, HttpServletResponse response) {
//通过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());
}
//分页查询
Pager<News> pagers = newsService.findByMap(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", news);
return jsonObject.toString();
}
/**
* ajax 添加
* @param
* @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())){
// 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();
}
/**
* 单文件上传
* @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
*/
@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 "";
}
// --------------------------------------- 华丽分割线 ------------------------------
}
如果也想学习本系统,下面领取。关注并回复:001小程序文章来源地址https://www.toymoban.com/news/detail-499578.html
到了这里,关于Java项目:微信小程序商城+后台管理系统的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!