0 项目说明
基于Spring MVC的动态旅游网站设计与实现
提示:适合用于课程设计或毕业设计,工作量达标,源码开放
1 项目介绍
对比国内外的旅游网站,国内基本都是一些专业的大公司运作的消费者旅游网站,而非商业性质的旅游信息网站却很少。而本课题选择的这个动态网站建设是基于非商业用途的旅游信息交互式网站,网站的信息来源可以来源于管理者,也可以来源于用户。在用户的基数够大的情况下,会出现很多优质的旅游信息,为其他用户提供服务。
本系统采用三层结构,确定系统的Java作为编程语言,View层采用JSP,Spring 作为整个项目的整合核心管理所有 Bean 的生命周期行为,Dao层采用MyBatis,MySQL作为数据库,SpringMVC 的 Controller作为整个应用的控制器。整个系统要操作方便、易于维护、灵活使用。 本系统采用以上方法,基本实现了用户模块、景点模块、酒店模块、论坛模块、定制模块、留言回复功能,及相应模块的后台管理功能等。
2 技术
使用Java作为开发语言
2.1 后端
- Spring
- SpringMVC
- MyBatis
2.2 前端
- bootstrap
- jQuery
- 数据库
- MySQL 5.5
2.3 本项目数据库
src/resources/trip_web_db.sql
2.4 工具
- IDEA
- Maven
- Git
- dropzone
3 项目源码
package cn.zm.trip.web.controller;
import cn.zm.trip.web.commons.Msg;
import cn.zm.trip.web.dao.ForumDao;
import cn.zm.trip.web.domain.Forum;
import cn.zm.trip.web.domain.ForumExample;
import cn.zm.trip.web.domain.User;
import cn.zm.trip.web.domain.ViewPoint;
import cn.zm.trip.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping(value = "user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private HttpSession session;
@Autowired
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";
}
@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";
}
/**
* 跳转个人信息
*/
@RequestMapping(value = "info", method = RequestMethod.GET)
public String info(String uid) {
User user = userService.userGet(uid);
String prefix = "/static/upload/useravatar/";
String suffix = user.getUpic();
user.setUpic(prefix+suffix);
session.setAttribute("user", user);
System.out.println(user);
return "proscenium/user/info";
}
/**
* 跳转编辑信息
*/
@RequestMapping(value = "edit", method = RequestMethod.GET)
public String edit() {
return "proscenium/user/edit";
}
/**
* 前台用户个人信息管理
*/
@RequestMapping(value = "useredithandle", method = RequestMethod.POST)
public String userEditHandle(User user) {
//显示首页的景点
String prefix = "/static/upload/useravatar/";
userService.updataUserInfo(user);
String suffix = user.getUpic();
user.setUpic(prefix + suffix);
session.setAttribute("user", userService.userGet(user.getUid()));
session.setAttribute("msg", Msg.success("用户信息更新成功!"));
return "proscenium/user/edit";
}
/**
* 跳转用户发表管理
*/
@RequestMapping(value = "forum", method = RequestMethod.GET)
public String forum(Integer uid, Model model) {
ForumExample example = new ForumExample();
example.setOrderByClause("tp_fid desc");
List<Forum> forums = forumDao.selectByExample(example);
List<Forum> queryForums = new ArrayList<>();
for(Forum forum : forums){
if (uid.equals(forum.getTpAuthorId())){
queryForums.add(forum);
}
}
model.addAttribute("forums", queryForums);
return "proscenium/user/forum";
}
/**
* 用户发表管理单击删除
*/
@RequestMapping(value = "forumDelete", method = RequestMethod.GET)
public String forumDelete(Integer tpFid, Integer uid, Model model) {
forumDao.deleteByPrimaryKey(tpFid);
ForumExample example = new ForumExample();
example.setOrderByClause("tp_fid desc");
List<Forum> forums = forumDao.selectByExample(example);
List<Forum> queryForums = new ArrayList<>();
for(Forum forum : forums){
if (uid.equals(forum.getTpAuthorId())){
queryForums.add(forum);
}
}
model.addAttribute("forums", queryForums);
return "proscenium/user/forum";
}
///**
// * 用户发表论坛编辑
// */
//@RequestMapping(value = "forumEdit", method = RequestMethod.GET)
//public String forumEdit(Integer tpFid, Model model) {
// Forum forum = forumDao.selectByPrimaryKey(tpFid);
// model.addAttribute("forum", forum);
// return "proscenium/user/forum_edit";
//}
}