基于javaweb+mysql的springboot宠物领养寄养商城系统(java+springboot+html+bootstrap+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot宠物领养寄养商城系统(java+springboot+html+bootstrap+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项目:是;
技术栈
-
后端:SpringBoot+Mybatis
-
前端:HTML+CSS+Bootstrap+jQuery
使用说明
-
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
-
使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
- 将项目中application.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,登录地址:http://localhost:8089/login
管理员: admin/admin123
普通账户: liming/123456
try
{
// 获取被踢出的sessionId的session对象
Session kickoutSession = sessionManager.getSession(new DefaultSessionKey(kickoutSessionId));
if (null != kickoutSession)
{
// 设置会话的kickout属性表示踢出了
kickoutSession.setAttribute("kickout", true);
}
}
catch (Exception e)
{
// 面对异常,我们选择忽略
}
}
// 如果被踢出了,(前者或后者)直接退出,重定向到踢出后的地址
if ((Boolean) session.getAttribute("kickout") != null && (Boolean) session.getAttribute("kickout") == true)
{
// 退出登录
subject.logout();
saveRequest(request);
return isAjaxResponse(request, response);
}
return true;
}
catch (Exception e)
{
return isAjaxResponse(request, response);
}
}
private boolean isAjaxResponse(ServletRequest request, ServletResponse response) throws IOException
{
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
if (ServletUtils.isAjaxRequest(req))
{
AjaxResult ajaxResult = AjaxResult.error("您已在别处登录,请您修改密码或重新登录");
ServletUtils.renderString(res, objectMapper.writeValueAsString(ajaxResult));
}
else
{
WebUtils.issueRedirect(request, response, kickoutUrl);
}
return false;
}
public void setMaxSession(int maxSession)
/**
* 登录帐号控制过滤器
*
*/
public class KickoutSessionFilter extends AccessControlFilter
{
private final static ObjectMapper objectMapper = new ObjectMapper();
/**
* 同一个用户最大会话数
**/
private int maxSession = -1;
/**
* 踢出之前登录的/之后登录的用户 默认false踢出之前登录的用户
**/
private Boolean kickoutAfter = false;
/**
* 踢出后到的地址
**/
private String kickoutUrl;
private SessionManager sessionManager;
private Cache<String, Deque<Serializable>> cache;
@Override
protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o)
throws Exception
{
return false;
}
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception
{
Subject subject = getSubject(request, response);
if (!subject.isAuthenticated() && !subject.isRemembered() || maxSession == -1)
{
// 如果没有登录或用户最大会话数为-1,直接进行之后的流程
return true;
}
try
@GetMapping("/{bookName}")
public String front(@PathVariable("bookName") String bookName, ModelMap mmap) {
User user = ShiroUtils.getSysUser();
if (user != null) {
mmap.put("userName", user.getUserName());
} else {
mmap.put("userName", null);
}
Type type = new Type();
type.setTypeStatus("0");
List<Type> typeList = typeService.selectTypeList(type);
mmap.put("typeList", typeList);
Product product = new Product();
product.setProductName(bookName);
List<Product> productList = productService.selectProductList(product);
mmap.put("productList", productList);
return prefix + "/index";
}
/**
* 进入我要领养界面
*
* @return
*/
@GetMapping("/visit_recycle")
public String visitRecycle(ModelMap mmap) {
// 获取当前登陆人信息
User user = ShiroUtils.getSysUser();
if (user == null) {
return "login";
}
mmap.put("userName", user.getUserName());
// 获取流浪宠物的信息
Product product = new Product();
product.setProductType("宠物信息");
product.setPetType("流浪");
List<Product> productList = productService.selectProductList(product);
mmap.put("productList", productList);
return prefix + "/visitRecycle";
deque = new ArrayDeque<Serializable>();
}
// 如果队列里没有此sessionId,且用户没有被踢出;放入队列
if (!deque.contains(sessionId) && session.getAttribute("kickout") == null)
{
// 将sessionId存入队列
deque.push(sessionId);
// 将用户的sessionId队列缓存
cache.put(loginName, deque);
}
// 如果队列里的sessionId数超出最大会话数,开始踢人
while (deque.size() > maxSession)
{
Serializable kickoutSessionId = null;
// 是否踢出后来登录的,默认是false;即后者登录的用户踢出前者登录的用户;
if (kickoutAfter)
{
// 踢出后者
kickoutSessionId = deque.removeFirst();
}
else
{
// 踢出前者
kickoutSessionId = deque.removeLast();
}
// 踢出后再更新下缓存队列
cache.put(loginName, deque);
try
{
// 获取被踢出的sessionId的session对象
Session kickoutSession = sessionManager.getSession(new DefaultSessionKey(kickoutSessionId));
if (null != kickoutSession)
{
// 设置会话的kickout属性表示踢出了
kickoutSession.setAttribute("kickout", true);
}
}
catch (Exception e)
{
// 面对异常,我们选择忽略
}
{
List<Post> list = postService.selectPostList(post);
ExcelUtil<Post> util = new ExcelUtil<Post>(Post.class);
return util.exportExcel(list, "岗位数据");
}
@RequiresPermissions("system:post:remove")
@Log(title = "岗位管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
try
{
return toAjax(postService.deletePostByIds(ids));
}
catch (Exception e)
{
return error(e.getMessage());
}
}
/**
* 新增岗位
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存岗位
*/
@RequiresPermissions("system:post:add")
@Log(title = "岗位管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated Post post)
{
if (UserConstants.POST_NAME_NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
{
if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
{
return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
return toAjax(configService.insertConfig(config));
}
/**
* 修改参数配置
*/
@GetMapping("/edit/{configId}")
public String edit(@PathVariable("configId") Long configId, ModelMap mmap)
{
mmap.put("config", configService.selectConfigById(configId));
return prefix + "/edit";
}
/**
* 修改保存参数配置
*/
@RequiresPermissions("system:config:edit")
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated Config config)
{
if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
{
return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
return toAjax(configService.updateConfig(config));
}
/**
* 删除参数配置
*/
@RequiresPermissions("system:config:remove")
@Log(title = "参数管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids)
/**
* 修改订单管理
*/
@GetMapping("/edit/{orderId}")
public String edit(@PathVariable("orderId") Long orderId, ModelMap mmap)
{
Order order = orderService.selectOrderById(orderId);
mmap.put("order", order);
return prefix + "/edit";
}
/**
* 修改订单管理
*/
@GetMapping("/pay/{orderId}")
public String pay(@PathVariable("orderId") Long orderId, ModelMap mmap)
{
Order order = orderService.selectOrderById(orderId);
mmap.put("order", order);
return prefix + "/pay";
}
@GetMapping("/comment/{orderId}")
public String comment(@PathVariable("orderId") Long orderId, ModelMap mmap)
{
Order order = orderService.selectOrderById(orderId);
mmap.put("order", order);
return prefix + "/comment";
}
/**
* 修改保存订单管理
*/
@Log(title = "订单管理", businessType = BusinessType.UPDATE)
@PostMapping("/comment")
@ResponseBody
public AjaxResult commentSave(Order order)
{
Order saveOrder = orderService.selectOrderById(order.getOrderId());
saveOrder.setOrderComment(order.getOrderComment());
saveOrder.setOrderCommentTime(new Date());
saveOrder.setOrderStatus("5");
/**
* 修改寄养订单管理
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id, ModelMap mmap)
{
SysParkpetOrder sysParkpetOrder = sysParkpetOrderService.selectSysParkpetOrderById(id);
mmap.put("sysParkpetOrder", sysParkpetOrder);
return prefix + "/edit";
}
/**
* 修改保存寄养订单管理
*/
@Log(title = "寄养订单管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(SysParkpetOrder sysParkpetOrder)
{
return toAjax(sysParkpetOrderService.updateSysParkpetOrder(sysParkpetOrder));
}
/**
* 删除寄养订单管理
*/
@Log(title = "寄养订单管理", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(sysParkpetOrderService.deleteSysParkpetOrderByIds(ids));
}
}
ExcelUtil<User> util = new ExcelUtil<User>(User.class);
List<User> userList = util.importExcel(file.getInputStream());
String message = userService.importUser(userList, updateSupport);
return AjaxResult.success(message);
}
@RequiresPermissions("system:user:view")
@GetMapping("/importTemplate")
@ResponseBody
public AjaxResult importTemplate()
{
ExcelUtil<User> util = new ExcelUtil<User>(User.class);
return util.importTemplateExcel("用户数据");
}
/**
* 新增用户
*/
@GetMapping("/add")
public String add(ModelMap mmap)
{
mmap.put("roles", roleService.selectRoleAll());
mmap.put("posts", postService.selectPostAll());
return prefix + "/add";
}
/**
* 新增保存用户
*/
@RequiresPermissions("system:user:add")
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated User user)
{
if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user.getLoginName())))
{
return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在");
}
else if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
{
return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在");
}
else if (UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
{
if (menuService.selectCountRoleMenuByMenuId(menuId) > 0)
{
return AjaxResult.warn("菜单已分配,不允许删除");
}
return toAjax(menuService.deleteMenuById(menuId));
}
/**
* 新增
*/
@GetMapping("/add/{parentId}")
public String add(@PathVariable("parentId") Long parentId, ModelMap mmap)
{
Menu menu = null;
if (0L != parentId)
{
menu = menuService.selectMenuById(parentId);
}
else
{
menu = new Menu();
menu.setMenuId(0L);
menu.setMenuName("主目录");
}
mmap.put("menu", menu);
return prefix + "/add";
}
/**
* 新增保存菜单
*/
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
@RequiresPermissions("system:menu:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated Menu menu)
{
if (UserConstants.MENU_NAME_NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
{
return error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
return userService.checkPhoneUnique(user);
}
/**
* 校验email邮箱
*/
@PostMapping("/checkEmailUnique")
@ResponseBody
public String checkEmailUnique(User user)
{
return userService.checkEmailUnique(user);
}
/**
* 用户状态修改
*/
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@RequiresPermissions("system:user:edit")
@PostMapping("/changeStatus")
@ResponseBody
public AjaxResult changeStatus(User user)
{
userService.checkUserAllowed(user);
return toAjax(userService.changeStatus(user));
}
}
final byte b1 = addr[1];
// 10.x.x.x/8
final byte SECTION_1 = 0x0A;
// 172.16.x.x/12
final byte SECTION_2 = (byte) 0xAC;
final byte SECTION_3 = (byte) 0x10;
final byte SECTION_4 = (byte) 0x1F;
// 192.168.x.x/16
final byte SECTION_5 = (byte) 0xC0;
final byte SECTION_6 = (byte) 0xA8;
switch (b0)
{
case SECTION_1:
return true;
case SECTION_2:
if (b1 >= SECTION_3 && b1 <= SECTION_4)
{
return true;
}
case SECTION_5:
switch (b1)
{
case SECTION_6:
return true;
}
default:
return false;
}
}
/**
* 将IPv4地址转换成字节
*
* @param text IPv4地址
* @return byte 字节
*/
public static byte[] textToNumericFormatV4(String text)
{
if (text.length() == 0)
{
return null;
{
startPage();
List<Message> list = messageService.selectMessageList(message);
return getDataTable(list);
}
/**
* 导出留言管理列表
*/
@RequiresPermissions("system:message:export")
@Log(title = "留言管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(Message message)
{
List<Message> list = messageService.selectMessageList(message);
ExcelUtil<Message> util = new ExcelUtil<Message>(Message.class);
return util.exportExcel(list, "message");
}
/**
* 新增留言管理
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增留言管理
*/
@GetMapping("/replyMessage/{messageId}")
public String replyMessage(@PathVariable("messageId") Long messageId, ModelMap mmap)
{
Message message = messageService.selectMessageById(messageId);
mmap.put("message", message);
return prefix + "/replyMessage";
}
@Log(title = "留言回复", businessType = BusinessType.UPDATE)
@PostMapping("/replyMessage")
@ResponseBody
public AjaxResult replyMessage(Message message){
Message saveMessage = messageService.selectMessageById(message.getMessageId());
saveMessage.setMessageReply(message.getMessageReply());
saveMessage.setMessageReplyTime(new Date());
return toAjax(messageService.updateMessage(saveMessage));
}
/**
/**
* 部门信息
*
*/
@Controller
@RequestMapping("/system/dept")
public class DeptController extends BaseController
{
private String prefix = "system/dept";
@Autowired
private IDeptService deptService;
@RequiresPermissions("system:dept:view")
@GetMapping()
public String dept()
{
return prefix + "/dept";
}
@RequiresPermissions("system:dept:list")
@PostMapping("/list")
@ResponseBody
public List<Dept> list(Dept dept)
{
List<Dept> deptList = deptService.selectDeptList(dept);
return deptList;
}
/**
* 新增部门
*/
/**
* 订单管理Controller
*
*/
@Controller
@RequestMapping("/system/order")
public class OrderController extends BaseController
{
private String prefix = "system/order";
@Autowired
private IOrderService orderService;
@Autowired
private IRoleService roleService;
@Autowired
private IProductService productService;
@Autowired
private IUserService userService;
@Autowired
private ICartService cartService;
@RequiresPermissions("system:order:view")
@GetMapping()
public String order(ModelMap mmap)
{
User user = ShiroUtils.getSysUser();
String roleString = roleService.selectRoleKeys(user.getUserId()).toString();
if(roleString.contains("admin")){
mmap.put("loginRole", "admin");
}else if(roleString.contains("seller")){
User user = ShiroUtils.getSysUser();
if (user != null) {
mmap.put("userName", user.getUserName());
} else {
mmap.put("userName", null);
}
Type type = new Type();
type.setTypeStatus("0");
List<Type> typeList = typeService.selectTypeList(type);
mmap.put("typeList", typeList);
Product product = productService.selectProductById(productId);
mmap.put("product", product);
Order queryOrder = new Order();
queryOrder.setOrderStatus("5");
queryOrder.setProductId(productId);
List<Order> productOrder = orderService.selectOrderList(queryOrder);
mmap.put("productOrder", productOrder);
Message queryMessage = new Message();
queryMessage.setProductId(productId);
List<Message> messageList = messageService.selectMessageList(queryMessage);
mmap.put("messageList", messageList);
return prefix + "/product";
}
/**
* 进入视频秀界面
* @param mmap
* @return
*/
@GetMapping("/videoShow")
public String videoShow(ModelMap mmap) {
User user = ShiroUtils.getSysUser();
if (user != null) {
mmap.put("userName", user.getUserName());
}
List<SysVideo> videos = sysVideoService.selectSysVideoList(new SysVideo());
/**
* 新增角色
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存角色
*/
@RequiresPermissions("system:role:add")
@Log(title = "角色管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated Role role)
{
if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
else if (UserConstants.ROLE_KEY_NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
{
return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
}
return toAjax(roleService.insertRole(role));
}
/**
* 修改角色
*/
@GetMapping("/edit/{roleId}")
public String edit(@PathVariable("roleId") Long roleId, ModelMap mmap)
{
mmap.put("role", roleService.selectRoleById(roleId));
return prefix + "/edit";
}
/**
* 修改保存角色
*/
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated Role role)
{
roleService.checkRoleAllowed(role);
if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
{
return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
public String edit(@PathVariable("id") Long id, ModelMap mmap)
{
SysRecycleOrder sysRecycleOrder = sysRecycleOrderService.selectSysRecycleOrderById(id);
mmap.put("sysRecycleOrder", sysRecycleOrder);
return prefix + "/edit";
}
/**
* 修改保存回收订单信息
*/
@Log(title = "回收订单信息", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(SysRecycleOrder sysRecycleOrder)
{
return toAjax(sysRecycleOrderService.updateSysRecycleOrder(sysRecycleOrder));
}
/**
* 客户取消自己的订单
*/
@Log(title = "回收订单信息", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(Long ids)
{
SysRecycleOrder sysRecycleOrder = sysRecycleOrderService.selectSysRecycleOrderById(ids);
sysRecycleOrder.setStatus("订单已取消");
// 更新订单状态
return toAjax(sysRecycleOrderService.updateSysRecycleOrder(sysRecycleOrder));
}
}