基于javaweb的景点门票预订管理系统(java+ssm+jsp+bootstrap+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的景点门票预订管理系统(java+SSM+JSP+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版本;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+bootstrap+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/
用户管理控制层:
@Controller
@RequestMapping(“/user.do”)
public class UserController {
@Autowired
private UserService userService;
@Autowired
private TouristService touristService;
@Autowired
private OrdersService ordersService;
@RequestMapping(params=“method=getAllUser”)
public ModelAndView getAllUser(HttpServletRequest request,HttpServletResponse reponse){
ModelAndView mav = new ModelAndView();
mav.setViewName(“admin/allUser”);
return mav;
@RequestMapping(params=“method=checkAllUser”)
public ModelAndView checkAllUser(HttpServletRequest request,HttpServletResponse reponse){
ModelAndView mav = new ModelAndView();
mav.setViewName(“admin/checkUserList”);
return mav;
@RequestMapping(params=“method=getCheckUserData”)
public ModelAndView getCheckUserData(HttpServletRequest request,HttpServletResponse response,@ModelAttribute User user){
List findAll = new ArrayList();
JSONObject obj = new JSONObject();
try{
if(user.getUsername()!=null&&StringUtils.isBlank(user.getUsername())){
user.setUsername(null);
user.setState(0);
findAll = userService.findAll(user);
catch(Exception e){
obj.put(“rows”, findAll);
obj.put(“total”, findAll.size());
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=getUserData”)
public ModelAndView getUserData(HttpServletRequest request,HttpServletResponse response,@ModelAttribute User user){
List findAll = new ArrayList();
JSONObject obj = new JSONObject();
try{
if(user.getUsername()!=null&&StringUtils.isBlank(user.getUsername())){
user.setUsername(null);
user.setState(1);
findAll = userService.findAll(user);
obj.put(“rows”, findAll);
obj.put(“total”, findAll.size());
catch(Exception e){
obj.put(“rows”, findAll);
obj.put(“total”, findAll.size());
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=addUser”)
public ModelAndView addUser(HttpServletRequest request,HttpServletResponse response,@ModelAttribute User user){
response.setContentType(“text/html;charset=utf-8”);
JSONObject obj = new JSONObject();
user.setRole(0);
user.setState(0);
try{
userService.save(user);
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “恭喜你,操作成功”);
catch(Exception e){
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “添加用户失败”);
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=toAddUser”)
public ModelAndView toAddUser(HttpServletRequest request,HttpServletResponse response){
ModelAndView mav = new ModelAndView();
mav.setViewName(“admin/userAdd”);
return mav;
@RequestMapping(params=“method=toEditUser”)
public ModelAndView toEditUser(HttpServletRequest request,HttpServletResponse response){
ModelAndView mav = new ModelAndView();
mav.setViewName(“admin/userEdit”);
return mav;
@RequestMapping(params=“method=toCheckUser”)
public ModelAndView toCheckUser(HttpServletRequest request,HttpServletResponse response){
ModelAndView mav = new ModelAndView();
mav.setViewName(“admin/userCheck”);
return mav;
@RequestMapping(params=“method=getUser”)
public ModelAndView getUser(HttpServletRequest request,HttpServletResponse response){
ModelAndView mav = new ModelAndView();
mav.setViewName(“editUser”);
return mav;
@RequestMapping(params=“method=findUser”)
public ModelAndView findUser(HttpServletRequest request,HttpServletResponse response){
int id =Integer.valueOf(request.getParameter(“id”));
User user = userService.findById(id);
return CommonResponse.JsonAjax(JSONObject.fromObject(user).toString());
@RequestMapping(params=“method=delUser”)
public ModelAndView delUser(HttpServletRequest request,HttpServletResponse response){
JSONObject obj = new JSONObject();
try{
int id=Integer.valueOf(String.valueOf(request.getParameter(“id”)));
if(userService.delete(id)){
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “恭喜你,操作成功”);
else{
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “删除用户失败”);
catch(Exception e){
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “删除用户失败”);
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=updateUser”)
public ModelAndView updateUser(User user,HttpServletRequest request){
JSONObject obj = new JSONObject();
try{
if(userService.update(user)){
user = userService.findById(user.getId());
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “恭喜你,操作成功”);
}else{
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “添加用户失败”);
catch(Exception ex){
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “添加用户失败”);
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=updateCheckUser”)
public ModelAndView updateCheckUser(User user,HttpServletRequest request){
JSONObject obj = new JSONObject();
try{
user.setState(1);
if(userService.update(user)){
user = userService.findById(user.getId());
request.setAttribute(“user”, user);
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “恭喜你,操作成功”);
}else{
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “添加用户失败”);
catch(Exception ex){
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “添加用户失败”);
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=buyTicket”)
public ModelAndView buyTicket(int id, String date, HttpServletRequest request){
JSONObject obj = new JSONObject();
User user = (User) request.getSession().getAttribute(“user”);
if (user == null) {
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “请先登录!”);
return CommonResponse.JsonAjax(obj.toString());
Tourist con = new Tourist();
con.setId(id);
Tourist tourist = touristService.findTourist(con);
Orders order = new Orders();
order.setCreatetime(DateUtil.parseDateTimeToString(new Date()));
order.setPrice(tourist.getPrice());
order.setTouristid(id);
order.setTouristname(tourist.getName());
order.setUserid(user.getId());
order.setUsername(user.getUsername());
order.setStatus(“未付款”);
order.setTicketdate(date);
try{
ordersService.save(order);
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “下单成功”);
catch(Exception ex){
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “下单失败”);
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=payOrder”)
public ModelAndView payOrder(int id,HttpServletRequest request){
JSONObject obj = new JSONObject();
Orders order = ordersService.findById(id);
order.setStatus(“已付款”);
try{
ordersService.update(order);
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “付款成功”);
catch(Exception ex){
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “付款失败”);
return CommonResponse.JsonAjax(obj.toString());
登录管理控制层:
@Controller
@RequestMapping(“/login.do”)
public class LoginController {
@Autowired
private UserService userService;
@RequestMapping(params=“method=Index”)
public ModelAndView Index(HttpServletRequest request,HttpServletResponse response){
ModelAndView mav = new ModelAndView();
User user = (User)request.getSession().getAttribute(“user”);
if(user!=null){
if(user.getRole()==1&&user.getState()==1){
mav.setViewName(“admin/index”);
mav.addObject(“user”, user);
else{
mav.setViewName(“redirect:home.do?method=homeIndex”);
if(user.getState()==1){
mav.addObject(“user”,user);
else{
mav.setViewName(“redirect:login.do?method=Login”);
return mav;
@RequestMapping(params=“method=Login”)
public ModelAndView Login(HttpServletRequest request,HttpServletResponse response){
ModelAndView mav = new ModelAndView();
User user = (User)request.getSession().getAttribute(“user”);
if(user!=null){
mav.setViewName(“redirect:login.do?method=Index”);
else{
mav.setViewName(“admin/login”);
return mav;
@RequestMapping(params=“method=checkLogin”)
private ModelAndView checkLogin(HttpServletRequest request,HttpServletResponse response){
String username=request.getParameter(“username”);
String password=request.getParameter(“password”);
JSONObject obj = new JSONObject();
HttpSession session = request.getSession();
try{
User user = this.userService.findByUsername(username);
if(user!=null){
if(user.getPassword().equals(password)){
obj.put(“code”, 1);
obj.put(“referer”, “login.do?method=Index”);
session.setAttribute(“user”, user);
else{
obj.put(“code”, -1);
else{
obj.put(“code”, -1);
catch(Exception e){
obj.put(“code”, -1);
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=Loginout”)
public ModelAndView Loginout(HttpServletRequest request,HttpServletResponse response){
HttpSession session = request.getSession();
session.removeAttribute(“user”);
ModelAndView mav = new ModelAndView();
mav.setViewName(“redirect:login.do?method=Login”);
return mav;
酒店管理控制层:
@Controller
@RequestMapping(“/hotel.do”)
public class HotelController {
@Autowired
private HotelService hotelService;
@RequestMapping(params=“method=touristMain”)
public ModelAndView touristMain(HttpServletRequest request,HttpServletResponse response){
ModelAndView mav = new ModelAndView();
mav.setViewName(“admin/hotelMain”);
return mav;
@RequestMapping(params=“method=touristMainData”)
public ModelAndView touristMainData(HttpServletRequest request,HttpServletResponse response,@ModelAttribute Hotel tourist){
response.setContentType(“text/html;charset=utf-8”);
List list = new ArrayList();
JSONObject obj = new JSONObject();
try{
if(StringUtils.isBlank(tourist.getName())){
tourist.setName(null);
list=this.hotelService.findHotelList(tourist);
catch(Exception e){
obj.put(“rows”, list);
obj.put(“total”, list.size());
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=toAddTourist”)
public ModelAndView toAddTourist(HttpServletRequest request,HttpServletResponse response){
ModelAndView mav = new ModelAndView();
mav.setViewName(“admin/hotelAdd”);
return mav;
@RequestMapping(params=“method=addTourist”)
public ModelAndView addTourist(HttpServletRequest request,HttpServletResponse response,@ModelAttribute Hotel tourist){
response.setContentType(“text/html;charset=utf-8”);
JSONObject obj = new JSONObject();
try{
this.hotelService.save(tourist);
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “恭喜你,添加酒店成功”);
catch(Exception ex){
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “添加酒店失败”);
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=toEditTourist”)
public ModelAndView toEditTourist(HttpServletRequest request,HttpServletResponse response){
ModelAndView mav = new ModelAndView();
mav.setViewName(“admin/hotelEdit”);
return mav;
@RequestMapping(params=“method=findTourist”)
public ModelAndView findTourist(HttpServletRequest request,HttpServletResponse response){
response.setContentType(“text/html;charset=utf-8”);
Hotel tourist = new Hotel();
try{
int id =Integer.valueOf(request.getParameter(“id”));
Hotel bean = new Hotel();
bean.setId(id);
tourist=this.hotelService.findHotelinfo(bean);
catch(Exception ex){
return CommonResponse.JsonAjax(JSONObject.fromObject(tourist).toString());
@RequestMapping(params=“method=updateTourist”)
public ModelAndView updateTourist(HttpServletRequest request,HttpServletResponse response,@ModelAttribute Hotel tourist){
response.setContentType(“text/html;charset=utf-8”);
JSONObject obj = new JSONObject();
try{
if(this.hotelService.update(tourist)){
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “恭喜你,操作成功”);
else{
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “更新酒店失败”);
catch(Exception ex){
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “更新酒店失败”);
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params=“method=deleteTourist”)
public ModelAndView deleteTourist(HttpServletRequest request,HttpServletResponse response,@ModelAttribute Hotel tourist){
response.setContentType(“text/html;charset=utf-8”);
JSONObject obj = new JSONObject();
try{
if(this.hotelService.delete(tourist)){
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “恭喜你,操作成功”);
else{
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “删除酒店失败”);
catch(Exception ex){
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “删除酒店失败”);
return CommonResponse.JsonAjax(obj.toString());
@RequestMapping(params = “method=fileUpLoad”)
//btnFile对应页面的name属性
public ModelAndView fileUpLoad(MultipartFile file, HttpServletRequest request, HttpServletResponse response){
response.setContentType(“text/html;charset=utf-8”);
JSONObject obj = new JSONObject();
try{
String path = request.getSession().getServletContext().getRealPath(“uploads”);
//上传文件名
String filename = new Date().getTime()+“_”+file.getOriginalFilename();
File filepath = new File(path,filename);
//判断路径是否存在,如果不存在就创建一个
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path + File.separator + filename));
obj.put(“statusCode”, 200);
obj.put(“title”, “操作提示”);
obj.put(“message”, “上传文件成功”);
obj.put(“filePath”, filename);
// OutputUtil.jsonOutPut(response, null);
}catch (Exception e) {
// OutputUtil.errorOutPut(response, “系统异常”);
obj.put(“statusCode”, 201);
obj.put(“title”, “操作提示”);
obj.put(“message”, “上传文件失败”);
return CommonResponse.JsonAjax(obj.toString());