基于Spring+SpringMvc+Hibernate的旅游网站

JavaWeb项目:基于Spring+SpringMvc+Hibernate的旅游网站
此项目为本人的Java大作业。
前台代码;代码已经上传到github上 下载地址   Github 
一、项目概况
1.1设计内容
  基于Spring+SpringMvc+Hibernate的旅游网站,分用户和管理员两种身份。此系统开发期间我们小组不定时地进行用户使用反馈信息收集,根据收集数据不断对系统进行优化、完善。目的是希望从使用者的角度查找系统的缺陷之处,继而使得整个系统的运行、结构更加清晰化、条理化、自动化。

1.2开发工具
  Eclipse或者Myeclipse,Java,MySQL,Redis,Html,CSS,JS。
二、详细设计
图4-1 用户应用顺序图

基于Spring+SpringMvc+Hibernate的旅游网站
功能模块图:如图4-2所示。

基于Spring+SpringMvc+Hibernate的旅游网站

 

 

图4-2 功能模块图
4.3 模块功能实现
1、主界面
主界面提供了很多的按钮,只要你点击想要查看的窗口,就可以随意进入,其中的更改用户可以让你回到登录界面重新登录,重新判断用户的权限,如图4-5所示。

图4-5 主界面显示

基于Spring+SpringMvc+Hibernate的旅游网站
此窗口中的信息添加,修改和删除都是只能由管理人员使用,一般用户只能查看翻阅基本资料。用户可以看到最新的信息,了解旅游地区的信息,如图4-6所示。

图4-6 旅游详细信息

基于Spring+SpringMvc+Hibernate的旅游网站
4、旅游线路信息窗口
此窗口是本系统最核心的设计,它提供给用户路线的选择和详细资料。你可以通过属性来选择。如果用户想更快地查到自己向往的旅游地点,也可以直接输入城市的名称,即可完成路线查找。若没有用户希望的旅游路线,旅游网站可以根据用户的要求,并结合导游、景点情况以及开发的前景预测适当新增或修改路线,尽量完成用户的愿望。当然,如果有的路线开发不合理,经过一段时间的试运营后可以删除,如图4-7所示。

基于Spring+SpringMvc+Hibernate的旅游网站

图4-7 旅游线路信息窗口
5、会员注册及登录窗口
用户通过了解景点信息窗口中的路线,做出自己的选择,就可以把个人基本信息告诉旅游网站以便统一管理和相互的联系。旅游网站就可以及时与用户取得联系,商量响应处理地方法,如下图所示。

会员登录界面

基于Spring+SpringMvc+Hibernate的旅游网站
网站主要界面

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站
票选线路

基于Spring+SpringMvc+Hibernate的旅游网站
线路查询

基于Spring+SpringMvc+Hibernate的旅游网站
线路预定

基于Spring+SpringMvc+Hibernate的旅游网站
会员查看预定信息

基于Spring+SpringMvc+Hibernate的旅游网站

会员登录修改个人信息

基于Spring+SpringMvc+Hibernate的旅游网站

管理员登录

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

 

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

基于Spring+SpringMvc+Hibernate的旅游网站

 

package com.sise.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sise.po.*;
import com.sise.service.*;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.*;

import javax.servlet.Registration;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.SimpleFormatter;

/**
* @Author:swye
* @Description:
* @Date:Create in 14:43 2018/2/4
*/
@Controller
@RequestMapping("/common")
public class CommonController {
  @Autowired
  private RegistrationTableService registrationTableService;

  @Autowired
  private ConsumerService consumerService;

  @Autowired
  private EmployeeService employeeService;

  @Autowired
  private TrackingInfoService trackingInfoService;

  @Autowired
  private CancelTableService cancelTableService;

  @Autowired
  private LoginService loginService;

  @RequestMapping(value = "/consumer_management",method = RequestMethod.GET)
  public String goConsumer_management(@RequestParam(value = "startTime",defaultValue = "",required = false) String startTime,@RequestParam(value = "endTime",defaultValue = "",required = false) String endTime,@RequestParam(value = "sname",defaultValue = "",required = false) String sname,
                    @RequestParam(value = "provinceId",defaultValue = "0",required = false) Integer provinceId,@RequestParam(value = "cityId",defaultValue = "0",required = false) Integer cityId,Model model,@RequestParam(defaultValue = "1",required = false) Integer pageNum,HttpSession session){
    SearchContent searchContent =new SearchContent();
    System.out.println(sname);
    if (!startTime.equals(""))
      searchContent.setStartTime(Date.valueOf(startTime));
    if (!endTime.equals(""))
      searchContent.setEndTime(Date.valueOf(endTime));
    if (sname!=null)
      searchContent.setSname(sname);
    if (provinceId !=null)
      searchContent.setProvinceId(provinceId);
    if (cityId!=null)
      searchContent.setCityId(cityId);
    Employee employee = (Employee) session.getAttribute("employee");
    searchContent.setEmployee(employee);
    System.out.println(searchContent.toString());
    PageHelper.startPage(pageNum, 8);
    List<RegistrationTable> registrationTables =registrationTableService.searchRegistrationWithSearchContentByStatus(1,searchContent);
    PageInfo<RegistrationTable> pageInfo = new PageInfo<RegistrationTable>(registrationTables);
    List<Integer> days = new ArrayList<Integer>();
    for (RegistrationTable r:registrationTables){
      Integer day = calculateDate(r.getNotrackingDays());
      r.setDays(day);
    }
    List<Province> provinces = consumerService.searchAllProvince();
    model.addAttribute("provinces",provinces);
    model.addAttribute("registrationTables",registrationTables);
    model.addAttribute("pageInfo",pageInfo);
    model.addAttribute("searchContent",searchContent);
    return "common_control/consumer_management";

  }


  /*前往登录表*/
  @RequestMapping(value = "/consumer_register")
  public String goConsumer_register( Model model){

    List<Province> provinces = consumerService.searchAllProvince();
    model.addAttribute("provinces",provinces);
    return "common_control/consumer_register";
  }

  @RequestMapping("/designate_designer")
  public String goDesignate_designer(@RequestParam(defaultValue = "1",required = false) Integer pageNum,Model model,@RequestParam(required = false,defaultValue = "",value = "search") String search){
    List<Employee> employees = new ArrayList<Employee>();

    if (search.equals("") || search ==null){
      PageHelper.startPage(pageNum, 8);
      employees = employeeService.searchAllDesigner();
      PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees);
      model.addAttribute("pageInfo",pageInfo);
    }else {
      PageHelper.startPage(pageNum, 8);
      employees= employeeService.searchEmployBySearch(search);
      PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees);
      model.addAttribute("pageInfo",pageInfo);
    }
    model.addAttribute("employees",employees);
    return "common_control/designate_designer";
  }
  /*返回指定设计师数据*/
  @RequestMapping(value = "/getDesigner" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String getDesigner(@RequestBody String requestdata){
    JSONObject jsonObject = JSONObject.fromObject(requestdata);
    Integer pageNum = Integer.parseInt(jsonObject.getString("pageNum"));
    String search =jsonObject.getString("search");
    List list = new ArrayList();
    if (search.equals("")){
      List<Employee> employees = new ArrayList<Employee>();
      PageHelper.startPage(pageNum, 5);
      employees = employeeService.searchAllDesigner();
      PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees);
      list.add(pageInfo);
      list.add(employees);
    }else {
      List<Employee> employees = new ArrayList<Employee>();
      PageHelper.startPage(pageNum, 5);
      employees= employeeService.searchEmployBySearch(search);
      PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees);
      list.add(pageInfo);
      list.add(employees);
    }
    Gson gson = new Gson();
    String result = gson.toJson(list);
    return result;
  }

  /*返回指定市场人员数据*/
  @RequestMapping(value = "/getMarketer" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String getMarketer(@RequestBody String requestdata){
    JSONObject jsonObject = JSONObject.fromObject(requestdata);
    Integer pageNum = Integer.parseInt(jsonObject.getString("pageNum"));
    String search =jsonObject.getString("search");
    List list = new ArrayList();
    if (search.equals("")){
      List<Employee> employees = new ArrayList<Employee>();
      PageHelper.startPage(pageNum, 5);
      employees = employeeService.searchAllMarketer();
      PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees);
      list.add(pageInfo);
      list.add(employees);
    }else {
      List<Employee> employees = new ArrayList<Employee>();
      PageHelper.startPage(pageNum, 5);
      employees= employeeService.searchMarketerBySearch(search);
      PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees);
      list.add(pageInfo);
      list.add(employees);
    }
    Gson gson = new Gson();
    String result = gson.toJson(list);
    return result;
  }


  @RequestMapping("getConsumer")
  @ResponseBody
  public String getConsumer(@RequestParam("userName") String userName){

    return "";
  }
  /*返回提交登记数据*/
  @RequestMapping(value = "/doregistration" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String doregistration(@RequestBody RegistrationTable registrationTable){
    Integer column = registrationTableService.saveRegistration(registrationTable);
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("result","true");
    return jsonObject.toString();
  }

  public Integer calculateDate(Date date){
    long from = date.getTime();
    long to = new Date(System.currentTimeMillis()).getTime();
    Integer days = (int) ((to - from)/(1000 * 60 * 60 * 24));
    return days;
  }
  /*返回指定设计师和市场人员数据*/
  @RequestMapping(value = "/management_setdesigner" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String management_setdesigner(@RequestBody String requestdata){
    JSONObject jsonObject = JSONObject.fromObject(requestdata);
    Integer employeeId = Integer.parseInt(jsonObject.getString("employeeId"));
    Integer registrationId = Integer.parseInt(jsonObject.getString("registrationId"));
    Integer versionA = Integer.parseInt(jsonObject.getString("version"));
    Integer version = registrationTableService.seeVersion(registrationId);
    String result = "";
    if (versionA>=version){
      Integer column = registrationTableService.setDesigner(employeeId,registrationId,version+1);
      registrationTableService.changStatusByRegistrationId(registrationId,2);
      result = "指定成功,客户已成为意向客户";
    }else{
      result = "指定失败,当前数据已被其他人修改";
    }
    JSONObject jsonObject1 = new JSONObject();
    jsonObject.put("result",result);
    return jsonObject.toString();
  }

  @RequestMapping("/tracking_info")
  public String goTrackingInfo(@RequestParam(defaultValue = "1",required = false) Integer pageNum,Model model,@RequestParam("registrationId") Integer registrationId,@RequestParam("employeeId") Integer employeeId){
    RegistrationTable registrationTable = registrationTableService.searchRegistrationById(registrationId);
    PageHelper.startPage(pageNum, 8);
    List<TrackingInfo> trackingInfos = trackingInfoService.searchTrackingInfoByRegistrationId(registrationId);
    PageInfo<TrackingInfo> pageInfo = new PageInfo<TrackingInfo>(trackingInfos);
    Employee employee = employeeService.searchEmployeeById(employeeId);
    model.addAttribute("trackingInfos",trackingInfos);
    model.addAttribute("pageInfo",pageInfo);
    model.addAttribute("registration",registrationTable);
    model.addAttribute("employee",employee);
    return "common_control/tracking_info";
  }

  @RequestMapping(value = "/addTrackingInfo" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String addTrackingInfo(@Valid @RequestBody TrackingInfo trackingInfo, Errors errors){
    JSONObject jsonObject = new JSONObject();
    if (errors.hasErrors()){
      System.out.println("错误:"+trackingInfo.toString());
      List<FieldError> errorList = errors.getFieldErrors();
      String msg="";
      for (FieldError e:errorList){
        //打印错误信息
        System.err.println("fied:"+e.getField() +"\t" +"msg:"+e.getDefaultMessage());
        msg=msg+e.getDefaultMessage();
      }
      String result="false";
      jsonObject.put("result",result);
      jsonObject.put("msg",msg);
      return jsonObject.toString();
    }
    System.out.println(trackingInfo.toString());
    trackingInfo.setInfoTime(new java.util.Date());
    Integer column = trackingInfoService.saveTrackingInfo(trackingInfo);
    if (column==1){
      RegistrationTable registrationTable= registrationTableService.searchRegistrationById(trackingInfo.registrationId);
      RegistrationTable update = Add_ChangRegistrationInfo(registrationTable,trackingInfo);
      Integer resultcolumn = registrationTableService.changInfo(registrationTable);

    }
    jsonObject.put("result","true");
    return jsonObject.toString();
  }

  /*更新跟踪信息*/
  @RequestMapping(value = "/getTrackingInfo" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String getTrackingInfo(@RequestBody String infoId){
    JSONObject jsonObject = JSONObject.fromObject(infoId);
    Integer infoID = Integer.parseInt(jsonObject.getString("infoId"));
    TrackingInfo trackingInfo = trackingInfoService.searchTrackingInfo(infoID);
    JSONObject jsonObject1 = JSONObject.fromObject(trackingInfo);
    return jsonObject1.toString() ;
  }


  /*更新跟踪信息*/
  @RequestMapping(value = "/updateTrackingInfo" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String updateTrackingInfo(@Valid @RequestBody TrackingInfo trackingInfo, Errors errors){
    JSONObject jsonObject = new JSONObject();
    if (errors.hasErrors()){
      System.out.println("错误:"+trackingInfo.toString());
      List<FieldError> errorList = errors.getFieldErrors();
      String msg="";
      for (FieldError e:errorList){
        //打印错误信息
        System.err.println("fied:"+e.getField() +"\t" +"msg:"+e.getDefaultMessage());
        msg=msg+e.getDefaultMessage();
      }
      String result="false";
      jsonObject.put("result",result);
      jsonObject.put("msg",msg);
      return jsonObject.toString();
    }
    System.out.println(trackingInfo.toString());
    Integer column = trackingInfoService.changTrackingInfo(trackingInfo.infoId,trackingInfo.infoContent,trackingInfo.infoType,trackingInfo.warning,trackingInfo.businessStatus);
    if (column==1){
      RegistrationTable registrationTable=registrationTableService.searchRegistrationById(trackingInfo.registrationId);
      RegistrationTable update = Update_ChangRegistrationInfo(registrationTable,trackingInfo);
      Integer resultcolumn = registrationTableService.changInfo(update);
    }
    jsonObject.put("result","true");
    return jsonObject.toString();
  }

  public RegistrationTable Add_ChangRegistrationInfo(RegistrationTable registrationTable,TrackingInfo trackingInfo){
    String businessStatus = trackingInfo.getBusinessStatus();
    Integer trackingTimes = trackingInfoService.changRistrationTrackingTime(trackingInfo.registrationId);
    Date notrackingDays = new Date(trackingInfo.getInfoTime().getTime());
    Integer warning = trackingInfoService.changRistrationWarningTimes(trackingInfo.registrationId);
    registrationTable.setBusinessStatus(businessStatus);
    registrationTable.setTrackingTimes(trackingTimes);
    registrationTable.setNotrackingDays(notrackingDays);
    registrationTable.setWarningTimes(warning);
    return registrationTable;
  }

  public RegistrationTable Update_ChangRegistrationInfo(RegistrationTable registrationTable,TrackingInfo trackingInfo){
    String businessStatus = trackingInfo.getBusinessStatus();
    Integer warning = trackingInfoService.changRistrationWarningTimes(trackingInfo.registrationId);
    registrationTable.setBusinessStatus(businessStatus);
    registrationTable.setWarningTimes(warning);
    return registrationTable;
  }
  /*插入飞单审批*/
  @RequestMapping(value = "/setCancelTable" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String setCancelTable(@Valid @RequestBody CancelTable cancelTable, Errors errors){
    JSONObject jsonObject = new JSONObject();
    if (errors.hasErrors()){
      System.out.println("错误:"+cancelTable.toString());
      List<FieldError> errorList = errors.getFieldErrors();
      String msg="";
      for (FieldError e:errorList){
        //打印错误信息
        System.err.println("fied:"+e.getField() +"\t" +"msg:"+e.getDefaultMessage());
        msg=msg+e.getDefaultMessage();
      }
      String result="操作失败,";
      jsonObject.put("result",result);
      jsonObject.put("msg",msg);
      return jsonObject.toString();
    }
    cancelTable.setCancelStatus(false);
    cancelTable.setCancelTime(new java.util.Date());
    System.out.println(cancelTable.toString());

    Integer resultcolumn = cancelTableService.saveCancelTable(cancelTable);
    if (resultcolumn==1){
      Integer s = registrationTableService.changStatusByRegistrationId(cancelTable.getRegistrationId(),6);
    }
    jsonObject.put("result","操作成功");
    return jsonObject.toString();
  }
  @RequestMapping("/resetpassword")
  public String resetpassword(){
    return "common_control/change_password";
  }

  @RequestMapping(value = "/changepassword" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String changepassword(@RequestBody String str, HttpSession session){
    JSONObject jsonObject = JSONObject.fromObject(str);
    String oldpassword = jsonObject.getString("oldpassword");
    String password = jsonObject.getString("password");
    Employee employee = (Employee) session.getAttribute("employee");
    boolean result = employeeService.changeEmployeepasswordByEmployeeId(employee.getEmployeeId(),password,oldpassword);
    JSONObject jsonObject1 = new JSONObject();
    if (employee==null){
      jsonObject1.put("msg","登录已过期,请重新登录!");
      return jsonObject1.toString();
    }
    if (result){
      jsonObject1.put("msg","修改密码成功!");
    }else {
      jsonObject1.put("msg","修改密码失败,或密码错误!");
    }
    return jsonObject1.toString();
  }

  @RequestMapping(value = "/logout" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String logout(HttpSession session){
    session.removeAttribute("employee");
    session.removeAttribute("name");
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("msg","退出成功!");
    return jsonObject.toString();
  }

  @RequestMapping("bind_username")
  public String bind_username(){
    return "common_control/bind_username";
  }
  @RequestMapping(value = "/checkUserName" ,method = RequestMethod.POST)
  @ResponseBody
  public String checkUserName(@RequestBody String userName){
    String checkUserName = userName.substring(9);
    System.out.println("input输入的账号为"+checkUserName);
    Map<String,String> map= new HashMap<String, String>();
    if(loginService.checkUserName(checkUserName)!=null && !loginService.checkUserName(checkUserName).equals("")){
      System.out.println("账号存在,可以绑定");
      map.put("valid","true");
    }else{
      System.out.println("账号不存在");
      map.put("valid","false");
    }
    JSONObject jsonObject = JSONObject.fromObject(map);
    String result = jsonObject.toString();
    System.out.println(result);
    return result;
  }

  @RequestMapping(value = "/checkRegistrationId" ,method = RequestMethod.POST)
  @ResponseBody
  public String checkRegistrationId(@RequestBody String registrationId){
    String checkregistrationId = registrationId.substring(15);
    System.out.println("input输入的登记编号为"+checkregistrationId);
    Map<String,String> map= new HashMap<String, String>();
    RegistrationTable registration = registrationTableService.searchRegistrationById(Integer.parseInt(checkregistrationId));
    if(registration!=null){
      System.out.println("登记编号存在,可以绑定");
      map.put("valid","true");
    }else{
      System.out.println("登记编号不存在");
      map.put("valid","false");
    }
    JSONObject jsonObject = JSONObject.fromObject(map);
    String result = jsonObject.toString();
    System.out.println(result);
    return result;
  }
  @RequestMapping(value = "/changeRegistrationId" ,method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
  @ResponseBody
  public String changeRegistrationId(@RequestBody String str, HttpSession session){
    JSONObject jsonObject = JSONObject.fromObject(str);
   Integer registrationId = jsonObject.getInt("registrationId");
    String userName = jsonObject.getString("userName");
    Integer status = jsonObject.getInt("status");
    Employee employee = (Employee) session.getAttribute("employee");
    JSONObject jsonObject1 = new JSONObject();
    if (employee==null){
      jsonObject1.put("msg","登录已过期,请重新登录!");
      return jsonObject1.toString();
    }
    String name = registrationTableService.searchUserNameByRegistrationId(registrationId);
    if(status==0){
      if (!name.equals("") ){
        jsonObject1.put("resultstatus","1");
        jsonObject1.put("msg","该表单已绑定客户账号【"+name+"】,请确认是否继续!<button class='btn btn-primary' type='button' οnclick='changeRegistration()' >继续绑定</button>");
        return jsonObject1.toString();
      }else {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("registrationId",registrationId);
        map.put("userName",userName);
        Integer column = registrationTableService.changeUserNameByRegistrationId(map);
        if (column==1){
          jsonObject1.put("msg","成功绑定客户账号【"+userName+"】");
        }else {
          jsonObject1.put("msg","请刷新确认登记记录是否存在!");
        }

      }
    }else {
      Map<String,Object> map = new HashMap<String,Object>();
      map.put("registrationId",registrationId);
      map.put("userName",userName);
      Integer column = registrationTableService.changeUserNameByRegistrationId(map);
      if (column==1){
        jsonObject1.put("msg","成功绑定客户账号【"+userName+"】");
      }else {
        jsonObject1.put("msg","请刷新确认登记记录是否存在!");
      }
    }
    jsonObject1.put("resultstatus","0");
    return jsonObject1.toString();
  }
}