基于javaweb+mysql的ssm+maven旅游管理系统(前台、后台)(java+jsp+ssm+maven+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
分为前台用户和后台管理员功能
管理员
- 登录、管理用户、管理景点、管理酒店、管理论坛帖子、管理评论等
用户端
- 登录、注册、景点、酒店、论坛、评论等功能的浏览和评论等
idea运行/eclipse/MyEclipse运行
前台
后台
技术框架
JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) Maven MySQL jQuery JavaScript CSS
基于javaweb+mysql的SSM+Maven旅游管理系统(前台、后台)(java+jsp+ssm+maven+mysql)
//全路径
hotel.setImgUrl(prefix + suffix);
}
//传送景点
model.addAttribute("hotels", hotels);
return "proscenium/hotel/index";
}
/**
* 跳转首页
*/
@RequestMapping(value = "content", method = RequestMethod.GET)
public String content(Integer hid, Model model) {
//封装留言信息
List<Words> lw_list = viewPointService.findByWords();
model.addAttribute("lw_list",lw_list);
//封装回复信息
List<Reply> lr_list = viewPointService.findByReply();
model.addAttribute("lr_list",lr_list);
Hotel hotel = hotelDao.selectByPrimaryKey(hid);
model.addAttribute("hotel", hotel);
return "proscenium/hotel/content";
}
/**
* 钱台酒店模糊搜索
*/
@RequestMapping(value = "hotelPointSearch", method = RequestMethod.GET)
public String hotelPointSearch(String keyword, Model model) {
String prefix = "/static/upload/hotelAvatar/";
Hotel hotel = new Hotel();
hotel.setLocal(keyword);
hotel.setHouseType(keyword);
hotel.setBedType(keyword);
List<Hotel> hotels = hotelDao.hotelPointSearch(hotel);
for (Hotel hotelForEach : hotels){
String imgUrl = hotelForEach.getImgUrl();
hotelForEach.setImgUrl(prefix + imgUrl);
}
}
/**
* 跳转到论坛
*/
@RequestMapping(value="/toForumArticleView")
public String toForumArticleView(@RequestParam int tpFid, Model model){
//封装留言信息
lw_list = viewPointService.findByWords();
model.addAttribute("lw_list",lw_list);
//封装回复信息
lr_list = viewPointService.findByReply();
model.addAttribute("lr_list",lr_list);
//查询文章信息
Forum forum = forumDao.selectByPrimaryKey(tpFid);
System.out.println("查询到当前文章的ID值:" + forum.getTpFid());
if (forum != null) {
model.addAttribute("forum", forum);
return "proscenium/forum/content";
} else {
return null;
}
}
/**
* 保存论坛回复信息
*/
@RequestMapping(value="/saveHotelReply")
public String saveHotelReply(Reply reply){
if(reply != null){
viewPointService.saveReply(reply);
String hid = reply.getLr_hotel_id();
return "redirect:toHotelArticleView.do?hid=" + hid;
}else{
return null;
}
}
/**
* 保存论坛留言信息
*/
@RequestMapping(value="/saveHotelWords")
private ForumDao forumDao;
@Autowired
private ForumExample example;
/**
* index页用户登录
*/
@RequestMapping(value = "login", method = RequestMethod.POST)
public String userLogin(String uemail, String upwd, Model model) {
//index页面登录成功图片显示路径
String prefix = "/static/upload/useravatar/";
//index页用户登录验证
if (uemail == null || uemail == "" || upwd == null || upwd == "") {
session.setAttribute("msg", Msg.fail("邮箱或密码不可为空!"));
return "redirect:/index";
}
User user = userService.userLogin(new User(uemail, upwd));
if (user != null) {
String suffix = user.getUpic();
user.setUpic(prefix+suffix);
session.setAttribute("user", user);
return "redirect:/index";
} else {
session.setAttribute("msg", Msg.fail("还未注册或邮箱密码错误,请重新输入!"));
return "redirect:/index";
}
}
/**
* 前台用户注销
*
* @return
*/
@RequestMapping(value = "loginout", method = RequestMethod.GET)
public String loginOut() {
session.invalidate();
return "redirect:/index";
}
/**
* 跳转注册用户
*
* @return
*/
@RequestMapping(value = "regst", method = RequestMethod.GET)
public String regst() {
return "proscenium/user/regst";
//index页用户登录验证
if (uemail == null || uemail == "" || upwd == null || upwd == "") {
session.setAttribute("msg", Msg.fail("邮箱或密码不可为空!"));
return "redirect:/index";
}
User user = userService.userLogin(new User(uemail, upwd));
if (user != null) {
String suffix = user.getUpic();
user.setUpic(prefix+suffix);
session.setAttribute("user", user);
return "redirect:/index";
} else {
session.setAttribute("msg", Msg.fail("还未注册或邮箱密码错误,请重新输入!"));
return "redirect:/index";
}
}
/**
* 前台用户注销
*
* @return
*/
@RequestMapping(value = "loginout", method = RequestMethod.GET)
public String loginOut() {
session.invalidate();
return "redirect:/index";
}
/**
* 跳转注册用户
*
* @return
*/
@RequestMapping(value = "regst", method = RequestMethod.GET)
public String regst() {
return "proscenium/user/regst";
}
@RequestMapping(value = "regstform", method = RequestMethod.POST)
public String regst(String uname, String uemail, String upwd, String reupwd, Model model) {
if (uemail == null || upwd == null || uemail.trim().equals("") || upwd.trim().equals("")) {
model.addAttribute("msg", Msg.fail("用户名或密码不可为空,请重新输入!"));
} else if (!reupwd.equals(upwd)) {
model.addAttribute("msg", Msg.fail("密码不正确请重新输入!"));
} else {
userService.insertUser(uname, uemail, upwd);
model.addAttribute("msg", Msg.success("用户注册成功!"));
}
System.out.println(!uemail.trim().equals(""));
return "proscenium/user/regst";
}
File file = new File(realPath);
//判断文件是否存在
if (!file.exists()){
file.mkdir();
}
file = new File(realPath,UUID.randomUUID() + fileSuffix);
try {
dropFile.transferTo(file);
} catch (IOException e) {
e.printStackTrace();
}
result.put("fileName",file.getName());
return result;
}
/**
* 后台内容图片上传
* @param dropFile
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "hotelContentUpload", method = RequestMethod.POST)
public Map<String, Object> hotelContentUpload(MultipartFile dropFile, HttpServletRequest request) {
Map<String, Object> result = new HashMap<>();
//前缀路径 Scheme服务端提供的协议 getServerName服务器名称 port 端口
//String server = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
//图片显示路径
String prefix = "/static/upload/hotelFile/";
//获取文件后缀
String fileName = dropFile.getOriginalFilename();
String fileSuffix = fileName.substring(fileName.lastIndexOf('.'));
//文件存放路径
String realPath = request.getSession().getServletContext().getRealPath(prefix);
File file = new File(realPath);
//判断文件是否存在
if (!file.exists()){
file.mkdir();
}
file = new File(realPath, UUID.randomUUID() + fileSuffix);
@Autowired
private WordsDao wordsDao;
@Autowired
private ReplyDao replyDao;
/**
* **********login start***************
* 从前端跳转到后台登录
*/
@RequestMapping(value = "login", method = RequestMethod.GET)
public String login() {
return "admin/login";
}
/**
* 登录逻辑
* handle
*
* @param aemail 用户邮箱
* @param apwd 密码
* @return String
*/
@RequestMapping(value = "login", method = RequestMethod.POST)
// @RequestParam(required = true) 为true时意思为不可缺省
public String login(String aemail, String apwd, HttpSession session) {
Admin admin = adminService.login(aemail, apwd);
String timestamp = TimeStampUtil.getTimeFormat();
//登录失败
if (admin == null) {
session.setAttribute("msg", Msg.fail("邮箱或者密码错误!"));
return login();
}
//登录成功
else {
// 将登录信息放入session
session.setAttribute("msg", Msg.success());
session.setAttribute("timestamp", timestamp);
session.setAttribute("admin", admin);
// 明日任务,获取域对象传送user信息
return "redirect:main";
}
}
/**
* 后台注销
*/
@RequestMapping(value = "loginout", method = RequestMethod.GET)
public String loginOut(HttpSession session) {
/**
* 文件上传控制器
*/
@RequestMapping(value = "upload")
@Controller
public class UploadController {
@Autowired
private UserService userService;
@Autowired
private ViewPointService viewPointService;
/**
* 文件上传
* @param dropFile
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "viewAvatar", method = RequestMethod.POST)
public Map<String, Object> viewAvatar(MultipartFile dropFile, HttpServletRequest request) {
Map<String, Object> result = new HashMap<>();
//文件存放路径
String filePath = "/static/upload/viewavatar/";
//获取文件后缀
String fileName = dropFile.getOriginalFilename();
String fileSuffix = fileName.substring(fileName.lastIndexOf('.'));
//文件存放路径
String realPath = request.getSession().getServletContext().getRealPath(filePath);
File file = new File(realPath);
//判断文件是否存在
if (!file.exists()){
file.mkdir();
return "proscenium/forum/edit";
}
example.setOrderByClause("tp_fid desc");
List<Forum> forums = forumDao.selectByExampleWithBLOBs(example);
model.addAttribute("forums",forums);
model.addAttribute("msg", Msg.fail("您还未登录!"));
return "proscenium/forum/index";
}
/**
* 编辑页面
*/
@RequestMapping(value = "edit", method = RequestMethod.GET)
public String edit(Integer uid, Model model){
if (uid != null){
return "proscenium/forum/edit";
}
model.addAttribute("msg", Msg.fail("您还未登录!"));
return "redirect:index";
}
/**
* content
*/
@RequestMapping(value = "savecontent", method = RequestMethod.POST)
public String saveContent(Forum forum, Model model){
forumDao.insert(forum);
model.addAttribute("msg", Msg.success("发帖成功"));
return "redirect:index";
}
/*############后台开始##############*/
}
package com.demo.controller;
* 编辑页面
*/
@RequestMapping(value = "edit", method = RequestMethod.GET)
public String edit(Integer uid, Model model){
if (uid != null){
return "proscenium/forum/edit";
}
model.addAttribute("msg", Msg.fail("您还未登录!"));
return "redirect:index";
}
/**
* content
*/
@RequestMapping(value = "savecontent", method = RequestMethod.POST)
public String saveContent(Forum forum, Model model){
forumDao.insert(forum);
model.addAttribute("msg", Msg.success("发帖成功"));
return "redirect:index";
}
/*############后台开始##############*/
}
package com.demo.controller;
@Controller
@RequestMapping(value = "view")
public class ViewPointController {
@Autowired
private ViewPointService viewPointService;
private HttpSession session;
/**
* 保存景点留言信息
*/
@RequestMapping(value="/saveWords")
public String saveWords(Words words){
if(words != null){
String r_id = words.getLw_for_article_id();
viewPointService.saveWords(words);
return "redirect:toArticleView.do?r_id="+r_id;
}else{
return null;
}
}
/**
* 保存回复信息
*/
@RequestMapping(value="/saveReply")
public String saveReply(Reply reply){
if(reply != null){
viewPointService.saveReply(reply);
String r_id = reply.getLr_for_article_id();
return "redirect:toArticleView.do?r_id="+r_id;
}else{
return null;
}
}
/**
* 跳转到查看文章内容页面
*/
@RequestMapping(value="/toArticleView")
public String toArticleView(@RequestParam int r_id, Model model){
//封装留言信息
lw_list = viewPointService.findByWords();
model.addAttribute("lw_list",lw_list);
//封装回复信息
lr_list = viewPointService.findByReply();
model.addAttribute("lr_list",lr_list);
//查询文章信息
ViewPoint viewPoint = viewPointService.selectByPrimaryKey(r_id);
System.out.println("查询到当前文章的ID值:" + viewPoint.getTpVid());
if (viewPoint != null) {
model.addAttribute("viewPoint", viewPoint);
return "proscenium/viewpoint/content";
} else {
return null;
}
}
@Autowired
private ForumExample example;
/**
* index页用户登录
*/
@RequestMapping(value = "login", method = RequestMethod.POST)
public String userLogin(String uemail, String upwd, Model model) {
//index页面登录成功图片显示路径
String prefix = "/static/upload/useravatar/";
//index页用户登录验证
if (uemail == null || uemail == "" || upwd == null || upwd == "") {
session.setAttribute("msg", Msg.fail("邮箱或密码不可为空!"));
return "redirect:/index";
}
User user = userService.userLogin(new User(uemail, upwd));
if (user != null) {
String suffix = user.getUpic();
user.setUpic(prefix+suffix);
session.setAttribute("user", user);
return "redirect:/index";
} else {
session.setAttribute("msg", Msg.fail("还未注册或邮箱密码错误,请重新输入!"));
return "redirect:/index";
}
}
/**
* 前台用户注销
*
* @return
*/
@RequestMapping(value = "loginout", method = RequestMethod.GET)
public String loginOut() {
session.invalidate();
return "redirect:/index";
}
/**
* 跳转注册用户
*
* @return
*/
@RequestMapping(value = "regst", method = RequestMethod.GET)
public String regst() {
return "proscenium/user/regst";
}
@RequestMapping(value = "regstform", method = RequestMethod.POST)
public String regst(String uname, String uemail, String upwd, String reupwd, Model model) {
if (uemail == null || upwd == null || uemail.trim().equals("") || upwd.trim().equals("")) {
model.addAttribute("msg", Msg.fail("用户名或密码不可为空,请重新输入!"));
if (user != null) {
String suffix = user.getUpic();
user.setUpic(prefix+suffix);
session.setAttribute("user", user);
return "redirect:/index";
} else {
session.setAttribute("msg", Msg.fail("还未注册或邮箱密码错误,请重新输入!"));
return "redirect:/index";
}
}
/**
* 前台用户注销
*
* @return
*/
@RequestMapping(value = "loginout", method = RequestMethod.GET)
public String loginOut() {
session.invalidate();
return "redirect:/index";
}
/**
* 跳转注册用户
*
* @return
*/
@RequestMapping(value = "regst", method = RequestMethod.GET)
public String regst() {
return "proscenium/user/regst";
}
@RequestMapping(value = "regstform", method = RequestMethod.POST)
public String regst(String uname, String uemail, String upwd, String reupwd, Model model) {
if (uemail == null || upwd == null || uemail.trim().equals("") || upwd.trim().equals("")) {
model.addAttribute("msg", Msg.fail("用户名或密码不可为空,请重新输入!"));
} else if (!reupwd.equals(upwd)) {
model.addAttribute("msg", Msg.fail("密码不正确请重新输入!"));
} else {
userService.insertUser(uname, uemail, upwd);
model.addAttribute("msg", Msg.success("用户注册成功!"));
}
System.out.println(!uemail.trim().equals(""));
return "proscenium/user/regst";
}
*
* @param tpFids
* @param model
* @return
*/
@ResponseBody//返回给前端
@RequestMapping(value = "forumMutiDelete", method = RequestMethod.GET)
public String forumMutiDelete(Integer[] tpFids, Model model) {
for (Integer tpFid : tpFids) {
forumDao.deleteByPrimaryKey(tpFid);
}
session.setAttribute("msg", Msg.success(Arrays.toString(tpFids) + "号批量删除成功!"));
return "1";
}
/**
* forummutidelete
*/
@RequestMapping(value = "forumDelete", method = RequestMethod.GET)
public String forumDelete(Integer tpFid, Model model) {
forumDao.deleteByPrimaryKey(tpFid);
model.addAttribute("msg", Msg.success(tpFid + "号批量删除成功!"));
return "redirect:forumList";
}
/**
* 酒店
* 新增表单跳转
*/
@RequestMapping(value = "forumInsertForm", method = RequestMethod.GET)
public String forumInsertForm() {
return "admin/forum_insert";
}
/**
* 酒店新增
*/
@RequestMapping(value = "forumInsert", method = RequestMethod.POST)
public String forumInsert(Forum forum, Model model) {
if (forum.getTpFid() == null) {
*/
@RequestMapping(value = "wordsDelete", method = RequestMethod.GET)
public String wordsDelete(Integer lw_id, Model model) {
wordsDao.deleteByPrimaryKey(lw_id);
model.addAttribute("msg", Msg.success(lw_id + "号删除成功!"));
return "redirect:wordsList";
}
/**
* 跳转回复列表
* @return
*/
@RequestMapping(value = "replyList", method = RequestMethod.GET)
public String ReplyList(Model model) {
List<Reply> replys = viewPointService.findByReply();
model.addAttribute("replys", replys);
return "admin/reply_list";
}
/**
* 回复批量删除
* @return
*/
@ResponseBody
@RequestMapping(value = "replyMutiDelete", method = RequestMethod.GET)
public String replyMutiDelete(Integer[] lr_ids, Model model) {
for (Integer lr_id : lr_ids){
replyDao.deleteByPrimaryKey(lr_id);
}
model.addAttribute("msg", Msg.success(Arrays.toString(lr_ids) + "号删除成功!"));
return "1";
}
/**
* 单击删除
* @return
*/
@RequestMapping(value = "replyDelete", method = RequestMethod.GET)
public String replyDelete(Integer lr_id, Model model) {
replyDao.deleteByPrimaryKey(lr_id);
model.addAttribute("msg", Msg.success(lr_id + "号删除成功!"));
return "redirect:replyList";
}
}
package com.demo.controller;
/**
* 用户单个单击删除
*/
@RequestMapping(value = "viewdelete", method = RequestMethod.GET)
public String viewDelete(Integer tpVid) {
viewPointService.deleteviews(tpVid);
session.setAttribute("msg", Msg.success(tpVid + "号用户删除成功!"));
return "redirect:viewlist";
}
/**
* 景点新增表单跳转
*/
@RequestMapping(value = "viewform", method = RequestMethod.GET)
public String viewForm() {
return "admin/view_form";
}
/**
* 景点新增
*/
@RequestMapping(value = "viewinsert", method = RequestMethod.POST)
public String viewInsert(ViewPoint viewPoint) {
if (viewPoint.getTpVid() == null) {
viewPointService.insertView(viewPoint);
session.setAttribute("msg", Msg.success("新增景点成功!"));
return "redirect:viewlist";
}
session.setAttribute("msg", Msg.fail("新增景点失败!"));
return "redirect:viewlist";
}
/**
* 跳转景点编辑更新界面
*/
@RequestMapping(value = "viewedit", method = RequestMethod.GET)
public String viewEdit(Integer tpVid, Model model) {
ViewPoint viewPoint = viewPointService.selectByPrimaryKey(tpVid);
model.addAttribute("viewPoint", viewPoint);
return "admin/view_edit";
}
/**
* 跳转景点更新业务
*/
@RequestMapping(value = "viewedithandle", method = RequestMethod.POST)
public String viewEditHandle(ViewPoint viewPoint) {
viewPointService.updateByPrimaryKeySelective(viewPoint);
session.setAttribute("msg", Msg.success("景点信息保存成功!"));
return "redirect:viewlist";
return "redirect:index";
}
/**
* content
*/
@RequestMapping(value = "savecontent", method = RequestMethod.POST)
public String saveContent(Forum forum, Model model){
forumDao.insert(forum);
model.addAttribute("msg", Msg.success("发帖成功"));
return "redirect:index";
}
/*############后台开始##############*/
}
package com.demo.controller;
@Controller
@RequestMapping(value = "view")
public class ViewPointController {
@Autowired
private ViewPointService viewPointService;
private HttpSession session;
@Autowired
private ViewPointExample viewPointExample;
@Autowired
private ViewPointDao viewPointDao;
* 跳转交通新增页面
* @return
*/
@RequestMapping(value = "trafficInsert", method = RequestMethod.GET)
public String trafficInsert() {
return "admin/traffic_insert";
}
/**
* 提交新增信息
* @return
*/
@RequestMapping(value = "trafficInsertHandler", method = RequestMethod.POST)
public String trafficInsertHandler(Traffic traffic, String currentTime, String arriveTime, Model model) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
// String parseCurrent = simpleDateFormat.format(currentTime);
// String parseArriveTime = simpleDateFormat.format(arriveTime);
traffic.setTpCurrentTime(currentTime);
traffic.setTpArriveTime(arriveTime);
} catch (Exception e) {
e.printStackTrace();
}
trafficDao.insertSelective(traffic);
model.addAttribute("msg",Msg.success("新增交通信息成功!"));
return "redirect:trafficList";
}
/**
* 单机删除
* @return
*/
@RequestMapping(value = "trafficDelete", method = RequestMethod.GET)
public String trafficDelete(Integer tpTid, Model model) {
trafficDao.deleteByPrimaryKey(tpTid);
model.addAttribute("msg", Msg.success(tpTid + "号删除成功!"));
return "redirect:trafficList";
}
/**
* 批量删除
* @return
*/
@ResponseBody
@RequestMapping(value = "trafficMutiDelete", method = RequestMethod.GET)
public String trafficsMutiDelete(Integer[] tpTids, Model model) {
for (Integer tpTid : tpTids){
trafficDao.deleteByPrimaryKey(tpTid);
}
model.addAttribute("msg", Msg.success(Arrays.toString(tpTids) + "号删除成功!"));
@Controller
@RequestMapping(value = "")
public class IndexController {
@Autowired
private ViewPointService viewPointService;
@Autowired
private HotelDao hotelDao;
/**
* 跳转首页
*/
@RequestMapping(value = {"", "index"}, method = RequestMethod.GET)
public String index(ViewPointExample example, Model model) {
HotelExample hotelExample = new HotelExample();
//显示首页的景点
String prefix = "/static/upload/viewavatar/";
//酒店
String prefixHotel = "/static/upload/hotelAvatar/";
example.setOrderByClause("tp_vid desc");
List<ViewPoint> viewPoints = viewPointService.selectByExample(example);
for (ViewPoint viewPoint : viewPoints) {
String suffix = viewPoint.getTpVpic();
viewPoint.setTpVpic(prefix + suffix);
}
//酒店
hotelExample.setOrderByClause("hid desc");
List<Hotel> hotels = hotelDao.selectByExample(hotelExample);
for (Hotel hotel : hotels) {
String suffix = hotel.getImgUrl();
hotel.setImgUrl(prefixHotel + suffix);
}
//传送景点
model.addAttribute("viewPoints", viewPoints);
model.addAttribute("hotels", hotels);
return "index";
}
}
/**
* 论坛模块
*/
@Controller
@RequestMapping(value = "forum")
public class ForumController {
@Autowired
ForumService forumService;
@Autowired
ForumExample example;
@Autowired
ForumDao forumDao;
@Autowired
Words words;
@Autowired
Reply reply;
@Autowired
ViewPointService viewPointService;
private Model model;
/**
* 倒序查询帖子 跳转forum页面
*/
@RequestMapping(value = "index", method = RequestMethod.GET)
public String index(Model model){
example.setOrderByClause("tp_fid desc");
List<Forum> forums = forumDao.selectByExampleWithBLOBs(example);
model.addAttribute("forums",forums);
return "proscenium/forum/index";
}
/**
* 倒序查询帖子 跳转forum页面
*/
@RequestMapping(value = "content", method = RequestMethod.GET)
public String content(Integer tpFid, Model model){
//封装留言信息
List<Words> byWords = viewPointService.findByWords();
model.addAttribute("lw_list",byWords);
//封装回复信息
List<Reply> byReply = viewPointService.findByReply();
model.addAttribute("lr_list",byReply);
model.addAttribute("viewPoint", viewPoint);
return "proscenium/viewpoint/content";
}
/**
* 前台景点模糊搜索
*/
@RequestMapping(value = "viewPointSearch", method = RequestMethod.GET)
public String viewPointSearch(String keyword, Model model) {
String prefix = "/static/upload/viewavatar/";
ViewPoint viewPoint = new ViewPoint();
viewPoint.setTpVname(keyword);
viewPoint.setTpVtype(keyword);
viewPoint.setTpLocation(keyword);
List<ViewPoint> viewPoints = viewPointDao.viewPointSearch(viewPoint);
for (ViewPoint vp : viewPoints){
String imgUrl = vp.getTpVpic();
vp.setTpVpic(prefix + imgUrl);
}
model.addAttribute("viewPoints", viewPoints);
model.addAttribute("msg", Msg.success("景点查询成功!"));
return "proscenium/viewpoint/view";
}
}
package com.demo.controller;
@Controller
@RequestMapping(value = "view")
public class ViewPointController {
@Autowired
private ViewPointService viewPointService;
private HttpSession session;
@Autowired
private ViewPointExample viewPointExample;
@Autowired
private ViewPointDao viewPointDao;
/**
* 旅游景点跳转
* @return
*/
@RequestMapping(value = "point", method = RequestMethod.GET)
public String viewPoint(ViewPointExample example, Model model) {
example.setOrderByClause("tp_vid desc");
String prefix = "/static/upload/viewavatar/";
List<ViewPoint> viewPoints = viewPointService.selectByExample(example);
for (ViewPoint viewPoint : viewPoints){
String suffix = viewPoint.getTpVpic();
//前端img标签路径
viewPoint.setTpVpic(prefix+suffix);
}
model.addAttribute("viewPoints", viewPoints);
return "proscenium/viewpoint/view";
}
/**
* 前台景点模糊搜索
*
* 待完成
*
System.out.println(uid);
String prefix = "/static/upload/useravatar/";
userService.userDelete(uid);
List<User> users = userService.selectAll();
for (User user : users){
String imgUrl = user.getUpic();
user.setUpic(prefix + imgUrl);
}
session.setAttribute("users", users);
session.setAttribute("msg", Msg.success(uid + "号用户删除成功!"));
return "admin/user_list";
}
/**
* 用户新增表单跳转
*/
@RequestMapping(value = "userform", method = RequestMethod.GET)
public String userForm() {
return "admin/user_form";
}
/**
* 用户新增
*/
@RequestMapping(value = "userinsert", method = RequestMethod.POST)
public String userInsert(String uname, String uemail, String upwd) {
userService.insertUser(uname, uemail, upwd);
session.setAttribute("msg", Msg.success("新增用户成功"));
return "redirect:userlist";
}
/**
* 用户批量删除功能
*/
@RequestMapping(value = "usersectiondelete", method = RequestMethod.GET)
@ResponseBody//返回给前端
public String userSectionDelete(String[] uids) {
for (String uid : uids) {
userService.userDelete(uid);
}
session.setAttribute("msg", Msg.success(Arrays.toString(uids) + "号用户批量删除成功!"));
return "1";
}
/**
* 跳转用户编辑更新界面
*/
}
/**
* 后台论坛模糊搜索
*/
@RequestMapping(value = "forumPointSearch", method = RequestMethod.GET)
public String forumPointSearch(String keyword, Model model) {
Forum forum = new Forum();
forum.setTpTag(keyword);
forum.setTpTitle(keyword);
forum.setTpSubTitle(keyword);
forum.setTpAuthor(keyword);
List<Forum> forums = forumDao.forumPointSearch(forum);
model.addAttribute("forums", forums);
model.addAttribute("msg", Msg.success("论坛查询成功!"));
return "proscenium/forum/index";
}
/**
* 发帖功能 跳转编辑页面
*/
@RequestMapping(value = "issue", method = RequestMethod.GET)
public String issue(Integer uid, Model model){
if (uid != null){
return "proscenium/forum/edit";
}
example.setOrderByClause("tp_fid desc");
List<Forum> forums = forumDao.selectByExampleWithBLOBs(example);
model.addAttribute("forums",forums);
model.addAttribute("msg", Msg.fail("您还未登录!"));
return "proscenium/forum/index";
}
/**
* 编辑页面
*/
@RequestMapping(value = "edit", method = RequestMethod.GET)
List<Hotel> hotels = hotelDao.selectByExample(example);
for (Hotel hotel : hotels){
String fileSuffix = hotel.getImgUrl();
hotel.setImgUrl(filePath + fileSuffix);
}
System.out.println(hotels);
return hotels;
}
}
package com.demo.controller;
@Controller
@RequestMapping(value = "")
public class IndexController {
@Autowired
private ViewPointService viewPointService;
@Autowired
private HotelDao hotelDao;
/**
* 跳转首页
*/
@RequestMapping(value = {"", "index"}, method = RequestMethod.GET)
public String index(ViewPointExample example, Model model) {
HotelExample hotelExample = new HotelExample();
//显示首页的景点
String prefix = "/static/upload/viewavatar/";
//酒店
String prefixHotel = "/static/upload/hotelAvatar/";
example.setOrderByClause("tp_vid desc");
List<ViewPoint> viewPoints = viewPointService.selectByExample(example);
for (ViewPoint viewPoint : viewPoints) {
String suffix = viewPoint.getTpVpic();
viewPoint.setTpVpic(prefix + suffix);
}
//酒店
//获取文件后缀
String fileName = dropFile.getOriginalFilename();
String fileSuffix = fileName.substring(fileName.lastIndexOf('.'));
//文件存放路径
String realPath = request.getSession().getServletContext().getRealPath(filePath);
File file = new File(realPath);
//判断文件是否存在
if (!file.exists()){
file.mkdir();
}
file = new File(realPath,UUID.randomUUID() + fileSuffix);
try {
dropFile.transferTo(file);
} catch (IOException e) {
e.printStackTrace();
}
result.put("fileName",file.getName());
return result;
}
/**
* 后台内容图片上传
* @param dropFile
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "viewContentUpload", method = RequestMethod.POST)
public Map<String, Object> viewContentUpload(MultipartFile dropFile, HttpServletRequest request) {
Map<String, Object> result = new HashMap<>();
//前缀路径 Scheme服务端提供的协议 getServerName服务器名称 port 端口
//String server = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
//图片显示路径
String prefix = "/static/upload/contentFile/";
//获取文件后缀
String fileName = dropFile.getOriginalFilename();
String fileSuffix = fileName.substring(fileName.lastIndexOf('.'));
//文件存放路径
String realPath = request.getSession().getServletContext().getRealPath(prefix);
@RequestMapping(value = "forumEditForm", method = RequestMethod.GET)
public String forumEditForm(Integer tpFid, Model model) {
Forum forum = forumDao.selectByPrimaryKey(tpFid);
model.addAttribute("forum", forum);
return "admin/forum_edit";
}
/**
* 景点新增
*/
@RequestMapping(value = "forumEdit", method = RequestMethod.POST)
public String forumEdit(Forum forum, Model model) {
forumDao.updateByPrimaryKeySelective(forum);
model.addAttribute("msg", Msg.success("更新成功!"));
return "redirect:forumList";
}
/**Traffic**
* 跳转交通列表页面
*/
@RequestMapping(value = "trafficList", method = RequestMethod.GET)
public String trafficList(Model model) {
TrafficExample example = new TrafficExample();
example.setOrderByClause("tp_Tid desc");
List<Traffic> traffics = trafficDao.selectByExample(example);
model.addAttribute("traffics", traffics);
return "admin/traffic_list";
}
/**
* 跳转交通新增页面
* @return
*/
@RequestMapping(value = "trafficInsert", method = RequestMethod.GET)
public String trafficInsert() {
return "admin/traffic_insert";
}
/**
* 提交新增信息
* @return
*/
@RequestMapping(value = "trafficInsertHandler", method = RequestMethod.POST)
public String trafficInsertHandler(Traffic traffic, String currentTime, String arriveTime, Model model) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
// String parseCurrent = simpleDateFormat.format(currentTime);
// String parseArriveTime = simpleDateFormat.format(arriveTime);