项目介绍
旅游推荐网分为前后台,普通用户在前台登录,功能如下:登录、查看热门景点推荐、景点详情、动态查看、联系我们、留言等
管理员通过后台登录,功能如下:登录、留言评审管理、景区管理、用户管理、系统统计等
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目: 否;
技术栈
Servlet、JSP、JDBC、MySQL5.7、Tomcat8
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,然后运行;
3. 将项目中src/com/dao/DB.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入地址;
前台地址:http://localhost:8080/lvyou/qianduan/index.html
普通社员账号:zhangsan 密码:123456
后台地址:http://localhost:8080/lvyou/admin/index.html
管理员账号:admin 密码:admin
后台登陆页面控制层:
/**
* 登陆后台管理界面
*
*/
@Controller
@RequestMapping("/backgroundweb")
public class SysloginController {
public Logger logger = LoggerFactory
.getLogger(SysloginController.class);// 输出日志
@Autowired
private SceneInformationService sceneInformationService;
@Autowired
private StrategyInfoemationService strategyInfoemationService;
@Autowired
private TourismUserService tourismUserService;
@Autowired
private SearchRecordService searchRecordService;
@RequestMapping("/checkLogin")
@ResponseBody
public JSONObject checkLogin(HttpServletRequest request,HttpServletResponse response,String userName,String passWord){
logger.info("收到的用户名为:"+userName+",密码为:"+passWord);
JSONObject json=new JSONObject();
if(userName.equals("admin") && passWord.equals("123456")){
request.getSession().setAttribute("userName","admin");
json.put("fiag", true);
}else{
json.put("fiag", false);
}
return json;
}
@RequestMapping("/jumpMain")
public String jumpMain(ModelMap model){
model.put("userName","admin");
return "backgroundWeb/main";
}
//跳转新建景点界面
@RequestMapping("/addAttractions")
public String addAttractions(){
return "backgroundWeb/addAttractions";
}
//跳转用户信息界面
@RequestMapping("/viewUser")
public String viewUser(){
return "backgroundWeb/viewUser";
}
/**
* 用户退出
* @return
*/
@RequestMapping(value="/logout")
public String dropOut(HttpServletRequest request, HttpServletResponse response){
HttpSession session = request.getSession();
session.removeAttribute("userName");
return "redirect:/login";
}
//保存景点信息
@RequestMapping("/save")
@ResponseBody
public JSONObject save (@RequestBody AttractionsDto attractionsDto){
JSONObject json =new JSONObject();
boolean flag=true;
logger.info("保存的实体类信息:"+JSONObject.toJSONString(attractionsDto));
try{
SceneInformation sceneInformation =new SceneInformation();
sceneInformation.setCreateTime(new Date());
sceneInformation.setState(1);
sceneInformation.setSceneSite(attractionsDto.getSceneSite());
sceneInformation.setSceneImage(attractionsDto.getSceneImage());
sceneInformation.setSceneName(attractionsDto.getSceneName());
sceneInformation.setScenePrice(attractionsDto.getScenePrice());
sceneInformation.setSceneTime(attractionsDto.getSceneTime());
sceneInformation.setSceneIntroduce(attractionsDto.getSceneIntroduce());
Integer aa= sceneInformationService.insert(sceneInformation);
logger.info("返回的id为:"+aa+"当前实体类id为:"+sceneInformation.getId());
if(aa >0){
if(StringUtils.isNotEmpty(attractionsDto.getOneSite())){
StrategyInfoemation strategyInfoemation =new StrategyInfoemation();
strategyInfoemation.setStatus(Constant.isUsd);
strategyInfoemation.setCreateTime(new Date());
strategyInfoemation.setStrategyAccommodation(attractionsDto.getOneAccommodation());
strategyInfoemation.setStrategyDays(1);
strategyInfoemation.setStrategyIntroduce(attractionsDto.getOneIntroduce());
strategyInfoemation.setStrategySite(attractionsDto.getOneSite());
strategyInfoemation.setStrategyTraffic(attractionsDto.getOneTraffic());
strategyInfoemation.setSceneId(sceneInformation.getId());
strategyInfoemationService.insert(strategyInfoemation);
strategyInfoemation=null;
}
if(StringUtils.isNotEmpty(attractionsDto.getTwoSite())){
StrategyInfoemation twoStrategyInfoemation=new StrategyInfoemation();
twoStrategyInfoemation.setStatus(Constant.isUsd);
twoStrategyInfoemation.setCreateTime(new Date());
twoStrategyInfoemation.setStrategyAccommodation(attractionsDto.getTwoAccommodation());
twoStrategyInfoemation.setStrategyDays(2);
twoStrategyInfoemation.setSceneId(sceneInformation.getId());
twoStrategyInfoemation.setStrategyIntroduce(attractionsDto.getTwoIntroduce());
twoStrategyInfoemation.setStrategySite(attractionsDto.getTwoSite());
twoStrategyInfoemation.setStrategyTraffic(attractionsDto.getTwoTraffic());
strategyInfoemationService.insert(twoStrategyInfoemation);
twoStrategyInfoemation=null;
}
if(StringUtils.isNotEmpty(attractionsDto.getThreeSite())){
StrategyInfoemation threeStrategyInfoemation=new StrategyInfoemation();
threeStrategyInfoemation.setStatus(Constant.isUsd);
threeStrategyInfoemation.setCreateTime(new Date());
threeStrategyInfoemation.setStrategyAccommodation(attractionsDto.getThreeAccommodation());
threeStrategyInfoemation.setStrategyDays(3);
threeStrategyInfoemation.setSceneId(sceneInformation.getId());
threeStrategyInfoemation.setStrategyIntroduce(attractionsDto.getThreeIntroduce());
threeStrategyInfoemation.setStrategySite(attractionsDto.getThreeSite());
threeStrategyInfoemation.setStrategyTraffic(attractionsDto.getThreeTraffic());
strategyInfoemationService.insert(threeStrategyInfoemation);
threeStrategyInfoemation=null;
}
}else{
flag=false;
}
}catch(Throwable te){
flag=false;
logger.error("保存景点信息异常信息为:", te);
}
json.put("flag", flag);
return json;
}
@RequestMapping("/selectUserAll")
@ResponseBody
public PageBean<TourismUser> selectUserAll(@RequestBody UserDto userDto){
PageBean<TourismUser> pageBean = new PageBean<TourismUser>();// 初始化分页的实体
try {
List<TourismUser> list=tourismUserService.selectAllUsers(userDto.getRows(),userDto.getOffset(),userDto.getMobilePhone(),userDto.getUserName());
Integer count=tourismUserService.selectUserCount(userDto.getMobilePhone(),userDto.getUserName());
pageBean.setRows(list);
pageBean.setTotal(count);
}catch (Throwable te) {
logger.error("查询用户所有信息异常信息为:", te);
}
return pageBean;
}
@RequestMapping("/viewSearchRecord")
public String viewSearchRecord(){
return "backgroundWeb/viewSearchRecord";
}
@RequestMapping("/selectSearchRecordAll")
@ResponseBody
public PageBean<SearchRecord> selectSearchRecordAll(@RequestBody SearchRecordDto searchRecordDto){
PageBean<SearchRecord> pageBean = new PageBean<SearchRecord>();// 初始化分页的实体
try {
List<SearchRecord> list=searchRecordService.selectAllSearchRecord(searchRecordDto.getRows(),searchRecordDto.getOffset(),searchRecordDto.getSearchScene(),searchRecordDto.getUserName());
Integer count=searchRecordService.selectSearchRecordCount(searchRecordDto.getSearchScene(),searchRecordDto.getUserName());
pageBean.setRows(list);
pageBean.setTotal(count);
}catch (Throwable te) {
logger.error("查询搜索所有信息异常信息为:", te);
}
return pageBean;
}
}
用户管理控制层:
/**
* 旅游用户前端控制器
*/
@Controller
@RequestMapping("/tourismUser")
public class TourismUserController {
public Logger logger = LoggerFactory
.getLogger(TourismUserController.class);// 输出日志
@Autowired
private TourismUserService tourismUserService;
@RequestMapping("/save")
@ResponseBody
public ResponseInformation save(@RequestBody TourismUser tourismUser){
// 初始化返回码和返回信息,默认处理成功
ResponseInformation responseInformation=new ResponseInformation();
logger.info("保存用户信息为:"+JSONObject.toJSONString(tourismUser));
try {
tourismUser.setCreateTime(new Date());
tourismUser.setStatus(Constant.isUsd);
Integer count= tourismUserService.insert(tourismUser);
if (count > 0) {
logger.info("保存成功");
}else{
responseInformation.setReponseCode(Constant.dataCode);
responseInformation.setReponseMessage("数据异常");
}
}catch(Throwable te){
responseInformation.setReponseCode(Constant.dataCode);
responseInformation.setReponseMessage("保存失败");
logger.error("保存人员异常信息为:", te);
}
return responseInformation;
}
@RequestMapping("/checkLogin")
@ResponseBody
public JSONObject checkLogin(HttpServletRequest request,HttpServletResponse response,String userName,String passWord){
logger.info("收到的用户名为:"+userName+",密码为:"+passWord);
JSONObject json=new JSONObject();
TourismUser tourismUser =new TourismUser();
tourismUser.setStatus(Constant.isUsd);
tourismUser.setUserArount(userName);
tourismUser.setUserPassword(passWord);
TourismUser retTourismUser = tourismUserService.selectOne(tourismUser);
if(null != retTourismUser){
request.getSession().setAttribute("tourismUser",retTourismUser.getUserName());
json.put("fiag", true);
}else{
json.put("fiag", false);
}
return json;
}
@RequestMapping("/validUserName")
@ResponseBody
public JSONObject validUserName(String userName){
JSONObject json=new JSONObject();
TourismUser TourismUser=new TourismUser();
TourismUser.setUserArount(userName);
TourismUser ret =tourismUserService.selectOne(TourismUser);
if(null != ret){
json.put("flag", false);
}else{
json.put("flag", true);
}
return json;
}
@RequestMapping("/update")
@ResponseBody
public ResponseInformation update(@RequestBody TourismUser tourismUser){
// 初始化返回码和返回信息,默认处理成功
ResponseInformation responseInformation=new ResponseInformation();
logger.info("保存用户信息为:"+JSONObject.toJSONString(tourismUser));
try {
tourismUser.setCreateTime(new Date());
tourismUser.setStatus(Constant.isUsd);
Integer count= tourismUserService.updateById(tourismUser);
if (count > 0) {
logger.info("保存成功");
}else{
responseInformation.setReponseCode(Constant.dataCode);
responseInformation.setReponseMessage("数据异常");
}
}catch(Throwable te){
responseInformation.setReponseCode(Constant.dataCode);
responseInformation.setReponseMessage("保存失败");
logger.error("保存人员异常信息为:", te);
}
return responseInformation;
}
}
后台管理的拦截器:
//后台管理的拦截器
@Component
public class UserLoginFilter extends HandlerInterceptorAdapter{
public static Logger logger = LoggerFactory.getLogger(UserLoginFilter.class);
public UserLoginFilter() {
}
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
logger.info("进入拦截器");
String contextPath=request.getContextPath();
if(null == request.getSession()){
response.sendRedirect(contextPath+"/userlogin");
return false;
}else{
if(null == request.getSession().getAttribute("tourismUser")){
response.sendRedirect(contextPath+"/userlogin");
return false;
}else{
return true;
}
}
}
}