作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
本项目分为前后台,前台为普通用户登录,后台为管理员登录;
管理员角色包含以下功能:
管理员登录,管理员信息管理,网站用户信息管理,新闻公告信息管理,演唱会类型信息管理,城市信息管理,剧场信息管理,演唱会信息管理,订单信息管理等功能。
用户角色包含以下功能:
用户登录,按分类查看,查看演唱会详情,加入购物车,提交订单,查看我的订单,修改个人信息,提交评论,演唱会评价信息管理等功能。
环境需要
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. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+CSS+JavaScript+jQuery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中springmvc-servlet.xml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080/ 登录
用户账号/密码: user/123456
管理员账号/密码:admin/admin
运行截图
前台界面
后台界面
相关代码
管理员控制器
package com.action;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.entity.Admin;
import com.service.AdminService;
import com.util.PageHelper;
import com.util.VeDate;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/admin", produces = "text/plain;charset=utf-8")
public class AdminAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private AdminService adminService;
// 管理员登录 1 验证用户名是否存在 2 验证密码是否正确
@RequestMapping("login.action")
public String login() {
String username = this.getRequest().getParameter("username");
String password = this.getRequest().getParameter("password");
Admin adminEntity = new Admin();
adminEntity.setUsername(username);
List<Admin> adminlist = this.adminService.getAdminByCond(adminEntity);
if (adminlist.size() == 0) {
this.getRequest().setAttribute("message", "用户名不存在");
return "admin/index";
} else {
Admin admin = adminlist.get(0);
if (password.equals(admin.getPassword())) {
this.getSession().setAttribute("adminid", admin.getAdminid());
this.getSession().setAttribute("adminname", admin.getUsername());
this.getSession().setAttribute("realname", admin.getRealname());
} else {
this.getRequest().setAttribute("message", "密码错误");
return "admin/index";
}
}
return "admin/main";
}
// 修改密码
@RequestMapping("editpwd.action")
public String editpwd() {
String adminid = (String) this.getSession().getAttribute("adminid");
String password = this.getRequest().getParameter("password");
String repassword = this.getRequest().getParameter("repassword");
Admin admin = this.adminService.getAdminById(adminid);
if (password.equals(admin.getPassword())) {
admin.setPassword(repassword);
this.adminService.updateAdmin(admin);
} else {
this.getRequest().setAttribute("message", "旧密码错误");
}
return "admin/editpwd";
}
// 管理员退出登录
@RequestMapping("exit.action")
public String exit() {
this.getSession().removeAttribute("adminid");
this.getSession().removeAttribute("adminname");
this.getSession().removeAttribute("realname");
return "admin/index";
}
// 准备添加数据
@RequestMapping("createAdmin.action")
public String createAdmin() {
return "admin/addadmin";
}
// 添加数据
@RequestMapping("addAdmin.action")
public String addAdmin(Admin admin) {
admin.setAddtime(VeDate.getStringDateShort());
this.adminService.insertAdmin(admin);
return "redirect:/admin/createAdmin.action";
}
// 通过主键删除数据
@RequestMapping("deleteAdmin.action")
public String deleteAdmin(String id) {
this.adminService.deleteAdmin(id);
return "redirect:/admin/getAllAdmin.action";
}
// 批量删除数据
@RequestMapping("deleteAdminByIds.action")
public String deleteAdminByIds() {
String[] ids = this.getRequest().getParameterValues("adminid");
for (String adminid : ids) {
this.adminService.deleteAdmin(adminid);
}
return "redirect:/admin/getAllAdmin.action";
}
// 更新数据
@RequestMapping("updateAdmin.action")
public String updateAdmin(Admin admin) {
this.adminService.updateAdmin(admin);
return "redirect:/admin/getAllAdmin.action";
}
// 显示全部数据
@RequestMapping("getAllAdmin.action")
public String getAllAdmin(String number) {
List<Admin> adminList = this.adminService.getAllAdmin();
PageHelper.getPage(adminList, "admin", null, null, 10, number, this.getRequest(), null);
return "admin/listadmin";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryAdminByCond.action")
public String queryAdminByCond(String cond, String name, String number) {
Admin admin = new Admin();
if (cond != null) {
if ("username".equals(cond)) {
admin.setUsername(name);
}
if ("password".equals(cond)) {
admin.setPassword(name);
}
if ("realname".equals(cond)) {
admin.setRealname(name);
}
if ("contact".equals(cond)) {
admin.setContact(name);
}
if ("addtime".equals(cond)) {
admin.setAddtime(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.adminService.getAdminByLike(admin), "admin", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryadmin";
}
// 按主键查询数据
@RequestMapping("getAdminById.action")
public String getAdminById(String id) {
Admin admin = this.adminService.getAdminById(id);
this.getRequest().setAttribute("admin", admin);
return "admin/editadmin";
}
public AdminService getAdminService() {
return adminService;
}
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
}
购物车控制器
package com.action;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.entity.Cart;
import com.service.CartService;
import com.entity.Users;
import com.entity.Film;
import com.service.UsersService;
import com.service.FilmService;
import com.util.PageHelper;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/cart", produces = "text/plain;charset=utf-8")
public class CartAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private CartService cartService;
@Autowired
@Resource
private UsersService usersService;
@Autowired
@Resource
private FilmService filmService;
// 准备添加数据
@RequestMapping("createCart.action")
public String createCart() {
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Film> filmList = this.filmService.getAllFilm();
this.getRequest().setAttribute("filmList", filmList);
return "admin/addcart";
}
// 添加数据
@RequestMapping("addCart.action")
public String addCart(Cart cart) {
this.cartService.insertCart(cart);
return "redirect:/cart/createCart.action";
}
// 通过主键删除数据
@RequestMapping("deleteCart.action")
public String deleteCart(String id) {
this.cartService.deleteCart(id);
return "redirect:/cart/getAllCart.action";
}
// 批量删除数据
@RequestMapping("deleteCartByIds.action")
public String deleteCartByIds() {
String[] ids = this.getRequest().getParameterValues("cartid");
for (String cartid : ids) {
this.cartService.deleteCart(cartid);
}
return "redirect:/cart/getAllCart.action";
}
// 更新数据
@RequestMapping("updateCart.action")
public String updateCart(Cart cart) {
this.cartService.updateCart(cart);
return "redirect:/cart/getAllCart.action";
}
// 显示全部数据
@RequestMapping("getAllCart.action")
public String getAllCart(String number) {
List<Cart> cartList = this.cartService.getAllCart();
PageHelper.getPage(cartList, "cart", null, null, 10, number, this.getRequest(), null);
return "admin/listcart";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryCartByCond.action")
public String queryCartByCond(String cond, String name, String number) {
Cart cart = new Cart();
if (cond != null) {
if ("username".equals(cond)) {
cart.setUsername(name);
}
if ("filmname".equals(cond)) {
cart.setFilmname(name);
}
if ("num".equals(cond)) {
cart.setNum(name);
}
if ("price".equals(cond)) {
cart.setPrice(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.cartService.getCartByLike(cart), "cart", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querycart";
}
// 按主键查询数据
@RequestMapping("getCartById.action")
public String getCartById(String id) {
Cart cart = this.cartService.getCartById(id);
this.getRequest().setAttribute("cart", cart);
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Film> filmList = this.filmService.getAllFilm();
this.getRequest().setAttribute("filmList", filmList);
return "admin/editcart";
}
public CartService getCartService() {
return cartService;
}
public void setCartService(CartService cartService) {
this.cartService = cartService;
}
}
电影控制器
package com.action;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.entity.Film;
import com.service.FilmService;
import com.entity.Cate;
import com.service.CateService;
import com.util.PageHelper;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/film", produces = "text/plain;charset=utf-8")
public class FilmAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private FilmService filmService;
@Autowired
@Resource
private CateService cateService;
// 准备添加数据
@RequestMapping("createFilm.action")
public String createFilm() {
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/addjiancai";
}
// 添加数据
@RequestMapping("addFilm.action")
public String addFilm(Film film) {
film.setHits("0");
film.setSellnum("0");
this.filmService.insertFilm(film);
return "redirect:/film/createFilm.action";
}
// 通过主键删除数据
@RequestMapping("deleteFilm.action")
public String deleteFilm(String id) {
this.filmService.deleteFilm(id);
return "redirect:/film/getAllFilm.action";
}
// 批量删除数据
@RequestMapping("deleteFilmByIds.action")
public String deleteFilmByIds() {
String[] ids = this.getRequest().getParameterValues("filmid");
for (String filmid : ids) {
this.filmService.deleteFilm(filmid);
}
return "redirect:/film/getAllFilm.action";
}
// 更新数据
@RequestMapping("updateFilm.action")
public String updateFilm(Film film) {
this.filmService.updateFilm(film);
return "redirect:/film/getAllFilm.action";
}
// 显示全部数据
@RequestMapping("getAllFilm.action")
public String getAllFilm(String number) {
List<Film> filmList = this.filmService.getAllFilm();
PageHelper.getPage(filmList, "film", null, null, 10, number, this.getRequest(), null);
// return "admin/listfilm";
return "admin/listjiancai";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryFilmByCond.action")
public String queryFilmByCond(String cond, String name, String number) {
Film film = new Film();
if (cond != null) {
if ("filmname".equals(cond)) {
film.setFilmname(name);
}
if ("image".equals(cond)) {
film.setImage(name);
}
if ("cateid".equals(cond)) {
film.setCatename(name);
}
if ("price".equals(cond)) {
film.setPrice(name);
}
if ("recommend".equals(cond)) {
film.setRecommend(name);
}
if ("thestart".equals(cond)) {
film.setThestart(name);
}
if ("theend".equals(cond)) {
film.setTheend(name);
}
if ("hits".equals(cond)) {
film.setHits(name);
}
if ("sellnum".equals(cond)) {
film.setSellnum(name);
}
if ("contents".equals(cond)) {
film.setContents(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.filmService.getFilmByLike(film), "film", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
// return "admin/queryfilm";
return "admin/queryjiancai";
}
// 按主键查询数据
@RequestMapping("getFilmById.action")
public String getFilmById(String id) {
Film film = this.filmService.getFilmById(id);
this.getRequest().setAttribute("film", film);
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/editfilm";
}
public FilmService getFilmService() {
return filmService;
}
public void setFilmService(FilmService filmService) {
this.filmService = filmService;
}
}
用户控制器
package com.action;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.entity.Users;
import com.service.UsersService;
import com.util.PageHelper;
import com.util.VeDate;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/users" , produces = "text/plain;charset=utf-8")
public class UsersAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private UsersService usersService;
// 准备添加数据
@RequestMapping("createUsers.action")
public String createUsers() {
return "admin/addusers";
}
// 添加数据
@RequestMapping("addUsers.action")
public String addUsers(Users users) {
users.setRegdate(VeDate.getStringDateShort());
this.usersService.insertUsers(users);
return "redirect:/users/createUsers.action";
}
// 通过主键删除数据
@RequestMapping("deleteUsers.action")
public String deleteUsers(String id) {
this.usersService.deleteUsers(id);
return "redirect:/users/getAllUsers.action";
}
// 批量删除数据
@RequestMapping("deleteUsersByIds.action")
public String deleteUsersByIds() {
String[] ids = this.getRequest().getParameterValues("usersid");
for (String usersid : ids) {
this.usersService.deleteUsers(usersid);
}
return "redirect:/users/getAllUsers.action";
}
// 更新数据
@RequestMapping("updateUsers.action")
public String updateUsers(Users users) {
this.usersService.updateUsers(users);
return "redirect:/users/getAllUsers.action";
}
// 显示全部数据
@RequestMapping("getAllUsers.action")
public String getAllUsers(String number) {
List<Users> usersList = this.usersService.getAllUsers();
PageHelper.getPage(usersList, "users", null, null, 10, number, this.getRequest(), null);
return "admin/listusers";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryUsersByCond.action")
public String queryUsersByCond(String cond, String name, String number) {
Users users = new Users();
if(cond != null){
if ("username".equals(cond)) {
users.setUsername(name);
}
if ("password".equals(cond)) {
users.setPassword(name);
}
if ("realname".equals(cond)) {
users.setRealname(name);
}
if ("sex".equals(cond)) {
users.setSex(name);
}
if ("birthday".equals(cond)) {
users.setBirthday(name);
}
if ("contact".equals(cond)) {
users.setContact(name);
}
if ("regdate".equals(cond)) {
users.setRegdate(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.usersService.getUsersByLike(users), "users", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryusers";
}
// 按主键查询数据
@RequestMapping("getUsersById.action")
public String getUsersById(String id ) {
Users users = this.usersService.getUsersById(id);
this.getRequest().setAttribute("users", users);
return "admin/editusers";
}
public UsersService getUsersService() { return usersService; }
public void setUsersService(UsersService usersService) { this.usersService = usersService; }
}
如果也想学习本系统,下面领取。回复:193ssm