博主主页:Java旅途
简介:分享计算机知识、学习路线、系统源码及教程
文末获取源码
旅游网站是由SpringBoot+Mybatis开发的,旅游网站分为前台和后台,前台为用户浏览,后台进行数据管理
后台功能如下:
前台功能如下:
用idea打开项目
在idea中配置jdk环境
配置maven环境并下载依赖
新建数据库,导入数据库文件
在application.yml文件中将数据库账号密码改成自己本地的
静态资源路径修改,找到application.yml中的uploadPath: xxx\target\classes\static按以下方式修改
# xxx表示你本地项目的根目录,从磁盘开始复制到项目名字
# 比如我本地的项目在F:\biyesheji\travel,那么xxx在用F:\biyesheji\travel替换
启动运行
前台
地址:http://localhost/index
账号:user 密码:123456
后台
地址:http://localhost/login
账号:admin 密码:123456
LoginController
package com.cn.travel.web.manager;
import com.cn.travel.role.admin.entity.Admin;
import com.cn.travel.role.admin.service.imp.AdminService;
import com.cn.travel.utils.Tools;
import com.cn.travel.web.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpServletRequest;
@Controller
public class LoginController extends BaseController {
@Autowired
AdminService adminService;
@RequestMapping("/login")
public String login(HttpServletRequest request){
Object user = request.getSession().getAttribute("admin");
if (user != null) {
return REDIRECT+"/manager/index";
}
return "login";
}
@RequestMapping("/loging")
public String loging(String userName,String password,RedirectAttributes redirectAttributes,HttpServletRequest request){
if (Tools.isEmpty(userName)||Tools.isEmpty(password)){
redirectAttributes.addFlashAttribute("message","用户名密码不得为空!");
return REDIRECT+"/login";
}
try {
Admin admin = adminService.login(userName, password);
if (Tools.isEmpty(admin)){
redirectAttributes.addFlashAttribute("message","用户名不存在或密码错误!");
return REDIRECT+"/login";
}else{
if (admin.getState() == 1) {
request.getSession().setAttribute("admin", admin);
return REDIRECT+"/manager/index";
} else {
redirectAttributes.addFlashAttribute("message","账户已被停用!");
return REDIRECT+"/login";
}
}
} catch (Exception e) {
e.printStackTrace();
}
return REDIRECT+"/login";
}
@RequestMapping("/logout")
public String logout(HttpServletRequest request){
Object user = request.getSession().getAttribute("admin");
if (user != null) {
request.getSession().removeAttribute("admin");
}
return "/login";
}
}
OrderPortalController
package com.cn.travel.web.portal;
import com.cn.travel.cms.order.entity.Order;
import com.cn.travel.cms.order.service.imp.OrderService;
import com.cn.travel.role.user.entity.User;
import com.cn.travel.role.user.service.imp.UserService;
import com.cn.travel.web.base.BaseController;
import com.cn.travel.web.base.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
@Controller
public class OrderPortalController extends BaseController {
@Autowired
UserService userService;
@Autowired
OrderService orderService;
@RequestMapping("/myOrder")
public ModelAndView myOrder(HttpSession httpSession,
@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = "7") int pageSize
) throws Exception {
ModelAndView mv = this.getModeAndView();
User user = userService.findByUserName(httpSession.getAttribute("userName").toString());
PageParam pageParam = orderService.findByPageByUserId(pageNum,pageSize,user.getId());
mv.addObject("pageData", pageParam.getResult());
mv.addObject("pageParam",pageParam);
mv.setViewName("portal/myOrder");
return mv;
}
@RequestMapping("/payOrder")
public String payOrder(String id) throws Exception {
Order order = orderService.findById(id);
order.setState(1);
orderService.update(order);
return REDIRECT+"/myOrder";
}
@RequestMapping("/deleteOrder")
public String deleteOrder(String id) throws Exception {
Order order = orderService.findById(id);
order.setState(2);
orderService.update(order);
return REDIRECT+"/myOrder";
}
}
大家点赞、收藏、关注、评论啦 、点开下方卡片关注后回复 103