Java项目:旅游推荐系统(java+Servlet+JSP+JDBC+Mysql)

news/2024/5/19 1:37:59 标签: java, mysql, servlet, JSP, JDBC

源码获取:俺的博客首页 "资源" 里下载!

项目介绍

旅游推荐网分为前后台,普通用户在前台登录,功能如下:登录、查看热门景点推荐、景点详情、动态查看、联系我们、留言等
管理员通过后台登录,功能如下:登录、留言评审管理、景区管理、用户管理、系统统计等


环境需要

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、JSPJDBC、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

 

 

 

 

 

 

后台登陆页面控制层:

java">/**
 * 登陆后台管理界面
 *
 */
@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;
		
	}
}

用户管理控制层:

java">/**
 * 旅游用户前端控制器
 */
@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;
  }
  }

后台管理的拦截器:

java">//后台管理的拦截器
@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;
			    }
			}
	   
	}
}

 源码获取:俺的博客首页 "资源" 里下载!


http://www.niftyadmin.cn/n/1553421.html

相关文章

2008.1.9 Do you get a kick out of watching me suffer?

Do you get a kick out of watching me suffer?看我难受你就高兴是不是&#xff1f;----------------------------------------------------------------------固定搭配get a kick out of something&#xff0c;意思是做某事得到乐趣、刺激、快感。例句&#xff1a;I really g…

Java项目:家庭理财管理系统(java+SSM+bootstrap+highcharts+Mysql)

源码获取&#xff1a;俺的博客首页 "资源" 里下载&#xff01; 项目介绍 SSM家庭理财管理系统,分为管理员与普通用户两种角色&#xff1b; 管理员角色包含以下功能&#xff1a; 收支管理&#xff1a;收入信息维护、支出信息维护&#xff1b; 财务管理&#xff1a;证…

Java项目:乐器租赁管理系统(java+SSM+JSP+javascript+Mysql)

源码获取&#xff1a;俺的博客首页 "资源" 里下载&#xff01; 项目介绍 管理员角色包含以下功能&#xff1a; 管理员登录,管理员信息管理,查看用户信息,新闻公告管理,品牌信息管理,城市信息管理,租赁点信息管理,乐器信息管理,订单信息管理,评价信息管理,修改密码等…

Connect by实现树查询的妙用

做了个实验总结一下connect by树查询的用法&#xff1a; SQL> select * from t_dept_temp; DEPT_ID PARENT_ID DEPT_NAME AMOUNT---------- ---------- ---------- ---------- 1 1 2 2 1 1-2 1…

Java项目:办公用品商城系统(java+SSM+JSP+javascript+Mysql)

源码获取&#xff1a;俺的博客首页 "资源" 里下载&#xff01; 项目介绍 本项目分为管理员与普通用户两种角色&#xff0c;分为前台与后台&#xff1b; 管理员角色包含以下功能&#xff1a; 管理员登录,用户查看,一级分类管理,二级分类管理,办公用品管理,订单管理,…

Oracle 10g 中驱动包的意义

JDBC Thin for All Platforms classes12.jar (1,594,191 bytes) - for use with JDK 1.2 and JDK 1.3 classes12_g.jar (2,038,127 bytes) - same as classes12.jar, except that classes were compiled with “javac -g” and contain some tracing information. classes12d…

Java项目:农产品商城管理系统(java+SSM+JSP+jQuery+Mysql)

源码获取&#xff1a;俺的博客首页 "资源" 里下载&#xff01; 项目介绍 本项目分为普通用户与管理员两种角色&#xff1b; 管理员角色包含以下功能&#xff1a; 管理员登录,用户管理,一级分类管理,二级分类管理,农产品管理,订单管理,留言管理,公告管理等功能。 用…

Java项目:画室管理系统(java+SSM+JSP+jQuery+Mysql)

源码获取&#xff1a;俺的博客首页 "资源" 里下载&#xff01;项目介绍本项目包含管理员与普通用户两种角色管理员角色包含以下功能&#xff1a;修改密码,新闻分类管理,新闻管理,日志管理,用户信息管理,管理员登录,菜单管理,角色管理,评论管理等功能。用户角色包含以…