Java项目:在线旅游美食展现管理系统(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版本;


技术栈

1. 后端:Spring+SpringMVC+Mbytes
2. 前端:JSP+bootstrap+jQuery


使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入localhost:8080/

 

 

 

 

 

美食管理控制层:

@WebServlet("/FoodServlet") // 用户类
@MultipartConfig
public class FoodServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	BaseDao dao = new BaseDaoImpl();
	PrintWriter out = null;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		// service
		// 方法类-----------------------------------------------------------------------------------------------------
		ObjectService service = new ObjectService();
		FoodEntity foo = service.setObject(request, FoodEntity.class);
		out = response.getWriter();
		// 全局变量类----------------------------------------------------------------------------------------------------------
		String method = request.getParameter("method");
		System.out.println(method);

		if ("foodList".equals(method)) {// 列表
			try {
				JSONArray food = dao
						.findJSONArray("select s.sce_name,f.* from food f left join scenic s on s.sce_id=f.sce_id");
				request.setAttribute("food", food);
				request.getRequestDispatcher("admin-food.jsp").forward(request, response);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else if ("searchFood".equals(method)) {// 查询
			try {
				System.out.println(foo.getFooName());
				JSONArray food = dao.findJSONArray(
						"select s.sce_name,f.* from food f left join scenic s on s.sce_id=f.sce_id where f.foo_name like '%"
								+ foo.getFooName() + "%'");
				String sceId = request.getParameter("sceId");
				System.out.println(sceId);
				if (sceId != null && sceId != "") {
					food = dao.findJSONArray(
							"select s.sce_name,f.* from food f left join scenic s on s.sce_id=f.sce_id where f.sce_id="
									+ sceId + " and f.foo_name like '%" + foo.getFooName() + "%'");
				}
				request.setAttribute("food", food);
				request.getRequestDispatcher("admin-food.jsp").forward(request, response);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else if ("foodAdd".equals(method)) {// 增加
			Part part = request.getPart("Savatar");
			String heads_url = service.imagepath(part);
			String img_url = heads_url;
			Object[] params = { foo.getFooName(), img_url, foo.getAddress(), foo.getSceId(), foo.getDescription() };
			try {
				int i = dao.update("INSERT INTO food(foo_name,img_url,address,sce_id,description) VALUES(?,?,?,?,?)",
						params);
				if (i > 0) {
					response.sendRedirect("FoodServlet?method=foodList");
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else if ("deleteFood".equals(method)) {// 删除
			try {
				int i = dao.update("delete from food where foo_id=?", foo.getFooId());
				if (i > 0) {
					response.sendRedirect("FoodServlet?method=foodList");
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else if ("updateFood".equals(method)) {// 修改
			Object[] params = { foo.getFooId() };
			try {
				JSONObject food = dao.findJSONObject(
						"select s.sce_name,f.* from food f left join scenic s on s.sce_id=f.sce_id where f.foo_id = ?",
						params);
				request.setAttribute("food", food);
				request.getRequestDispatcher("admin-foodUpdate.jsp").forward(request, response);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else if ("updateFood1".equals(method)) {// 完成修改
			String img_url = null;
			Part part1 = request.getPart("Savatar");
			if (part1.getSize() > 0) {
				String savepath = service.imagepath(part1);
				img_url = savepath;
			} else {
				img_url = foo.getImgUrl();
			}
			Object[] params = { foo.getFooName(), img_url, foo.getAddress(), foo.getSceId(), foo.getDescription(),
					foo.getFooId() };
			try {
				int i = dao.update(
						"update food set foo_name = ?,img_url=?,address=?,sce_id=?,description=? where foo_id=?",
						params);
				if (i > 0) {
					response.sendRedirect("FoodServlet?method=foodList");
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else if ("foodCllentList".equals(method)) {// 用户查看列表
			String ctel = (String) request.getSession().getAttribute("ctel");
			try {
				String sql = "select IF(ISNULL(c.ctel),'0','1') count,IF(ISNULL(fo.foo_id),'0',CONVERT( COUNT(*) USING UTF8)) num ,f.* "
						+ "from foo_collect fo " + "left join food f on fo.foo_id=f.foo_id "
						+ "left join cllent c on c.ctel=fo.ctel " + "and c.ctel=? where f.sce_id=? "
						+ "GROUP BY f.foo_id order by num desc";
				JSONArray food = dao.findJSONArray(sql, ctel, foo.getSceId());
				request.setAttribute("food", food);
				request.getRequestDispatcher("food-list.jsp").forward(request, response);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else if ("foodCllentSearch".equals(method)) {// 用户搜索列表
			String ctel = (String) request.getSession().getAttribute("ctel");
			try {
				String sql = "select IF(ISNULL(c.ctel),'0','1') count,IF(ISNULL(fo.foo_id),'0',CONVERT( COUNT(*) USING UTF8)) num ,f.* "
						+ "from foo_collect fo " + "left join food f on fo.foo_id=f.foo_id "
						+ "left join cllent c on c.ctel=fo.ctel " + "and c.ctel=" + ctel + " where f.sce_id = "
						+ foo.getSceId() + " and f.foo_name like '%" + foo.getFooName() + "%' "
						+ "GROUP BY f.foo_id order by num desc";
				JSONArray food = dao.findJSONArray(sql);
				request.setAttribute("food", food);
				request.getRequestDispatcher("food-list.jsp").forward(request, response);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else if ("detailFood".equals(method)) {// 美食详情
			try {
				JSONObject food = dao.findJSONObject("select * from food where foo_id=?", foo.getFooId());
				request.setAttribute("food", food);
				request.getRequestDispatcher("food-detail.jsp").forward(request, response);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}

登录管理控制层:

@WebServlet("/Login")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	BaseDao dao = new BaseDaoImpl();
	PrintWriter out = null;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		// service
		// 方法类-----------------------------------------------------------------------------------------------------
		ObjectService service = new ObjectService();
		HttpSession session = request.getSession();
		UsersEntity use = service.setObject(request, UsersEntity.class);
		// 全局变量类----------------------------------------------------------------------------------------------------------
		String method = request.getParameter("method");
		System.out.println(method);
		out = response.getWriter();
		File[] files = File.listRoots();
		String rootpath = files[files.length - 1].getPath();
		if ("login".equals(method)) {// 登录
			Object[] params = { use.getUname(), use.getPassword() };
			System.out.println(use.getUname() + use.getPassword());
			JSONObject user = null;
			try {
				user = dao.findJSONObject("select * from users where uname = ? and password = ?", params);
				System.out.println(user);
				System.out.println(user.get("uname"));
				System.out.println(user.get("utype"));
				request.getSession().setAttribute("uname", user.get("uname"));
				request.getSession().setAttribute("utype", user.get("utype"));
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				if (user.size() > 0) {
					out.write("1");
					out.flush();
					out.close();
				}
			}
		} else if ("exit".equals(method)) {// 退出登录
			request.getSession().removeAttribute("uname");
			request.getSession().removeAttribute("utype");
			request.getSession().removeAttribute("rootpath");
			response.sendRedirect("login.jsp");
		} else if ("index".equals(method)) {// 进入首页
			String uname = (String) session.getAttribute("uname");
			System.out.println(uname);
			String utype = "" + session.getAttribute("utype");
			request.getSession().setAttribute("rootpath", rootpath);
			System.out.println(utype);
			if (utype.equals("1")) {
				request.getRequestDispatcher("index.jsp").forward(request, response);
			} 
		} else if ("updateUsers".equals(method)) {// 修改密码
			String pwd = request.getParameter("pwd");
			String pwd1 = request.getParameter("pwd1");
			System.out.println(pwd);
			System.out.println(pwd1);
			String uname = (String) request.getSession().getAttribute("uname");
			Object[] params = { pwd1, uname };
			try {
				int m = (int) dao.getCount("select count(*) from users where password = ?", pwd);
				if (m > 0) {
					dao.update("update users set password = ? where uname = ?", params);
					out.write("1");
					out.flush();
					out.close();
				} else {
					out.write("2");
					out.flush();
					out.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else if ("users".equals(method)) {// 管理员信息
			JSONArray records;
			try {
				records = dao.findJSONArray("select * from users where uname=?", use.getUname());
				request.setAttribute("records", records);
				request.getRequestDispatcher("admin-info.jsp").forward(request, response);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

	}
}

景点管理控制层:

@WebServlet("/Tdetail") // 加载图片
public class TdetailServlet extends HttpServlet {
	BaseDao dao = new BaseDaoImpl();

	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		String method = request.getParameter("method");
//		File[] files = File.listRoots();
//		String rootpath = files[files.length - 1].getPath();
		System.out.println(method);
		if ("showImage".equals(method)) {// 加载图片
			File file = new File(request.getParameter("image"));
//			System.out.println(file);
			if (file == null || !file.exists()) {
				return;
			}
			InputStream in = new FileInputStream(file);
			int len = 0;
			byte[] b = new byte[1024 * 4];
			OutputStream out = response.getOutputStream();
			while ((len = in.read(b)) != -1) {
//				 System.out.println(len);
				out.write(b, 0, len);
			}
			response.flushBuffer();
			out.close();
			in.close();

		}
	}

}

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

猜你喜欢

转载自blog.csdn.net/pastclouds/article/details/125481350