基于javaweb+mysql的ssm茶叶售卖商城系统(java+ssm+jsp+easyui+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM茶叶售卖商城系统(java+ssm+jsp+easyui+mysql)
这是一个应用SSM框架的项目,前端页面整洁清晰。该系统有两个角色,一个是普通用户,另一个是管理员。
普通用户具有注册、登录、查看商品、添加购物车、添加商品收藏、下订单、商品评价、用户地址管理等等功能。
管理员具有登录、管理用户信息、管理商品信息、管理商品活动信息、管理订单信息、管理用户评论信息的等等功能。
应用技术:Jsp + SSM + EasyUi
运行环境:eclipse/IDEA + MySQL5.7 + Tomcat8.5 + JDK1.8
ret.put("msg", "活动数量编辑失败,请联系管理员!");
return ret;
}
}
if(teaService.edit(tea) <= 0){
ret.put("type", "error");
ret.put("msg", "商品编辑失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "商品编辑成功!");
return ret;
}
/**
* 批量删除商品
* @param ids
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(String ids){
Map<String, String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "选择要删除的数据!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
String[] split_ids= ids.split(",");//以逗号分割
for(int i=0;i<split_ids.length;i++)
{
Tea t = teaService.findByTeaId(split_ids[i]);
if(t == null) {
continue;
}
// 减少对应的活动数
actionService.reduceNowNum(t.getActionId());
// 删除与商品有关的购物车订单内容
Map<String,Object> queryMap = new HashMap<String, Object>();
queryMap.put("productId", t.getId());
List<Shopping> findList = shoppingService.findList(queryMap);
/**
* 批量删除账户
* @param ids
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(String ids){
Map<String, String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "选择要删除的数据!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
String[] split = ids.split(",");
for(String str : split) {
// 删除与账户有关的评论信息
commentService.deleteByAccountId(Long.valueOf(str));
shoppingService.deleteByAccountId(Long.valueOf(str));
ordersService.deleteByAccountId(Long.valueOf(str));
view_LogService.deleteByAccountId(Long.valueOf(str));
addressService.deleteByAccountId(Long.valueOf(str));
collectService.deleteByAccountId(Long.valueOf(str));
}
if(accountService.delete(ids) == 0){
ret.put("type", "error");
ret.put("msg", "账户删除失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "账户删除成功!");
return ret;
}
return ret;
}
// 删除与改角色有关权限信息
authorityService.deleteByRoleId(id);
if(roleService.delete(id) == 0){
ret.put("type", "error");
ret.put("msg", "删除失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色删除成功!");
return ret;
}
/**
* 获取所有的菜单信息
* @return
*/
@RequestMapping(value="/get_all_menu",method=RequestMethod.POST)
@ResponseBody
public List<Menu> getAllMenu(){
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("offset", 0);
queryMap.put("pageSize", 99999);
return menuService.findList(queryMap);
}
/**
* 添加权限
* @param ids
* @return
*/
@RequestMapping(value="/add_authority",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> addAuthority(
@RequestParam(name="ids",required=true) String ids,
@RequestParam(name="roleId",required=true) Long roleId
){
Map<String,String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
Account account = accountService.findByUsername(username);
if(account == null)return false;
if(account.getId().longValue() == id.longValue())return false;
return true;
}
}
/**
* 前端购物控制类
*
*/
@Controller
@RequestMapping("/home/shopping")
public class ShopShoppingController {
public class ShopLoginController {
@Autowired
private AccountService accountService;
@Autowired
private LogService logService;
@Autowired
private ShoppingService shoppingService;
/**
* 前端系统登录页面
* @param model
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.GET)
public ModelAndView index(ModelAndView model,HttpServletRequest request){
Account account = (Account) request.getSession().getAttribute("account");
if(account!=null)
{
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("accountId",account.getId());
queryMap.put("state","未支付");
model.addObject("cartTotal",shoppingService.getTotal(queryMap));
}
model.setViewName("home/login/index");
return model;
}
/**
* 登录表单提交处理控制器
* @param user
* @param cpacha
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> loginAct(Account account,HttpServletRequest request){
Map<String, String> ret = new HashMap<String, String>();
if(account == null){
Map<String, String> ret = new HashMap<String, String>();
ret.put("type", "error");
ret.put("msg", "登录会话超时或还未登录,请重新登录!");
response.getWriter().write(JSONObject.fromObject(ret).toString());
return false;
}
//表示是普通链接跳转,直接重定向到登录页面
response.sendRedirect(request.getServletContext().getContextPath() + "/system/login");
return false;
}
//获取菜单id
String mid = request.getParameter("_mid");
if(!StringUtils.isEmpty(mid)){
List<Menu> allThirdMenu = MenuUtil.getAllThirdMenu((List<Menu>)request.getSession().getAttribute("userMenus"), Long.valueOf(mid));
request.setAttribute("thirdMenuList", allThirdMenu);
}
return true;
}
}
@Controller
@RequestMapping("/home/comment")
public class ShopCommentController {
@Autowired
private CommentService commentService;
@Autowired
private TeaService teaService;
}
String savePath = request.getServletContext().getRealPath("/") + "/resources/upload/";
File savePathFile = new File(savePath);
if(!savePathFile.exists()){
//若不存在改目录,则创建目录
savePathFile.mkdir();
}
String filename = new Date().getTime()+"."+suffix;
try {
//将文件保存至指定目录
photo.transferTo(new File(savePath+filename));
}catch (Exception e) {
// TODO Auto-generated catch block
ret.put("type", "error");
ret.put("msg", "保存文件异常!");
e.printStackTrace();
return ret;
}
ret.put("type", "success");
ret.put("msg", "图片上传成功!");
ret.put("filepath",request.getServletContext().getContextPath() + "/resources/upload/" + filename );
return ret;
}
/**
* 判断该用户名是否存在
* @param username
* @param id
* @return
*/
private boolean isExist(String username,Long id){
User user = userService.findByUsername(username);
if(user == null)return false;
if(user.getId().longValue() == id.longValue())return false;
return true;
}
}
/**
* 商品管理控制器
*
*/
@RequestMapping("/admin/product")
@Controller
public class ProductController {
}
String savePath = request.getServletContext().getRealPath("/") + "/resources/upload/";
File savePathFile = new File(savePath);
if(!savePathFile.exists()){
//若不存在改目录,则创建目录
savePathFile.mkdir();
}
String filename = new Date().getTime()+"."+suffix;
try {
//将文件保存至指定目录
photo.transferTo(new File(savePath+filename));
}catch (Exception e) {
// TODO Auto-generated catch block
ret.put("type", "error");
ret.put("msg", "保存文件异常!");
e.printStackTrace();
return ret;
}
ret.put("type", "success");
ret.put("msg", "图片上传成功!");
ret.put("filepath",request.getServletContext().getContextPath() + "/resources/upload/" + filename );
return ret;
}
/**
* 判断该用户名是否存在
* @param username
* @param id
* @return
*/
private boolean isExist(String username,Long id){
User user = userService.findByUsername(username);
if(user == null)return false;
if(user.getId().longValue() == id.longValue())return false;
return true;
}
}
ret.put("msg", "文件大小不能超过10M!");
return ret;
}
//获取文件后缀
String suffix = photo.getOriginalFilename().substring(photo.getOriginalFilename().lastIndexOf(".")+1,photo.getOriginalFilename().length());
if(!"jpg,jpeg,gif,png".toUpperCase().contains(suffix.toUpperCase())){
ret.put("type", "error");
ret.put("msg", "请选择jpg,jpeg,gif,png格式的图片!");
return ret;
}
String savePath = request.getServletContext().getRealPath("/") + "/resources/upload/";
File savePathFile = new File(savePath);
if(!savePathFile.exists()){
//若不存在改目录,则创建目录
savePathFile.mkdir();
}
String filename = new Date().getTime()+"."+suffix;
try {
//将文件保存至指定目录
photo.transferTo(new File(savePath+filename));
}catch (Exception e) {
// TODO Auto-generated catch block
ret.put("type", "error");
ret.put("msg", "保存文件异常!");
e.printStackTrace();
return ret;
}
ret.put("type", "success");
ret.put("msg", "图片上传成功!");
ret.put("filepath",request.getServletContext().getContextPath() + "/resources/upload/" + filename );
return ret;
}
/**
* 判断该用户名是否存在
* @param username
* @param id
* @return
*/
private boolean isExist(String username,Long id){
Account account = accountService.findByUsername(username);
if(account == null)return false;
orders.setAccount_Id(account.getId());
if(ordersService.add(orders)<=0)
{
ret.put("type", "error");
ret.put("msg", "订单提交失败!请联系管理员!");
return ret;
}
String[] split_id = ID.split(",");//以逗号分割
for (int i=0;i<split_id.length;i++) {
Shopping s = new Shopping();
s.setId(Long.parseLong(split_id[i]));
s.setState("已支付");
if(shoppingService.editState(s)<=0)
{
ret.put("type", "error");
ret.put("msg", "订单提交失败!请联系管理员!");
return ret;
}
}
for (int i=0;i<split_id.length;i++) {
Shopping s = shoppingService.findByShoppingId(Long.parseLong(split_id[i]));
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("num",s.getNum());
queryMap.put("id",s.getProductId());
if(teaService.editSaleNum(queryMap)<=0)
{
ret.put("type", "error");
ret.put("msg", "商品销售量刷新失败!请联系管理员!");
return ret;
}
if(teaService.editStockNum(queryMap)<=0)
{
ret.put("type", "error");
ret.put("msg", "商品库存量刷新失败!请联系管理员!");
return ret;
}
}
ret.put("type", "success");
ret.put("msg", "恭喜你下单成功!您可以去<我的订单>中查看订单详情!");
return ret;
}
/**
* 前端商品控制类
*
*/
@Controller
@RequestMapping("/home/product")
public class ShopProductController {
@Autowired
private TeaCategoryService teaCategoryService;
@Autowired
private TeaService teaService;
@Autowired
private LogService logService;
@Autowired
private View_LogService view_LogService;
@Autowired
private CommentService commentService;
@Autowired
private ShoppingService shoppingService;
/**
* 商品列表信息页面
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView index(ModelAndView model,Long categoryId,Page page,
Long price,Long sale,Long comment,Long flag,Long flag2,String name,
HttpServletRequest request){
Map<String, Object> queryMap = new HashMap<String, Object>();
model.addObject("teaCategoryList", teaCategoryService.findAll());
//如果从其他页面访问,商品种类权限重置下
if(flag2 != null)
}
/**
* 添加权限
* @param ids
* @return
*/
@RequestMapping(value="/add_authority",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> addAuthority(
@RequestParam(name="ids",required=true) String ids,
@RequestParam(name="roleId",required=true) Long roleId
){
Map<String,String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "请选择相应的权限!");
return ret;
}
if(roleId == null){
ret.put("type", "error");
ret.put("msg", "请选择相应的角色!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
String[] idArr = ids.split(",");
if(idArr.length > 0){
authorityService.deleteByRoleId(roleId);
}
for(String id:idArr){
Authority authority = new Authority();
authority.setMenuId(Long.valueOf(id));
authority.setRoleId(roleId);
authorityService.add(authority);
}
ret.put("type", "success");
ret.put("msg", "权限编辑成功!");
return ret;
}
/**
* 获取某个角色的所有权限
* @param roleId
* @return
*/
@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
/**
* 获取某个角色的所有权限
* @param roleId
* @return
*/
@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
@ResponseBody
public List<Authority> getRoleAuthority(
@RequestParam(name="roleId",required=true) Long roleId
){
return authorityService.findListByRoleId(roleId);
}
}
/**
* 菜单管理控制器
Map<String, Object> queryMap2 = new HashMap<String, Object>();
queryMap2.put("actionId", 2);
model.addObject("teaListByActionId", teaService.findList(queryMap2));
Account account = (Account) request.getSession().getAttribute("account");
Map<String, Object> queryMap3 = new HashMap<String, Object>();
queryMap3.put("accountId",account.getId());
queryMap3.put("state","未支付");
model.addObject("cartList",shoppingService.findList(queryMap3));
model.addObject("cartTotal",shoppingService.getTotal(queryMap3));
model.setViewName("home/account/collect");
return model;
}
/**
* 编辑账户信息
* @param user
* @return
*/
@RequestMapping(value="/edit_info",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit_info(Account account,HttpServletRequest request){
Map<String, String> ret = new HashMap<String, String>();
if(account == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的用户信息!");
return ret;
}
if(StringUtils.isEmpty(account.getUsername())){
ret.put("type", "error");
ret.put("msg", "请填写用户名!");
return ret;
}
if(StringUtils.isEmpty(account.getRealname())){
ret.put("type", "error");
ret.put("msg", "请填写真实姓名!");
return ret;
}
if(account.getPhone() == null){
ret.put("type", "error");
/**
* 角色role控制器
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
@Autowired
private UserService userService;
/**
* 角色列表页面
* @param model
* @return
*/
* @param username
* @param roleId
* @param sex
* @return
*/
@RequestMapping(value="/comment",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getComment(Page page,
@RequestParam(name="content",required=false,defaultValue="") String content
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("content", content);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", commentService.findList(queryMap));
ret.put("total", commentService.getTotal(queryMap));
return ret;
}
/**
* 获取用户列表
* @param page
* @param username
* @param roleId
* @param sex
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(Page page,
@RequestParam(name="username",required=false,defaultValue="") String username
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("username", username);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", accountService.findList(queryMap));
ret.put("total", accountService.getTotal(queryMap));
return ret;
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
if(logService.delete(ids) <= 0){
ret.put("type", "error");
ret.put("msg", "日志删除失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "日志删除成功!");
return ret;
}
}
/**
*前端系统用户登录控制类
*
*/
@Controller
@RequestMapping("/home")
public class ShopLoginController {