作者主页:源码空间站2022
简介: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
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
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
nameList = new ArrayList(); - List
valueList = new ArrayList(); - 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.List;
-
- import javax.annotation.Resource;
-
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
-
- import com.entity.Peihuo;
- import com.service.PeihuoService;
-
- //定义为控制器
- @Controller
- // 设置路径
- @RequestMapping(value = "/ajax", produces = "text/plain;charset=utf-8")
- public class AjaxAction extends BaseAction {
-
- @Autowired
- @Resource
- private PeihuoService peihuoService;
-
- // 准备添加数据
- @RequestMapping("getPeihuo.action")
- @ResponseBody
- public String getPeihuo() throws JSONException {
- String cityid = this.getRequest().getParameter("cityid");
- Peihuo peihuo = new Peihuo();
- peihuo.setCityid(cityid);
- List
peihuoList = this.peihuoService.getPeihuoByCond(peihuo); - JSONArray peihuoid = new JSONArray(); // 存放ID
- JSONArray peihuoname = new JSONArray(); // 存放名称
- for (Peihuo c : peihuoList) {
- peihuoid.put(c.getPeihuoid());
- peihuoname.put(c.getPeihuoname());
- }
- JSONObject json = new JSONObject();
- json.put("peihuoid", peihuoid.toString().replaceAll("\"", ""));
- json.put("peihuoname", peihuoname.toString().replaceAll("\"", ""));
- System.out.println(json.toString());
- return json.toString();
- }
-
- }
- 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.Article;
- import com.service.ArticleService;
- import com.util.PageHelper;
- import com.util.VeDate;
-
- //定义为控制器
- @Controller
- // 设置路径
- @RequestMapping(value = "/article", produces = "text/plain;charset=utf-8")
- public class ArticleAction extends BaseAction {
- // 注入Service 由于标签的存在 所以不需要getter setter
- @Autowired
- @Resource
- private ArticleService articleService;
-
- // 准备添加数据
- @RequestMapping("createArticle.action")
- public String createArticle() {
- return "admin/addarticle";
- }
-
- // 添加数据
- @RequestMapping("addArticle.action")
- public String addArticle(Article article) {
- article.setAddtime(VeDate.getStringDateShort());
- article.setHits("0");
- this.articleService.insertArticle(article);
- return "redirect:/article/createArticle.action";
- }
-
- // 通过主键删除数据
- @RequestMapping("deleteArticle.action")
- public String deleteArticle(String id) {
- this.articleService.deleteArticle(id);
- return "redirect:/article/getAllArticle.action";
- }
-
- // 批量删除数据
- @RequestMapping("deleteArticleByIds.action")
- public String deleteArticleByIds() {
- String[] ids = this.getRequest().getParameterValues("articleid");
- for (String articleid : ids) {
- this.articleService.deleteArticle(articleid);
- }
- return "redirect:/article/getAllArticle.action";
- }
-
- // 更新数据
- @RequestMapping("updateArticle.action")
- public String updateArticle(Article article) {
- this.articleService.updateArticle(article);
- return "redirect:/article/getAllArticle.action";
- }
-
- // 显示全部数据
- @RequestMapping("getAllArticle.action")
- public String getAllArticle(String number) {
- List
articleList = this.articleService.getAllArticle(); - PageHelper.getPage(articleList, "article", null, null, 10, number, this.getRequest(), null);
- return "admin/listarticle";
- }
-
- // 按条件查询数据 (模糊查询)
- @RequestMapping("queryArticleByCond.action")
- public String queryArticleByCond(String cond, String name, String number) {
- Article article = new Article();
- if (cond != null) {
- if ("title".equals(cond)) {
- article.setTitle(name);
- }
- if ("image".equals(cond)) {
- article.setImage(name);
- }
- if ("contents".equals(cond)) {
- article.setContents(name);
- }
- if ("addtime".equals(cond)) {
- article.setAddtime(name);
- }
- if ("hits".equals(cond)) {
- article.setHits(name);
- }
- }
-
- List
nameList = new ArrayList(); - List
valueList = new ArrayList(); - nameList.add(cond);
- valueList.add(name);
- PageHelper.getPage(this.articleService.getArticleByLike(article), "article", nameList, valueList, 10, number, this.getRequest(),
- "query");
- name = null;
- cond = null;
- return "admin/queryarticle";
- }
-
- // 按主键查询数据
- @RequestMapping("getArticleById.action")
- public String getArticleById(String id) {
- Article article = this.articleService.getArticleById(id);
- this.getRequest().setAttribute("article", article);
- return "admin/editarticle";
- }
-
- public ArticleService getArticleService() {
- return articleService;
- }
-
- public void setArticleService(ArticleService articleService) {
- this.articleService = articleService;
- }
-
- }
- package com.action;
-
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Map;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
-
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.json.JSONException;
- import org.json.JSONObject;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.context.request.ServletRequestAttributes;
-
- /**
- * Action 基类
- */
- @Controller
- public class BaseAction {
-
- /* 日志 */
- protected final Log log = LogFactory.getLog(getClass());
-
- /* 获取基本环境 */
- public Map
getParameters() {// 封装为Map的requestParameters - ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
- return attrs.getRequest().getParameterMap();
- }
-
- public HttpServletRequest getRequest() {
- ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
- return attrs.getRequest();
- }
-
- public HttpSession getSession() {
- HttpSession session = null;
- try {
- session = this.getRequest().getSession();
- } catch (Exception e) {
- }
- return session;
- }
-
- /* 向客户端输出操作成功或失败信息 */
- public void writeJsonResponse(String success) throws IOException, JSONException {
- ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
- HttpServletResponse response = attrs.getResponse();
- response.setContentType("text/json;charset=UTF-8");
- PrintWriter out = response.getWriter();
- // 将要被返回到客户端的对象
- JSONObject json = new JSONObject();
- json.accumulate("result", success);
- System.out.println(json.toString());
- out.println(json.toString());
- out.flush();
- out.close();
- }
- }
如果也想学习本系统,下面领取。关注并回复:077ssm