基于javaweb+mysql的ssm鲜花商城管理系统(java+ssm+bootstrap+jsp+jquery+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSM鲜花商城管理系统(java+ssm+bootstrap+jsp+jquery+mysql)
管理员
admin 123456
用户
user1 123456
user2 123456
user3 123456
项目介绍
系统功能: 用户:登录、注册、商品查询、公告预览、留言、订单管理、商品商城、修改密码、个人信息修改、商品查询。 管理员:登录、类别管理、用户管理、商品管理、订单管理、公告管理、留言管理
环境需要
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等版本均可;
技术栈
后台框架:Spring、SpringMVC、MyBatis UI界面:JSP、jQuery 、BootStrap
数据库:MySQL
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目; 3. 将项目中db.xml配置文件中的数据库配置改为自己的配置,然后运行;
return "redirect:/news/findBySql";
}
/**
* 删除公告
*/
@RequestMapping("/delete")
public String delete(Integer id){
newsService.deleteById(id);
return "redirect:/news/findBySql";
}
/**
* 前端公告列表
*/
@RequestMapping("/list")
public String list(Model model){
Pager<News> pagers = newsService.findByEntity(new News());
model.addAttribute("pagers",pagers);
return "news/list";
}
/**
* 公告详情页面
*/
@RequestMapping("/view")
public String view(Integer id,Model model){
News obj = newsService.load(id);
model.addAttribute("obj",obj);
return "news/view";
}
}
model.addAttribute("lbs",list);
}
}
//折扣商品
List<Item> zks = itemService.listBySqlReturnEntity("select * from item where isDelete=0 and zk is not null order by zk desc limit 0,10");
model.addAttribute("zks",zks);
//热销商品
List<Item> rxs = itemService.listBySqlReturnEntity("select * from item where isDelete=0 order by gmNum desc limit 0,10");
model.addAttribute("rxs",rxs);
return "login/uIndex";
}
/**普通用户注册*/
@RequestMapping("/res")
public String res(){
return "login/res";
}
/**执行普通用户注册*/
@RequestMapping("/toRes")
public String toRes(User u, HttpServletRequest request){
//User byEntity = userService.getByEntity(u);
//if(byEntity==null){
// return "redirect:/login/res";
// }else {
userService.insert(u);
return "login/uLogin";
//}
}
/**普通用户登录入口*/
@RequestMapping("/uLogin")
public String uLogin(){
return "login/uLogin";
}
/**执行普通用户登录*/
@RequestMapping("/utoLogin")
public String utoLogin(User u,HttpServletRequest request){
User byEntity = userService.getByEntity(u);
if(byEntity==null){
return "redirect:/login/uLogin";
}else {
request.getSession().setAttribute("role",2);
request.getSession().setAttribute(Consts.USERNAME,byEntity.getUserName());
@RequestMapping("/saveFile")
public Map<String,Object> saveFile(@RequestParam(value="upfile",required = false)MultipartFile file) throws IOException {
Map<String,Object> params = new HashMap<>();
String n = UUIDUtils.create();
String path = SystemContext.getRealPath() + "resource\\ueditor\\upload\\" + n + file.getOriginalFilename();
File newFile = new File(path);
//通过CommonsMultipartFile的方法直接写文件
file.transferTo(newFile);
String visitUrl = "/resource/ueditor/upload/"+n+file.getOriginalFilename();
params.put("state","SUCCESS");
params.put("url",visitUrl);
params.put("size",file.getSize());
params.put("original",file.getOriginalFilename());
params.put("type",file.getContentType());
return params;
}
}
/**
* 评论
*/
@Controller
@RequestMapping("/comment")
public class CommentController extends BaseController {
@Autowired
private CommentService commentService;
/**
* 添加执行
*/
@RequestMapping("/exAdd")
public String exAdd(Comment comment, HttpServletRequest request){
Object attribute = request.getSession().getAttribute(Consts.USERID);
if(attribute==null){
return "redirect:/login/toLogin";
}
@RequestMapping("/exUpdate2")
public String exUpdate2(ItemCategory itemCategory){
itemCategoryService.updateById(itemCategory);
return "redirect:/itemCategory/findBySql2.action?pid="+itemCategory.getPid();
}
/**
* 删除二级类目
*/
@RequestMapping("/delete2")
public String delete2(Integer id,Integer pid){
//删除本身
ItemCategory load = itemCategoryService.load(id);
load.setIsDelete(1);
itemCategoryService.updateById(load);
return "redirect:/itemCategory/findBySql2.action?pid="+pid;
}
@Autowired
private ItemService itemService;
@RequestMapping(value = "/tj")
public String tj(ItemCategory itemCategory, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
String sql = "SELECT * FROM item_category WHERE isDelete = 0 and pid is null";
sql += " ORDER BY ID DESC ";
List<ItemCategory> list = itemCategoryService.listBySqlReturnEntity(sql);
List<Map<String,Object>> maps = new ArrayList<Map<String,Object>>();
List<TjDto> res = new ArrayList<TjDto>();
if (!CollectionUtils.isEmpty(list)){
for (ItemCategory c : list){
TjDto td = new TjDto();
int tot = 0;
List<Item> listBySqlReturnEntity = itemService.listBySqlReturnEntity("SELECT * FROM item WHERE 1=1 and isDelete =0 and category_id_one="+c.getId());
if (!CollectionUtils.isEmpty(listBySqlReturnEntity)){
for (Item i : listBySqlReturnEntity){
tot+= i.getGmNum();
}
}
Map<String,Object> map = new HashMap<String,Object>();
map.put("name", c.getName());
map.put("value", tot);
maps.add(map);
}
}
//存储查询条件
model.addAttribute("maps", maps);
return "itemCategory/tj";
//订单详情放入orderDetail,删除购物车
if(!CollectionUtils.isEmpty(ids)){
for(CarDto c:list){
Car load = carService.load(c.getId());
OrderDetail de = new OrderDetail();
de.setItemId(load.getItemId());
de.setOrderId(order.getId());
de.setStatus(0);
de.setNum(c.getNum());
de.setTotal(String.valueOf(c.getNum()*load.getPrice()*load.getZk()));
orderDetailService.insert(de);
//修改成交数
Item load2 = itemService.load(load.getItemId());
load2.setGmNum(load2.getGmNum()+c.getNum());
itemService.updateById(load2);
//删除购物车
carService.deleteById(c.getId());
}
}
js.put(Consts.RES,1);
return js.toJSONString();
}
private static String date;
private static long orderNum = 0L;
public static synchronized String getOrderNo(){
String str = new SimpleDateFormat("yyyyMMddHHmm").format(new Date());
if(date==null||!date.equals(str)){
date = str;
orderNum = 0L;
}
orderNum++;
long orderNO = Long.parseLong(date)*10000;
orderNO += orderNum;
return orderNO+"";
}
/**
* 取消订单
*/
@RequestMapping("/qx")
public String qx(Integer id,Model model){
ItemOrder obj =itemOrderService.load(id);
// Item load2 = itemService.load(obj.getItemId());
// load2.setGmNum(load2.getGmNum()-obj.);
@Autowired
private UserService userService;
@Autowired
private CarService carService;
@Autowired
private OrderDetailService orderDetailService;
@Autowired
private ItemService itemService;
/**
* 订单管理列表
*/
@RequestMapping("/findBySql")
public String findBySql(ItemOrder itemOrder, Model model){
//分页查询
String sql = "select * from item_order where 1=1 ";
if(!(isEmpty(itemOrder.getCode()))){
sql +=" and code like '%"+itemOrder.getCode()+"%' ";
}
sql += " order by id desc";
Pager<ItemOrder> pagers = itemOrderService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers",pagers);
//存储查询条件
model.addAttribute("obj",itemOrder);
return "itemOrder/itemOrder";
}
/**
* 我的订单
*/
@RequestMapping("/my")
public String my(Model model, HttpServletRequest request){
Object attribute = request.getSession().getAttribute(Consts.USERID);
if(attribute==null){
return "redirect:/login/uLogin";
}
Integer userId = Integer.valueOf(attribute.toString());
//全部订单
String sql = "select * from item_order where user_id="+userId+" order by id desc";
List<ItemOrder> all = itemOrderService.listBySqlReturnEntity(sql);
//待发货
String sql2 = "select * from item_order where user_id="+userId+" and status=0 order by id desc";
List<ItemOrder> dfh = itemOrderService.listBySqlReturnEntity(sql2);
//已取消
/**
* 留言管理
*/
@Controller
@RequestMapping("/message")
public class MessageController extends BaseController {
@Autowired
private MessageService messageService;
/**
* 留言列表
*/
@RequestMapping("/findBySql")
public String findBySql(Message message, Model model){
String sql = "select * from message where 1=1 ";
if(!isEmpty(message.getName())){
sql += " and name like '%"+message.getName()+"%'";
}
sql += " order by id desc";
Pager<Message> pagers = messageService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers",pagers);
model.addAttribute("obj",message);
return "message/message";
}
/**
* 删除留言
*/
@RequestMapping("/delete")
public String delete(Integer id){
messageService.deleteById(id);
return "redirect:/message/findBySql";
}
/**
* 发表留言进入
*/
@RequestMapping("/add")
String sql = "update item_category set isDelete=1 where pid="+id;
itemCategoryService.updateBysql(sql);
return "redirect:/itemCategory/findBySql.action";
}
/**
* 查看二级类目
*/
@RequestMapping("/findBySql2")
public String findBySql2(ItemCategory itemCategory,Model model){
String sql = "select * from item_category where isDelete=0 and pid="+itemCategory.getPid()+" order by id";
Pager<ItemCategory> pagers = itemCategoryService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers",pagers);
model.addAttribute("obj",itemCategory);
return "itemCategory/itemCategory2";
}
/**
* 转向到新增二级类目页面
*/
@RequestMapping(value = "/add2")
public String add2(int pid,Model model){
model.addAttribute("pid",pid);
return "itemCategory/add2";
}
/**
* 新增二级类目保存功能
*/
@RequestMapping("/exAdd2")
public String exAdd2(ItemCategory itemCategory){
itemCategory.setIsDelete(0);
itemCategoryService.insert(itemCategory);
return "redirect:/itemCategory/findBySql2.action?pid="+itemCategory.getPid();
}
/**
* 转向到修改二级类目页面
*/
@RequestMapping(value = "/update2")
public String update2(Integer id,Model model){
ItemCategory obj = itemCategoryService.load(id);
model.addAttribute("obj",obj);
return "itemCategory/update2";
}
/**
* 修改二级类目
*/
@RequestMapping("/exUpdate2")
public String exUpdate2(ItemCategory itemCategory){
}
/**
* 管理员退出
*/
@RequestMapping("mtuichu")
public String mtuichu(HttpServletRequest request){
request.getSession().setAttribute(Consts.MANAGE,null);
return "/login/mLogin";
}
/**
* 前端首页
*/
@RequestMapping("/uIndex")
public String uIndex(Model model, Item item,HttpServletRequest request){
String sql1 = "select * from item_category where isDelete=0 and pid is null order by name";
List<ItemCategory> fatherList = itemCategoryService.listBySqlReturnEntity(sql1);
List<CategoryDto> list = new ArrayList<>();
if(!CollectionUtils.isEmpty(fatherList)){
for(ItemCategory ic:fatherList){
CategoryDto dto = new CategoryDto();
dto.setFather(ic);
//查询二级类目
String sql2 = "select * from item_category where isDelete=0 and pid="+ic.getId();
List<ItemCategory> childrens = itemCategoryService.listBySqlReturnEntity(sql2);
dto.setChildrens(childrens);
list.add(dto);
model.addAttribute("lbs",list);
}
}
//折扣商品
List<Item> zks = itemService.listBySqlReturnEntity("select * from item where isDelete=0 and zk is not null order by zk desc limit 0,10");
model.addAttribute("zks",zks);
//热销商品
List<Item> rxs = itemService.listBySqlReturnEntity("select * from item where isDelete=0 order by gmNum desc limit 0,10");
model.addAttribute("rxs",rxs);
return "login/uIndex";
}
/**普通用户注册*/
@RequestMapping("/res")
public String res(){
return "login/res";
}
/**执行普通用户注册*/
@RequestMapping("/toRes")
model.addAttribute("obj",itemOrder);
return "itemOrder/itemOrder";
}
/**
* 我的订单
*/
@RequestMapping("/my")
public String my(Model model, HttpServletRequest request){
Object attribute = request.getSession().getAttribute(Consts.USERID);
if(attribute==null){
return "redirect:/login/uLogin";
}
Integer userId = Integer.valueOf(attribute.toString());
//全部订单
String sql = "select * from item_order where user_id="+userId+" order by id desc";
List<ItemOrder> all = itemOrderService.listBySqlReturnEntity(sql);
//待发货
String sql2 = "select * from item_order where user_id="+userId+" and status=0 order by id desc";
List<ItemOrder> dfh = itemOrderService.listBySqlReturnEntity(sql2);
//已取消
String sql3 = "select * from item_order where user_id="+userId+" and status=1 order by id desc";
List<ItemOrder> yqx = itemOrderService.listBySqlReturnEntity(sql3);
//已发货
String sql4 = "select * from item_order where user_id="+userId+" and status=2 order by id desc";
List<ItemOrder> dsh = itemOrderService.listBySqlReturnEntity(sql4);
//已收货
String sql5 = "select * from item_order where user_id="+userId+" and status=3 order by id desc";
List<ItemOrder> ysh = itemOrderService.listBySqlReturnEntity(sql5);
model.addAttribute("all",all);
model.addAttribute("dfh",dfh);
model.addAttribute("yqx",yqx);
model.addAttribute("dsh",dsh);
model.addAttribute("ysh",ysh);
return "itemOrder/my";
}
/**
* 购物车结算提交
*/
@RequestMapping("/exAdd")
@ResponseBody
public String exAdd(@RequestBody List<CarDto> list,HttpServletRequest request){
Object attribute = request.getSession().getAttribute(Consts.USERID);
JSONObject js = new JSONObject();
*/
@RequestMapping("/findBySql")
public String findBySql(ItemOrder itemOrder, Model model){
//分页查询
String sql = "select * from item_order where 1=1 ";
if(!(isEmpty(itemOrder.getCode()))){
sql +=" and code like '%"+itemOrder.getCode()+"%' ";
}
sql += " order by id desc";
Pager<ItemOrder> pagers = itemOrderService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers",pagers);
//存储查询条件
model.addAttribute("obj",itemOrder);
return "itemOrder/itemOrder";
}
/**
* 我的订单
*/
@RequestMapping("/my")
public String my(Model model, HttpServletRequest request){
Object attribute = request.getSession().getAttribute(Consts.USERID);
if(attribute==null){
return "redirect:/login/uLogin";
}
Integer userId = Integer.valueOf(attribute.toString());
//全部订单
String sql = "select * from item_order where user_id="+userId+" order by id desc";
List<ItemOrder> all = itemOrderService.listBySqlReturnEntity(sql);
//待发货
String sql2 = "select * from item_order where user_id="+userId+" and status=0 order by id desc";
List<ItemOrder> dfh = itemOrderService.listBySqlReturnEntity(sql2);
//已取消
String sql3 = "select * from item_order where user_id="+userId+" and status=1 order by id desc";
List<ItemOrder> yqx = itemOrderService.listBySqlReturnEntity(sql3);
//已发货
String sql4 = "select * from item_order where user_id="+userId+" and status=2 order by id desc";
List<ItemOrder> dsh = itemOrderService.listBySqlReturnEntity(sql4);
//已收货
String sql5 = "select * from item_order where user_id="+userId+" and status=3 order by id desc";
List<ItemOrder> ysh = itemOrderService.listBySqlReturnEntity(sql5);
model.addAttribute("all",all);
model.addAttribute("dfh",dfh);
model.addAttribute("yqx",yqx);
model.addAttribute("dsh",dsh);
model.addAttribute("ysh",ysh);
return "itemOrder/my";
}
/**
@Controller
@RequestMapping("/item")
public class ItemController extends BaseController {
@Autowired
private ItemService itemService;
@Autowired
private ItemCategoryService itemCategoryService;
/**
* 分页查询商品列表
*/
/**
* 删除公告
*/
@RequestMapping("/delete")
public String delete(Integer id){
newsService.deleteById(id);
return "redirect:/news/findBySql";
}
/**
* 前端公告列表
*/
@RequestMapping("/list")
public String list(Model model){
Pager<News> pagers = newsService.findByEntity(new News());
model.addAttribute("pagers",pagers);
return "news/list";
}
/**
* 公告详情页面
*/
@RequestMapping("/view")
public String view(Integer id,Model model){
News obj = newsService.load(id);
model.addAttribute("obj",obj);
return "news/view";
}
}
/**
/**
* 管理员登录前
* @return
*/
@RequestMapping("login")
public String login(){
return "/login/mLogin";
}
/**
* 登录验证
* @return
*/
@RequestMapping("toLogin")
public String toLogin(Manage manage, HttpServletRequest request){
Manage byEntity = manageService.getByEntity(manage);
if(byEntity==null){
return "redirect:/login/mtuichu";
}
request.getSession().setAttribute(Consts.MANAGE,byEntity);
return "/login/mIndex";
}
/**
* 管理员退出
*/
@RequestMapping("mtuichu")
public String mtuichu(HttpServletRequest request){
request.getSession().setAttribute(Consts.MANAGE,null);
return "/login/mLogin";
}
/**
* 前端首页
*/
@RequestMapping("/uIndex")
public String uIndex(Model model, Item item,HttpServletRequest request){
String sql1 = "select * from item_category where isDelete=0 and pid is null order by name";
List<ItemCategory> fatherList = itemCategoryService.listBySqlReturnEntity(sql1);
List<CategoryDto> list = new ArrayList<>();
if(!CollectionUtils.isEmpty(fatherList)){
for(ItemCategory ic:fatherList){
CategoryDto dto = new CategoryDto();
dto.setFather(ic);
//查询二级类目
String sql2 = "select * from item_category where isDelete=0 and pid="+ic.getId();
List<ItemCategory> childrens = itemCategoryService.listBySqlReturnEntity(sql2);
dto.setChildrens(childrens);
list.add(dto);
model.addAttribute("lbs",list);
public class UeditorController {
@ResponseBody
@RequestMapping("/saveFile")
public Map<String,Object> saveFile(@RequestParam(value="upfile",required = false)MultipartFile file) throws IOException {
Map<String,Object> params = new HashMap<>();
String n = UUIDUtils.create();
String path = SystemContext.getRealPath() + "resource\\ueditor\\upload\\" + n + file.getOriginalFilename();
File newFile = new File(path);
//通过CommonsMultipartFile的方法直接写文件
file.transferTo(newFile);
String visitUrl = "/resource/ueditor/upload/"+n+file.getOriginalFilename();
params.put("state","SUCCESS");
params.put("url",visitUrl);
params.put("size",file.getSize());
params.put("original",file.getOriginalFilename());
params.put("type",file.getContentType());
return params;
}
}
/**
* 评论
*/
@Controller
@RequestMapping("/comment")
public class CommentController extends BaseController {
@Autowired
private CommentService commentService;
/**
* 添加执行
*/
/**
* 修改二级类目
*/
@RequestMapping("/exUpdate2")
public String exUpdate2(ItemCategory itemCategory){
itemCategoryService.updateById(itemCategory);
return "redirect:/itemCategory/findBySql2.action?pid="+itemCategory.getPid();
}
/**
* 删除二级类目
*/
@RequestMapping("/delete2")
public String delete2(Integer id,Integer pid){
//删除本身
ItemCategory load = itemCategoryService.load(id);
load.setIsDelete(1);
itemCategoryService.updateById(load);
return "redirect:/itemCategory/findBySql2.action?pid="+pid;
}
@Autowired
private ItemService itemService;
@RequestMapping(value = "/tj")
public String tj(ItemCategory itemCategory, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
String sql = "SELECT * FROM item_category WHERE isDelete = 0 and pid is null";
sql += " ORDER BY ID DESC ";
List<ItemCategory> list = itemCategoryService.listBySqlReturnEntity(sql);
List<Map<String,Object>> maps = new ArrayList<Map<String,Object>>();
List<TjDto> res = new ArrayList<TjDto>();
if (!CollectionUtils.isEmpty(list)){
for (ItemCategory c : list){
TjDto td = new TjDto();
int tot = 0;
List<Item> listBySqlReturnEntity = itemService.listBySqlReturnEntity("SELECT * FROM item WHERE 1=1 and isDelete =0 and category_id_one="+c.getId());
if (!CollectionUtils.isEmpty(listBySqlReturnEntity)){
for (Item i : listBySqlReturnEntity){
tot+= i.getGmNum();
}
}
Map<String,Object> map = new HashMap<String,Object>();
map.put("name", c.getName());
map.put("value", tot);
maps.add(map);
}
}
model.addAttribute("pagers",pagers);
model.addAttribute("obj",message);
return "message/message";
}
/**
* 删除留言
*/
@RequestMapping("/delete")
public String delete(Integer id){
messageService.deleteById(id);
return "redirect:/message/findBySql";
}
/**
* 发表留言进入
*/
@RequestMapping("/add")
public String add(){
return "message/add";
}
/**
* 发表留言
*/
@RequestMapping("/exAdd")
@ResponseBody
public String exAdd(Message message){
messageService.insert(message);
JSONObject js = new JSONObject();
js.put("message","添加成功");
return js.toString();
}
}