源码获取:俺的博客首页 "资源" 里下载!
项目介绍
本项目包含前后台,前台为普通用户登录,后台为管理员登录;
管理员角色包含以下功能:
管理员登陆,管理员管理,网站公告管理,酒店和旅行社管理,宾馆信息管理,用户信息管理,预定信息管理,留言管理,宾馆预定管理等功能。
用户角色包含以下功能:
用户注册,用户登陆,景点介绍,酒店信息查看,旅行社查看,留言板,宾馆预定,宾馆预订管理,个人中心管理等功能。
环境需要
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版本;
6.是否Maven项目:否;
技术栈
1.后端:servlet+struts
2.前端:JSP+CSS+JavaScript+jsp+mysql
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中util/DBO.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
管理员账号/密码:admin/admin
用户账号/密码: user/123456
管理员控制层:
@Controller
@RequestMapping("/manager")
public class AdminController extends BaseController {
@Autowired
AdminService adminService;
@RequestMapping("/adminList")
public ModelAndView adminList(PageParam pageParam, @RequestParam(value = "query", required = false) String query) {
ModelAndView mv = this.getModeAndView();
if(pageParam.getPageNumber()<1){
pageParam =new PageParam();
long count = 0;
try {
count = adminService.count();
} catch (Exception e) {
e.printStackTrace();
}
pageParam.setCount(count);
if(count<=10){
pageParam.setSize(1);
}else{
pageParam.setSize(count%10==0?count/10:count/10+1);
}
pageParam.setPageNumber(1);
pageParam.setPageSize(10);
}
List<Admin> list = adminService.findByPage(pageParam.getPageNumber(),pageParam.getPageSize(), query);
mv.addObject("pageData", list);
if (Tools.notEmpty(query)) {
mv.addObject("query", query);
pageParam.setCount(list.size());
if (list.size() > pageParam.getPageSize()) {
pageParam.setSize(list.size() / pageParam.getPageSize());
} else {
pageParam.setSize(1);
}
}
mv.addObject("pageParam",pageParam);
mv.setViewName("admin/adminList");
return mv;
}
@RequestMapping("/adminAdd")
public ModelAndView adminAdd(){
ModelAndView mv = this.getModeAndView();
mv.addObject("entity",new Admin());
mv.setViewName("admin/adminEdit");
return mv;
}
@RequestMapping("/adminView")
public ModelAndView adminView(String id){
ModelAndView mv = this.getModeAndView();
try {
mv.addObject("entity",adminService.findById(id));
}catch (Exception e){
e.printStackTrace();
}
mv.setViewName("admin/adminView");
return mv;
}
@RequestMapping("/adminEdit")
public ModelAndView adminEdit(String id){
ModelAndView mv = this.getModeAndView();
try {
mv.addObject("entity",adminService.findById(id));
}catch (Exception e){
e.printStackTrace();
}
mv.setViewName("admin/adminEdit");
return mv;
}
@RequestMapping("/adminSave")
public ModelAndView adminSave(HttpServletRequest request, String id){
ModelAndView mv = this.getModeAndView();
Admin entity = null;
try {
if(Tools.notEmpty(id)){
entity = adminService.findById(id);
}else{
entity = new Admin();
}
this.bindValidateRequestEntity(request,entity);
if (Tools.isEmpty(entity.getId())){
Admin object = adminService.findByUserName(entity.getUserName());
if (object != null) {
mv.addObject("message","用户名已存在!");
mv.addObject("entity",entity);
mv.setViewName("admin/adminEdit");
return mv;
}
entity.setId(Tools.getUUID());
adminService.save(entity);
}else{
adminService.update(entity);
}
} catch (Exception e) {
e.printStackTrace();
}
mv.addObject("pageData", adminService.findByPage(1, 10,null));
PageParam pageParam =new PageParam();
long count = 0;
try {
count = adminService.count();
} catch (Exception e) {
e.printStackTrace();
}
pageParam.setCount(count);
if(count<=10){
pageParam.setSize(1);
}else{
pageParam.setSize(count%10==0?count/10:count/10+1);
}
pageParam.setPageNumber(1);
pageParam.setPageSize(10);
mv.addObject("pageParam",pageParam);
mv.setViewName("admin/adminList");
return mv;
}
@RequestMapping("/adminDelete")
public String adminDelete(String id){
if(Tools.notEmpty(id)){
try {
adminService.deleteByid(id);
}catch (Exception e){
e.printStackTrace();
}
}
return REDIRECT+"/manager/adminList";
}
}
用户管理控制层:
@Controller
@RequestMapping("/manager")
public class UserController extends BaseController {
@Autowired
UserService userService;
@RequestMapping("/userList")
public ModelAndView userList(PageParam pageParam, @RequestParam(value = "query", required = false) String query) {
ModelAndView mv = this.getModeAndView();
if(pageParam.getPageNumber()<1){
pageParam =new PageParam();
long count = 0;
try {
count = userService.count();
} catch (Exception e) {
e.printStackTrace();
}
pageParam.setCount(count);
if(count<=10){
pageParam.setSize(1);
}else{
pageParam.setSize(count%10==0?count/10:count/10+1);
}
pageParam.setPageNumber(1);
pageParam.setPageSize(10);
}
List<User> list = userService.findByPage(pageParam.getPageNumber(),pageParam.getPageSize(), query);
mv.addObject("pageData", list);
if (Tools.notEmpty(query)) {
mv.addObject("query", query);
pageParam.setCount(list.size());
if (list.size() > pageParam.getPageSize()) {
pageParam.setSize(list.size() / pageParam.getPageSize());
} else {
pageParam.setSize(1);
}
}
mv.addObject("pageParam",pageParam);
mv.setViewName("user/allUsers");
return mv;
}
@RequestMapping("/userAdd")
public ModelAndView userAdd(){
ModelAndView mv = this.getModeAndView();
mv.addObject("entity",new User());
mv.setViewName("user/userEdit");
return mv;
}
@RequestMapping("/userView")
public ModelAndView userView(String id){
ModelAndView mv = this.getModeAndView();
try {
mv.addObject("entity",userService.findById(id));
}catch (Exception e){
e.printStackTrace();
}
mv.setViewName("user/userView");
return mv;
}
@RequestMapping("/userEdit")
public ModelAndView userEdit(String id){
ModelAndView mv = this.getModeAndView();
try {
mv.addObject("entity",userService.findById(id));
}catch (Exception e){
e.printStackTrace();
}
mv.setViewName("user/userEdit");
return mv;
}
@RequestMapping("/userSave")
public ModelAndView userSave(HttpServletRequest request, String id, RedirectAttributes redirectAttributes){
ModelAndView mv = this.getModeAndView();
User entity = null;
try {
if(Tools.notEmpty(id)){
entity = userService.findById(id);
}else{
entity = new User();
}
this.bindValidateRequestEntity(request,entity);
if (Tools.isEmpty(entity.getId())){
User object = userService.findByUserName(entity.getUserName());
if (object != null) {
mv.addObject("message","用户名已存在!");
mv.addObject("entity",entity);
mv.setViewName("user/userEdit");
return mv;
}
entity.setId(Tools.getUUID());
userService.save(entity);
}else{
userService.update(entity);
}
} catch (Exception e) {
e.printStackTrace();
}
mv.addObject("pageData", userService.findByPage(1, 10,null));
PageParam pageParam =new PageParam();
long count = 0;
try {
count = userService.count();
} catch (Exception e) {
e.printStackTrace();
}
pageParam.setCount(count);
if(count<=10){
pageParam.setSize(1);
}else{
pageParam.setSize(count%10==0?count/10:count/10+1);
}
pageParam.setPageNumber(1);
pageParam.setPageSize(10);
mv.addObject("pageParam",pageParam);
mv.setViewName("user/allUsers");
return mv;
}
@RequestMapping("/userDelete")
public String userDelete(String id){
if(Tools.notEmpty(id)){
try {
userService.deleteByid(id);
}catch (Exception e){
e.printStackTrace();
}
}
return REDIRECT+"/manager/userList";
}
}
登录管理控制层:
@Controller
public class LoginController extends BaseController {
@Autowired
AdminService adminService;
@RequestMapping("/login")
public String login(HttpServletRequest request){
Object user = request.getSession().getAttribute("admin");
if (user != null) {
return REDIRECT+"/manager/index";
}
return "login";
}
@RequestMapping("/loging")
public String loging(String userName,String password,RedirectAttributes redirectAttributes,HttpServletRequest request){
if (Tools.isEmpty(userName)||Tools.isEmpty(password)){
redirectAttributes.addFlashAttribute("message","用户名密码不得为空!");
return REDIRECT+"/login";
}
try {
Admin admin = adminService.login(userName, password);
if (Tools.isEmpty(admin)){
redirectAttributes.addFlashAttribute("message","用户名不存在或密码错误!");
return REDIRECT+"/login";
}else{
if (admin.getState() == 1) {
request.getSession().setAttribute("admin", admin);
return REDIRECT+"/manager/index";
} else {
redirectAttributes.addFlashAttribute("message","账户已被停用!");
return REDIRECT+"/login";
}
}
} catch (Exception e) {
e.printStackTrace();
}
return REDIRECT+"/login";
}
@RequestMapping("/logout")
public String logout(HttpServletRequest request){
Object user = request.getSession().getAttribute("admin");
if (user != null) {
request.getSession().removeAttribute("admin");
}
return "/login";
}
}
源码获取:俺的博客首页 "资源" 里下载!