diff --git a/src/com/controller/AdminController.java b/src/com/controller/AdminController.java new file mode 100644 index 0000000..5367480 --- /dev/null +++ b/src/com/controller/AdminController.java @@ -0,0 +1,226 @@ +package com.controller; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +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.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.Page; +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 AdminController extends BaseController { + // @Autowired的作用是自动注入依赖的ServiceBean + @Autowired + private AdminService adminService; + + // 管理员准备 + @RequestMapping("index.action") + public String index() { + return "admin/index"; + } + + // 管理员登录 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 "redirect:/admin/index.action"; + } 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()); + this.getSession().setAttribute("role", "管理员"); + } else { + this.getRequest().setAttribute("message", "密码错误"); + return "redirect:/admin/index.action"; + } + } + return "admin/main"; + } + + // 管理员准备修改密码 + @RequestMapping("prePwd.action") + public String prePwd() { + return "admin/editpwd"; + } + // 修改密码 + @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 "redirect:/admin/prePwd.action"; + } + + // 管理员退出登录 + @RequestMapping("exit.action") + public String exit() { + this.getSession().removeAttribute("adminid"); + this.getSession().removeAttribute("adminname"); + this.getSession().removeAttribute("realname"); + return "redirect:/admin/index.action"; + } + // 准备添加数据 + @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"; + } + + // AJAX添加数据 + @RequestMapping("xaddAdmin.action") + @ResponseBody //将java对象转为json格式的数据 + public String xaddAdmin(Admin admin) { + admin.setAddtime(VeDate.getStringDateShort()); + int x = this.adminService.insertAdmin(admin); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + // 通过主键删除数据 + @RequestMapping("deleteAdmin.action") + public String deleteAdmin(String id) { + this.adminService.deleteAdmin(id); + return "redirect:/admin/getAllAdmin.action"; + } + + // AJAX通过主键删除数据 + @RequestMapping("xdeleteAdmin.action") + @ResponseBody //将java对象转为json格式的数据 + public String xdeleteAdmin(String id) { + int x = this.adminService.deleteAdmin(id); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 批量删除数据 + @RequestMapping("deleteAdminByIds.action") + public String deleteAdminByIds() { + String[] ids = this.getRequest().getParameterValues("adminid"); + if (ids != null) { + 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"; + } + + // AJAX更新数据 + @RequestMapping("xupdateAdmin.action") + @ResponseBody //将java对象转为json格式的数据 + public String xupdateAdmin(Admin admin) { + int x = this.adminService.updateAdmin(admin); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 显示全部数据 + @RequestMapping("getAllAdmin.action") + public String getAllAdmin(String number) { + List adminList = this.adminService.getAllAdmin(); + PageHelper.getUserPage(adminList, "admin", "getAllAdmin", 10, number, this.getRequest()); + return "admin/listadmin"; + } + + // AJAX显示全部数据 + @RequestMapping(value = "getDataList.action", produces = "application/json; charset=utf-8") + @ResponseBody //将java对象转为json格式的数据 + public Map getDataList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) { + // 定义一个Map对象 用来返回数据 + Map map = new HashMap(); + Page pager = com.github.pagehelper.PageHelper.startPage(page, limit);// 定义当前页和分页条数 + List list = this.adminService.getAllAdmin(); + // 返回的map中定义Layui的数据格式 + map.put("count", pager.getTotal()); + map.put("data", list); + map.put("code", 0); + map.put("msg", ""); + return map; + } + + // 按条件查询数据 (模糊查询) + @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"; + } + + +} diff --git a/src/com/controller/ArticleController.java b/src/com/controller/ArticleController.java new file mode 100644 index 0000000..17c56b4 --- /dev/null +++ b/src/com/controller/ArticleController.java @@ -0,0 +1,184 @@ +package com.controller; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +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.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.Page; +import com.entity.Article; +import com.service.ArticleService; +import com.entity.Banner; +import com.service.BannerService; +import com.util.PageHelper; +import com.util.VeDate; +//定义为控制器 +@Controller +// 设置路径 +@RequestMapping(value = "/article" , produces = "text/plain;charset=utf-8") +public class ArticleController extends BaseController { + // @Autowired的作用是自动注入依赖的ServiceBean + @Autowired + private ArticleService articleService; + @Autowired + private BannerService bannerService; + + // 准备添加数据 + @RequestMapping("createArticle.action") + public String createArticle() { + List bannerList = this.bannerService.getAllBanner(); + this.getRequest().setAttribute("bannerList", bannerList); + 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"; + } + + // AJAX添加数据 + @RequestMapping("xaddArticle.action") + @ResponseBody //将java对象转为json格式的数据 + public String xaddArticle(Article article) { + article.setAddtime(VeDate.getStringDateShort()); + article.setHits("0"); + int x = this.articleService.insertArticle(article); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + // 通过主键删除数据 + @RequestMapping("deleteArticle.action") + public String deleteArticle(String id) { + this.articleService.deleteArticle(id); + return "redirect:/article/getAllArticle.action"; + } + + // AJAX通过主键删除数据 + @RequestMapping("xdeleteArticle.action") + @ResponseBody //将java对象转为json格式的数据 + public String xdeleteArticle(String id) { + int x = this.articleService.deleteArticle(id); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 批量删除数据 + @RequestMapping("deleteArticleByIds.action") + public String deleteArticleByIds() { + String[] ids = this.getRequest().getParameterValues("articleid"); + if (ids != null) { + 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"; + } + + // AJAX更新数据 + @RequestMapping("xupdateArticle.action") + @ResponseBody //将java对象转为json格式的数据 + public String xupdateArticle(Article article) { + int x = this.articleService.updateArticle(article); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 显示全部数据 + @RequestMapping("getAllArticle.action") + public String getAllArticle(String number) { + List
articleList = this.articleService.getAllArticle(); + PageHelper.getUserPage(articleList, "article", "getAllArticle", 10, number, this.getRequest()); + return "admin/listarticle"; + } + + // AJAX显示全部数据 + @RequestMapping(value = "getDataList.action", produces = "application/json; charset=utf-8") + @ResponseBody //将java对象转为json格式的数据 + public Map getDataList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) { + // 定义一个Map对象 用来返回数据 + Map map = new HashMap(); + Page
pager = com.github.pagehelper.PageHelper.startPage(page, limit);// 定义当前页和分页条数 + List
list = this.articleService.getAllArticle(); + // 返回的map中定义Layui的数据格式 + map.put("count", pager.getTotal()); + map.put("data", list); + map.put("code", 0); + map.put("msg", ""); + return map; + } + + // 按条件查询数据 (模糊查询) + @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 ("bannerid".equals(cond)) { + article.setBannerid(name); + } + if ("image".equals(cond)) { + article.setImage(name); + } + if ("istop".equals(cond)) { + article.setIstop(name); + } + if ("isflv".equals(cond)) { + article.setIsflv(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); + List bannerList = this.bannerService.getAllBanner(); + this.getRequest().setAttribute("bannerList", bannerList); + return "admin/editarticle"; + } + + +} diff --git a/src/com/controller/AsksController.java b/src/com/controller/AsksController.java new file mode 100644 index 0000000..5d2ead6 --- /dev/null +++ b/src/com/controller/AsksController.java @@ -0,0 +1,159 @@ +package com.controller; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +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.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.Page; +import com.entity.Asks; +import com.service.AsksService; +import com.util.PageHelper; +import com.util.VeDate; +//定义为控制器 +@Controller +// 设置路径 +@RequestMapping(value = "/asks" , produces = "text/plain;charset=utf-8") +public class AsksController extends BaseController { + // @Autowired的作用是自动注入依赖的ServiceBean + @Autowired + private AsksService asksService; + + // 准备添加数据 + @RequestMapping("createAsks.action") + public String createAsks() { + return "admin/addasks"; + } + // 添加数据 + @RequestMapping("addAsks.action") + public String addAsks(Asks asks) { + asks.setAddtime(VeDate.getStringDateShort()); + this.asksService.insertAsks(asks); + return "redirect:/asks/createAsks.action"; + } + + // AJAX添加数据 + @RequestMapping("xaddAsks.action") + @ResponseBody //将java对象转为json格式的数据 + public String xaddAsks(Asks asks) { + asks.setAddtime(VeDate.getStringDateShort()); + int x = this.asksService.insertAsks(asks); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + // 通过主键删除数据 + @RequestMapping("deleteAsks.action") + public String deleteAsks(String id) { + this.asksService.deleteAsks(id); + return "redirect:/asks/getAllAsks.action"; + } + + // AJAX通过主键删除数据 + @RequestMapping("xdeleteAsks.action") + @ResponseBody //将java对象转为json格式的数据 + public String xdeleteAsks(String id) { + int x = this.asksService.deleteAsks(id); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 批量删除数据 + @RequestMapping("deleteAsksByIds.action") + public String deleteAsksByIds() { + String[] ids = this.getRequest().getParameterValues("asksid"); + if (ids != null) { + for (String asksid : ids) { + this.asksService.deleteAsks(asksid); + } + } + return "redirect:/asks/getAllAsks.action"; + } + + // 更新数据 + @RequestMapping("updateAsks.action") + public String updateAsks(Asks asks) { + this.asksService.updateAsks(asks); + return "redirect:/asks/getAllAsks.action"; + } + + // AJAX更新数据 + @RequestMapping("xupdateAsks.action") + @ResponseBody //将java对象转为json格式的数据 + public String xupdateAsks(Asks asks) { + int x = this.asksService.updateAsks(asks); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 显示全部数据 + @RequestMapping("getAllAsks.action") + public String getAllAsks(String number) { + List asksList = this.asksService.getAllAsks(); + PageHelper.getUserPage(asksList, "asks", "getAllAsks", 10, number, this.getRequest()); + return "admin/listasks"; + } + + // AJAX显示全部数据 + @RequestMapping(value = "getDataList.action", produces = "application/json; charset=utf-8") + @ResponseBody //将java对象转为json格式的数据 + public Map getDataList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) { + // 定义一个Map对象 用来返回数据 + Map map = new HashMap(); + Page pager = com.github.pagehelper.PageHelper.startPage(page, limit);// 定义当前页和分页条数 + List list = this.asksService.getAllAsks(); + // 返回的map中定义Layui的数据格式 + map.put("count", pager.getTotal()); + map.put("data", list); + map.put("code", 0); + map.put("msg", ""); + return map; + } + + // 按条件查询数据 (模糊查询) + @RequestMapping("queryAsksByCond.action") + public String queryAsksByCond(String cond, String name, String number) { + Asks asks = new Asks(); + if(cond != null){ + if ("question".equals(cond)) { + asks.setQuestion(name); + } + if ("addtime".equals(cond)) { + asks.setAddtime(name); + } + if ("memo".equals(cond)) { + asks.setMemo(name); + } + } + + List nameList = new ArrayList(); + List valueList = new ArrayList(); + nameList.add(cond); + valueList.add(name); + PageHelper.getPage(this.asksService.getAsksByLike(asks), "asks", nameList, valueList, 10, number, this.getRequest(), "query"); + name = null; + cond = null; + return "admin/queryasks"; + } + + // 按主键查询数据 + @RequestMapping("getAsksById.action") + public String getAsksById(String id) { + Asks asks = this.asksService.getAsksById(id); + this.getRequest().setAttribute("asks", asks); + return "admin/editasks"; + } + + +} diff --git a/src/com/controller/BannerController.java b/src/com/controller/BannerController.java new file mode 100644 index 0000000..b1e7782 --- /dev/null +++ b/src/com/controller/BannerController.java @@ -0,0 +1,159 @@ +package com.controller; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +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.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.Page; +import com.entity.Banner; +import com.service.BannerService; +import com.util.PageHelper; +import com.util.VeDate; +//定义为控制器 +@Controller +// 设置路径 +@RequestMapping(value = "/banner" , produces = "text/plain;charset=utf-8") +public class BannerController extends BaseController { + // @Autowired的作用是自动注入依赖的ServiceBean + @Autowired + private BannerService bannerService; + + // 准备添加数据 + @RequestMapping("createBanner.action") + public String createBanner() { + return "admin/addbanner"; + } + // 添加数据 + @RequestMapping("addBanner.action") + public String addBanner(Banner banner) { + banner.setAddtime(VeDate.getStringDateShort()); + this.bannerService.insertBanner(banner); + return "redirect:/banner/createBanner.action"; + } + + // AJAX添加数据 + @RequestMapping("xaddBanner.action") + @ResponseBody //将java对象转为json格式的数据 + public String xaddBanner(Banner banner) { + banner.setAddtime(VeDate.getStringDateShort()); + int x = this.bannerService.insertBanner(banner); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + // 通过主键删除数据 + @RequestMapping("deleteBanner.action") + public String deleteBanner(String id) { + this.bannerService.deleteBanner(id); + return "redirect:/banner/getAllBanner.action"; + } + + // AJAX通过主键删除数据 + @RequestMapping("xdeleteBanner.action") + @ResponseBody //将java对象转为json格式的数据 + public String xdeleteBanner(String id) { + int x = this.bannerService.deleteBanner(id); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 批量删除数据 + @RequestMapping("deleteBannerByIds.action") + public String deleteBannerByIds() { + String[] ids = this.getRequest().getParameterValues("bannerid"); + if (ids != null) { + for (String bannerid : ids) { + this.bannerService.deleteBanner(bannerid); + } + } + return "redirect:/banner/getAllBanner.action"; + } + + // 更新数据 + @RequestMapping("updateBanner.action") + public String updateBanner(Banner banner) { + this.bannerService.updateBanner(banner); + return "redirect:/banner/getAllBanner.action"; + } + + // AJAX更新数据 + @RequestMapping("xupdateBanner.action") + @ResponseBody //将java对象转为json格式的数据 + public String xupdateBanner(Banner banner) { + int x = this.bannerService.updateBanner(banner); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 显示全部数据 + @RequestMapping("getAllBanner.action") + public String getAllBanner(String number) { + List bannerList = this.bannerService.getAllBanner(); + PageHelper.getUserPage(bannerList, "banner", "getAllBanner", 10, number, this.getRequest()); + return "admin/listbanner"; + } + + // AJAX显示全部数据 + @RequestMapping(value = "getDataList.action", produces = "application/json; charset=utf-8") + @ResponseBody //将java对象转为json格式的数据 + public Map getDataList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) { + // 定义一个Map对象 用来返回数据 + Map map = new HashMap(); + Page pager = com.github.pagehelper.PageHelper.startPage(page, limit);// 定义当前页和分页条数 + List list = this.bannerService.getAllBanner(); + // 返回的map中定义Layui的数据格式 + map.put("count", pager.getTotal()); + map.put("data", list); + map.put("code", 0); + map.put("msg", ""); + return map; + } + + // 按条件查询数据 (模糊查询) + @RequestMapping("queryBannerByCond.action") + public String queryBannerByCond(String cond, String name, String number) { + Banner banner = new Banner(); + if(cond != null){ + if ("bannername".equals(cond)) { + banner.setBannername(name); + } + if ("addtime".equals(cond)) { + banner.setAddtime(name); + } + if ("memo".equals(cond)) { + banner.setMemo(name); + } + } + + List nameList = new ArrayList(); + List valueList = new ArrayList(); + nameList.add(cond); + valueList.add(name); + PageHelper.getPage(this.bannerService.getBannerByLike(banner), "banner", nameList, valueList, 10, number, this.getRequest(), "query"); + name = null; + cond = null; + return "admin/querybanner"; + } + + // 按主键查询数据 + @RequestMapping("getBannerById.action") + public String getBannerById(String id) { + Banner banner = this.bannerService.getBannerById(id); + this.getRequest().setAttribute("banner", banner); + return "admin/editbanner"; + } + + +} diff --git a/src/com/controller/BaseController.java b/src/com/controller/BaseController.java new file mode 100644 index 0000000..deaf708 --- /dev/null +++ b/src/com/controller/BaseController.java @@ -0,0 +1,45 @@ +package com.controller; + +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +/** + * Controller 基类 + * 其他Controller继承此类的同时也继承了此类里面的各个方法 + * 省掉了重新定义 实例化的麻烦 + */ +@Controller +public class BaseController { + + /* 日志 */ + 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; + } + +} diff --git a/src/com/controller/ComplainsController.java b/src/com/controller/ComplainsController.java new file mode 100644 index 0000000..c21cb63 --- /dev/null +++ b/src/com/controller/ComplainsController.java @@ -0,0 +1,134 @@ +package com.controller; + +import java.util.ArrayList; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import com.entity.Complains; +import com.service.ComplainsService; +import com.entity.Users; +import com.service.UsersService; +import com.util.PageHelper; + +//定义为控制器 +@Controller +// 设置路径 +@RequestMapping(value = "/complains", produces = "text/plain;charset=utf-8") +public class ComplainsController extends BaseController { + // @Autowired的作用是自动注入依赖的ServiceBean + @Autowired + private ComplainsService complainsService; + @Autowired + private UsersService usersService; + + // 准备添加数据 + @RequestMapping("createComplains.action") + public String createComplains() { + List usersList = this.usersService.getAllUsers(); + this.getRequest().setAttribute("usersList", usersList); + return "admin/addcomplains"; + } + + // 添加数据 + @RequestMapping("addComplains.action") + public String addComplains(Complains complains) { + this.complainsService.insertComplains(complains); + return "redirect:/complains/createComplains.action"; + } + + // 通过主键删除数据 + @RequestMapping("deleteComplains.action") + public String deleteComplains(String id) { + this.complainsService.deleteComplains(id); + return "redirect:/complains/getAllComplains.action"; + } + + // 批量删除数据 + @RequestMapping("deleteComplainsByIds.action") + public String deleteComplainsByIds() { + String[] ids = this.getRequest().getParameterValues("complainsid"); + if (ids != null) { + for (String complainsid : ids) { + this.complainsService.deleteComplains(complainsid); + } + } + return "redirect:/complains/getAllComplains.action"; + } + + // 更新数据 + @RequestMapping("updateComplains.action") + public String updateComplains(Complains complains) { + this.complainsService.updateComplains(complains); + return "redirect:/complains/getAllComplains.action"; + } + + // 更新状态 + @RequestMapping("status.action") + public String status(String id) { + String status = ""; + Complains complains = this.complainsService.getComplainsById(id); + if (status.equals(complains.getStatus())) { + status = ""; + } + complains.setStatus(status); + this.complainsService.updateComplains(complains); + return "redirect:/complains/getAllComplains.action"; + } + + // 显示全部数据 + @RequestMapping("getAllComplains.action") + public String getAllComplains(String number) { + List complainsList = this.complainsService.getAllComplains(); + PageHelper.getPage(complainsList, "complains", null, null, 10, number, this.getRequest(), null); + return "admin/listcomplains"; + } + + // 按条件查询数据 (模糊查询) + @RequestMapping("queryComplainsByCond.action") + public String queryComplainsByCond(String cond, String name, String number) { + Complains complains = new Complains(); + if (cond != null) { + if ("usersid".equals(cond)) { + complains.setUsersid(name); + } + if ("title".equals(cond)) { + complains.setTitle(name); + } + if ("contents".equals(cond)) { + complains.setContents(name); + } + if ("addtime".equals(cond)) { + complains.setAddtime(name); + } + if ("status".equals(cond)) { + complains.setStatus(name); + } + if ("reps".equals(cond)) { + complains.setReps(name); + } + } + + List nameList = new ArrayList(); + List valueList = new ArrayList(); + nameList.add(cond); + valueList.add(name); + PageHelper.getPage(this.complainsService.getComplainsByLike(complains), "complains", nameList, valueList, 10, number, this.getRequest(), + "query"); + name = null; + cond = null; + return "admin/querycomplains"; + } + + // 按主键查询数据 + @RequestMapping("getComplainsById.action") + public String getComplainsById(String id) { + Complains complains = this.complainsService.getComplainsById(id); + this.getRequest().setAttribute("complains", complains); + List usersList = this.usersService.getAllUsers(); + this.getRequest().setAttribute("usersList", usersList); + return "admin/editcomplains"; + } + +} diff --git a/src/com/controller/FavController.java b/src/com/controller/FavController.java new file mode 100644 index 0000000..28d6315 --- /dev/null +++ b/src/com/controller/FavController.java @@ -0,0 +1,175 @@ +package com.controller; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +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.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.Page; +import com.entity.Fav; +import com.service.FavService; +import com.entity.Users; +import com.entity.Article; +import com.service.UsersService; +import com.service.ArticleService; +import com.util.PageHelper; +import com.util.VeDate; +//定义为控制器 +@Controller +// 设置路径 +@RequestMapping(value = "/fav" , produces = "text/plain;charset=utf-8") +public class FavController extends BaseController { + // @Autowired的作用是自动注入依赖的ServiceBean + @Autowired + private FavService favService; + @Autowired + private UsersService usersService; + @Autowired + private ArticleService articleService; + + // 准备添加数据 + @RequestMapping("createFav.action") + public String createFav() { + List usersList = this.usersService.getAllUsers(); + this.getRequest().setAttribute("usersList", usersList); + List
articleList = this.articleService.getAllArticle(); + this.getRequest().setAttribute("articleList", articleList); + return "admin/addfav"; + } + // 添加数据 + @RequestMapping("addFav.action") + public String addFav(Fav fav) { + fav.setAddtime(VeDate.getStringDateShort()); + this.favService.insertFav(fav); + return "redirect:/fav/createFav.action"; + } + + // AJAX添加数据 + @RequestMapping("xaddFav.action") + @ResponseBody //将java对象转为json格式的数据 + public String xaddFav(Fav fav) { + fav.setAddtime(VeDate.getStringDateShort()); + int x = this.favService.insertFav(fav); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + // 通过主键删除数据 + @RequestMapping("deleteFav.action") + public String deleteFav(String id) { + this.favService.deleteFav(id); + return "redirect:/fav/getAllFav.action"; + } + + // AJAX通过主键删除数据 + @RequestMapping("xdeleteFav.action") + @ResponseBody //将java对象转为json格式的数据 + public String xdeleteFav(String id) { + int x = this.favService.deleteFav(id); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 批量删除数据 + @RequestMapping("deleteFavByIds.action") + public String deleteFavByIds() { + String[] ids = this.getRequest().getParameterValues("favid"); + if (ids != null) { + for (String favid : ids) { + this.favService.deleteFav(favid); + } + } + return "redirect:/fav/getAllFav.action"; + } + + // 更新数据 + @RequestMapping("updateFav.action") + public String updateFav(Fav fav) { + this.favService.updateFav(fav); + return "redirect:/fav/getAllFav.action"; + } + + // AJAX更新数据 + @RequestMapping("xupdateFav.action") + @ResponseBody //将java对象转为json格式的数据 + public String xupdateFav(Fav fav) { + int x = this.favService.updateFav(fav); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 显示全部数据 + @RequestMapping("getAllFav.action") + public String getAllFav(String number) { + List favList = this.favService.getAllFav(); + PageHelper.getUserPage(favList, "fav", "getAllFav", 10, number, this.getRequest()); + return "admin/listfav"; + } + + // AJAX显示全部数据 + @RequestMapping(value = "getDataList.action", produces = "application/json; charset=utf-8") + @ResponseBody //将java对象转为json格式的数据 + public Map getDataList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) { + // 定义一个Map对象 用来返回数据 + Map map = new HashMap(); + Page pager = com.github.pagehelper.PageHelper.startPage(page, limit);// 定义当前页和分页条数 + List list = this.favService.getAllFav(); + // 返回的map中定义Layui的数据格式 + map.put("count", pager.getTotal()); + map.put("data", list); + map.put("code", 0); + map.put("msg", ""); + return map; + } + + // 按条件查询数据 (模糊查询) + @RequestMapping("queryFavByCond.action") + public String queryFavByCond(String cond, String name, String number) { + Fav fav = new Fav(); + if(cond != null){ + if ("usersid".equals(cond)) { + fav.setUsersid(name); + } + if ("articleid".equals(cond)) { + fav.setArticleid(name); + } + if ("addtime".equals(cond)) { + fav.setAddtime(name); + } + } + + List nameList = new ArrayList(); + List valueList = new ArrayList(); + nameList.add(cond); + valueList.add(name); + PageHelper.getPage(this.favService.getFavByLike(fav), "fav", nameList, valueList, 10, number, this.getRequest(), "query"); + name = null; + cond = null; + return "admin/queryfav"; + } + + // 按主键查询数据 + @RequestMapping("getFavById.action") + public String getFavById(String id) { + Fav fav = this.favService.getFavById(id); + this.getRequest().setAttribute("fav", fav); + List usersList = this.usersService.getAllUsers(); + this.getRequest().setAttribute("usersList", usersList); + List
articleList = this.articleService.getAllArticle(); + this.getRequest().setAttribute("articleList", articleList); + return "admin/editfav"; + } + + +} diff --git a/src/com/controller/IndexController.java b/src/com/controller/IndexController.java new file mode 100644 index 0000000..cf12e1e --- /dev/null +++ b/src/com/controller/IndexController.java @@ -0,0 +1,397 @@ +package com.controller; + +import java.util.ArrayList; +import java.util.List; + +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.alibaba.fastjson.JSONObject; +import com.entity.Article; +import com.entity.Asks; +import com.entity.Banner; +import com.entity.Complains; +import com.entity.Fav; +import com.entity.Topic; +import com.entity.Users; +import com.service.ArticleService; +import com.service.AsksService; +import com.service.BannerService; +import com.service.ComplainsService; +import com.service.FavService; +import com.service.TopicService; +import com.service.UsersService; +import com.util.PageHelper; +import com.util.VeDate; + +//定义为控制器 +@Controller +// 设置路径 +@RequestMapping("/index") +public class IndexController extends BaseController { + + @Autowired + private UsersService usersService; + @Autowired + private BannerService bannerService; + @Autowired + private ArticleService articleService; + @Autowired + private FavService favService; + @Autowired + private TopicService topicService; + @Autowired + private ComplainsService complainsService; + @Autowired + private AsksService asksService; + + // TODO Auto-generated method stub + // 公共方法 提供公共查询数据 + private void front() { + this.getRequest().setAttribute("title", "新闻发布管理系统"); + List bannerList = this.bannerService.getAllBanner(); + this.getRequest().setAttribute("bannerList", bannerList); + } + + // 首页显示 + @RequestMapping("index.action") + public String index() { + this.front(); + List bannerList = this.bannerService.getAllBanner(); + List frontList = new ArrayList(); + for (Banner banner : bannerList) { + List
articleList = this.articleService.getArticleByBanner(banner.getBannerid()); + banner.setArticleList(articleList); + frontList.add(banner); + } + this.getRequest().setAttribute("frontList", frontList); + List
topList = this.articleService.getTopArticle(); + List
favList = this.articleService.getFlvArticle(); + this.getRequest().setAttribute("topList", topList); + this.getRequest().setAttribute("favList", favList); + return "users/index"; + } + + // 新闻公告 + @RequestMapping("article.action") + public String article(String id, String number) { + this.front(); + Article article = new Article(); + article.setBannerid(id); + List
articleList = this.articleService.getArticleByCond(article); + PageHelper.getIndexPage(articleList, "article", "article", id, 10, number, this.getRequest()); + Banner banner = this.bannerService.getBannerById(id); + this.getRequest().setAttribute("banner", banner); + return "users/article"; + } + + // 阅读公告 + @RequestMapping("read.action") + public String read(String id) { + this.front(); + Article article = this.articleService.getArticleById(id); + article.setHits("" + (Integer.parseInt(article.getHits()) + 1)); + this.articleService.updateArticle(article); + this.getRequest().setAttribute("article", article); + Topic topic = new Topic(); + topic.setArticleid(id); + List topicList = this.topicService.getTopicByCond(topic); + this.getRequest().setAttribute("topicList", topicList); + this.getRequest().setAttribute("tnum", topicList.size()); + return "users/read"; + } + + // 准备登录 + @RequestMapping("preLogin.action") + public String prelogin() { + this.front(); + return "users/login"; + } + + // 用户登录 + @RequestMapping("login.action") + public String login() { + this.front(); + String username = this.getRequest().getParameter("username"); + String password = this.getRequest().getParameter("password"); + Users u = new Users(); + u.setUsername(username); + List usersList = this.usersService.getUsersByCond(u); + if (usersList.size() == 0) { + this.getSession().setAttribute("message", "用户名不存在"); + return "redirect:/index/preLogin.action"; + } else { + Users users = usersList.get(0); + if (password.equals(users.getPassword())) { + this.getSession().setAttribute("userid", users.getUsersid()); + this.getSession().setAttribute("username", users.getUsername()); + this.getSession().setAttribute("users", users); + return "redirect:/index/index.action"; + } else { + this.getSession().setAttribute("message", "密码错误"); + return "redirect:/index/preLogin.action"; + } + } + } + + // 准备注册 + @RequestMapping("preReg.action") + public String preReg() { + this.front(); + List asksList = this.asksService.getAllAsks(); + this.getRequest().setAttribute("asksList", asksList); + return "users/register"; + } + + // 用户注册 + @RequestMapping("register.action") + public String register(Users users) { + this.front(); + Users u = new Users(); + u.setUsername(users.getUsername()); + List usersList = this.usersService.getUsersByCond(u); + if (usersList.size() == 0) { + users.setRegdate(VeDate.getStringDateShort()); + this.usersService.insertUsers(users); + } else { + this.getSession().setAttribute("message", "用户名已存在"); + return "redirect:/index/preReg.action"; + } + + return "redirect:/index/preLogin.action"; + } + + // 退出登录 + @RequestMapping("exit.action") + public String exit() { + this.front(); + this.getSession().removeAttribute("userid"); + this.getSession().removeAttribute("username"); + this.getSession().removeAttribute("users"); + return "redirect:/index/index.action"; + } + + // 准备修改密码 + @RequestMapping("prePwd.action") + public String prePwd() { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + return "users/editpwd"; + } + + // 修改密码 + @RequestMapping("editpwd.action") + public String editpwd() { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + String userid = (String) this.getSession().getAttribute("userid"); + String password = this.getRequest().getParameter("password"); + String repassword = this.getRequest().getParameter("repassword"); + Users users = this.usersService.getUsersById(userid); + if (password.equals(users.getPassword())) { + users.setPassword(repassword); + this.usersService.updateUsers(users); + } else { + this.getSession().setAttribute("message", "旧密码错误"); + return "redirect:/index/prePwd.action"; + } + this.getSession().setAttribute("message", "修改成功"); + return "redirect:/index/prePwd.action"; + } + + @RequestMapping("forget.action") + public String forget() { + this.front(); + return "users/forget"; + } + + @RequestMapping("step1.action") + public String step1() { + this.front(); + String username = this.getRequest().getParameter("username"); + Users u = new Users(); + u.setUsername(username); + List usersList = this.usersService.getUsersByCond(u); + if (usersList.size() == 0) { + this.getSession().setAttribute("message", "用户名不存在"); + return "redirect:/index/preLogin.action"; + } else { + Users x = usersList.get(0); + String questions = x.getAsks().getQuestion(); + this.getRequest().setAttribute("questions", questions); + this.getRequest().setAttribute("username", username); + this.getRequest().setAttribute("userid", x.getUsersid()); + } + return "users/step1"; + } + + @RequestMapping("step2.action") + public String step2() { + this.front(); + String userid = this.getRequest().getParameter("userid"); + String answer = this.getRequest().getParameter("answer"); + Users u = this.usersService.getUsersById(userid); + if (u.getAnswer().equals(answer)) { + this.getRequest().setAttribute("userid", userid); + this.getRequest().setAttribute("username", u.getUsername()); + } else { + this.getSession().setAttribute("message", "答案错误"); + return "redirect:/index/preLogin.action"; + } + return "users/step2"; + } + + @RequestMapping("updatePwd.action") + public String updatePwd() { + this.front(); + String userid = this.getRequest().getParameter("userid"); + String password = this.getRequest().getParameter("repassword"); + Users u = this.usersService.getUsersById(userid); + u.setPassword(password); + this.usersService.updateUsers(u); + this.getSession().setAttribute("message", "密码已重置"); + return "redirect:/index/preLogin.action"; + } + + @RequestMapping("usercenter.action") + public String usercenter() { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + return "users/usercenter"; + } + + @RequestMapping("userinfo.action") + public String userinfo() { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + String userid = (String) this.getSession().getAttribute("userid"); + this.getSession().setAttribute("users", this.usersService.getUsersById(userid)); + return "users/userinfo"; + } + + @RequestMapping("personal.action") + public String personal(Users users) { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + this.usersService.updateUsers(users); + this.getSession().setAttribute("message", "修改成功"); + return "redirect:/index/userinfo.action"; + } + + @RequestMapping("preComplains.action") + public String preComplains() { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + return "users/addComplains"; + } + + @RequestMapping("addComplains.action") + public String addComplains(Complains complains) { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + String userid = (String) this.getSession().getAttribute("userid"); + complains.setAddtime(VeDate.getStringDateShort()); + complains.setStatus("未回复"); + complains.setUsersid(userid); + this.complainsService.insertComplains(complains); + return "redirect:/index/preComplains.action"; + } + + @RequestMapping("myComplains.action") + public String myComplains(String number) { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + String userid = (String) this.getSession().getAttribute("userid"); + Complains complains = new Complains(); + complains.setUsersid(userid); + List complainsList = this.complainsService.getComplainsByCond(complains); + PageHelper.getIndexPage(complainsList, "complains", "myComplains", null, 10, number, this.getRequest()); + return "users/myComplains"; + } + + @RequestMapping("addTopic.action") + public String addTopic(Topic topic) { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + String userid = (String) this.getSession().getAttribute("userid"); + topic.setAddtime(VeDate.getStringDateShort()); + topic.setUsersid(userid); + this.topicService.insertTopic(topic); + return "redirect:/index/read.action?id=" + topic.getArticleid(); + } + + @RequestMapping(value = "addfav.action", produces = "text/plain;charset=utf-8") + @ResponseBody + public String addfav(String id) { + this.front(); + JSONObject json = new JSONObject(); + if (this.getSession().getAttribute("userid") == null) { + json.put("status", "login"); + json.put("message", "请登录"); + System.out.println(json.toString()); + return json.toString(); + } + String userid = (String) this.getSession().getAttribute("userid"); + Fav fav = new Fav(); + fav.setArticleid(id); + fav.setUsersid(userid); + List favList = this.favService.getFavByCond(fav); + if (favList.size() == 0) { + fav.setAddtime(VeDate.getStringDateShort()); + this.favService.insertFav(fav); + json.put("status", "success"); + json.put("message", "收藏成功"); + } else { + json.put("status", "fail"); + json.put("message", "收藏失败"); + } + System.out.println(json.toString()); + return json.toString(); + } + + @RequestMapping("myFav.action") + public String myFav(String number) { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + String userid = (String) this.getSession().getAttribute("userid"); + Fav fav = new Fav(); + fav.setUsersid(userid); + List favList = this.favService.getFavByCond(fav); + PageHelper.getIndexPage(favList, "fav", "myFav", null, 10, number, this.getRequest()); + return "users/myFav"; + } + + @RequestMapping("deleteFav.action") + public String deleteFav(String id) { + this.front(); + if (this.getSession().getAttribute("userid") == null) { + return "redirect:/index/preLogin.action"; + } + this.favService.deleteFav(id); + return "redirect:/index/myFav.action"; + } + + // TODO Auto-generated method stub +} diff --git a/src/com/controller/TopicController.java b/src/com/controller/TopicController.java new file mode 100644 index 0000000..b58a2e7 --- /dev/null +++ b/src/com/controller/TopicController.java @@ -0,0 +1,178 @@ +package com.controller; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +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.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.Page; +import com.entity.Topic; +import com.service.TopicService; +import com.entity.Users; +import com.entity.Article; +import com.service.UsersService; +import com.service.ArticleService; +import com.util.PageHelper; +import com.util.VeDate; +//定义为控制器 +@Controller +// 设置路径 +@RequestMapping(value = "/topic" , produces = "text/plain;charset=utf-8") +public class TopicController extends BaseController { + // @Autowired的作用是自动注入依赖的ServiceBean + @Autowired + private TopicService topicService; + @Autowired + private UsersService usersService; + @Autowired + private ArticleService articleService; + + // 准备添加数据 + @RequestMapping("createTopic.action") + public String createTopic() { + List usersList = this.usersService.getAllUsers(); + this.getRequest().setAttribute("usersList", usersList); + List
articleList = this.articleService.getAllArticle(); + this.getRequest().setAttribute("articleList", articleList); + return "admin/addtopic"; + } + // 添加数据 + @RequestMapping("addTopic.action") + public String addTopic(Topic topic) { + topic.setAddtime(VeDate.getStringDateShort()); + this.topicService.insertTopic(topic); + return "redirect:/topic/createTopic.action"; + } + + // AJAX添加数据 + @RequestMapping("xaddTopic.action") + @ResponseBody //将java对象转为json格式的数据 + public String xaddTopic(Topic topic) { + topic.setAddtime(VeDate.getStringDateShort()); + int x = this.topicService.insertTopic(topic); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + // 通过主键删除数据 + @RequestMapping("deleteTopic.action") + public String deleteTopic(String id) { + this.topicService.deleteTopic(id); + return "redirect:/topic/getAllTopic.action"; + } + + // AJAX通过主键删除数据 + @RequestMapping("xdeleteTopic.action") + @ResponseBody //将java对象转为json格式的数据 + public String xdeleteTopic(String id) { + int x = this.topicService.deleteTopic(id); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 批量删除数据 + @RequestMapping("deleteTopicByIds.action") + public String deleteTopicByIds() { + String[] ids = this.getRequest().getParameterValues("topicid"); + if (ids != null) { + for (String topicid : ids) { + this.topicService.deleteTopic(topicid); + } + } + return "redirect:/topic/getAllTopic.action"; + } + + // 更新数据 + @RequestMapping("updateTopic.action") + public String updateTopic(Topic topic) { + this.topicService.updateTopic(topic); + return "redirect:/topic/getAllTopic.action"; + } + + // AJAX更新数据 + @RequestMapping("xupdateTopic.action") + @ResponseBody //将java对象转为json格式的数据 + public String xupdateTopic(Topic topic) { + int x = this.topicService.updateTopic(topic); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 显示全部数据 + @RequestMapping("getAllTopic.action") + public String getAllTopic(String number) { + List topicList = this.topicService.getAllTopic(); + PageHelper.getUserPage(topicList, "topic", "getAllTopic", 10, number, this.getRequest()); + return "admin/listtopic"; + } + + // AJAX显示全部数据 + @RequestMapping(value = "getDataList.action", produces = "application/json; charset=utf-8") + @ResponseBody //将java对象转为json格式的数据 + public Map getDataList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) { + // 定义一个Map对象 用来返回数据 + Map map = new HashMap(); + Page pager = com.github.pagehelper.PageHelper.startPage(page, limit);// 定义当前页和分页条数 + List list = this.topicService.getAllTopic(); + // 返回的map中定义Layui的数据格式 + map.put("count", pager.getTotal()); + map.put("data", list); + map.put("code", 0); + map.put("msg", ""); + return map; + } + + // 按条件查询数据 (模糊查询) + @RequestMapping("queryTopicByCond.action") + public String queryTopicByCond(String cond, String name, String number) { + Topic topic = new Topic(); + if(cond != null){ + if ("usersid".equals(cond)) { + topic.setUsersid(name); + } + if ("articleid".equals(cond)) { + topic.setArticleid(name); + } + if ("contents".equals(cond)) { + topic.setContents(name); + } + if ("addtime".equals(cond)) { + topic.setAddtime(name); + } + } + + List nameList = new ArrayList(); + List valueList = new ArrayList(); + nameList.add(cond); + valueList.add(name); + PageHelper.getPage(this.topicService.getTopicByLike(topic), "topic", nameList, valueList, 10, number, this.getRequest(), "query"); + name = null; + cond = null; + return "admin/querytopic"; + } + + // 按主键查询数据 + @RequestMapping("getTopicById.action") + public String getTopicById(String id) { + Topic topic = this.topicService.getTopicById(id); + this.getRequest().setAttribute("topic", topic); + List usersList = this.usersService.getAllUsers(); + this.getRequest().setAttribute("usersList", usersList); + List
articleList = this.articleService.getAllArticle(); + this.getRequest().setAttribute("articleList", articleList); + return "admin/edittopic"; + } + + +} diff --git a/src/com/controller/UploadController.java b/src/com/controller/UploadController.java new file mode 100644 index 0000000..a1e6c39 --- /dev/null +++ b/src/com/controller/UploadController.java @@ -0,0 +1,78 @@ +package com.controller; + +import java.io.File; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; + +import com.util.VeDate; + +@Controller +@RequestMapping("/upload") +public class UploadController extends BaseController { + + @RequestMapping("preUpload.action") + public String preUpload() { + return "page/saveimage"; + } + + @RequestMapping(value = "/image.action") + public String upload(@RequestParam(value = "image", required = false) MultipartFile file, + HttpServletRequest request, ModelMap model) { + String path = request.getSession().getServletContext().getRealPath("/") + "upfiles/"; + String fileName = file.getOriginalFilename(); + int i = fileName.lastIndexOf("."); + String name = String.valueOf(VeDate.getStringDatex()); + String type = fileName.substring(i + 1); + fileName = name + "." + type; + File targetFile = new File(path, fileName); + if (!targetFile.exists()) { + targetFile.mkdirs(); + } + + // 保存 + try { + file.transferTo(targetFile); + } catch (Exception e) { + e.printStackTrace(); + } + model.addAttribute("imageFileName", fileName); + return "page/saveimage"; + } + + @RequestMapping("preFile.action") + public String preFile() { + return "page/savefile"; + } + + @RequestMapping(value = "/files.action") + public String files(@RequestParam(value = "image", required = false) MultipartFile file, HttpServletRequest request, + ModelMap model) { + String path = request.getSession().getServletContext().getRealPath("/") + "upfiles/"; + String fileName = file.getOriginalFilename(); + int i = fileName.lastIndexOf("."); + String name = String.valueOf(VeDate.getStringDatex()); + String type = fileName.substring(i + 1); + fileName = name + "." + type; + File targetFile = new File(path, fileName); + if (!targetFile.exists()) { + targetFile.mkdirs(); + } + + // 保存 + try { + file.transferTo(targetFile); + } catch (Exception e) { + e.printStackTrace(); + } + model.addAttribute("imageFileName", fileName); + return "page/savefile"; + } +} + + diff --git a/src/com/controller/UsersController.java b/src/com/controller/UsersController.java new file mode 100644 index 0000000..0cce10a --- /dev/null +++ b/src/com/controller/UsersController.java @@ -0,0 +1,171 @@ +package com.controller; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +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.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.Page; +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 UsersController extends BaseController { + // @Autowired的作用是自动注入依赖的ServiceBean + @Autowired + 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"; + } + + // AJAX添加数据 + @RequestMapping("xaddUsers.action") + @ResponseBody //将java对象转为json格式的数据 + public String xaddUsers(Users users) { + users.setRegdate(VeDate.getStringDateShort()); + int x = this.usersService.insertUsers(users); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + // 通过主键删除数据 + @RequestMapping("deleteUsers.action") + public String deleteUsers(String id) { + this.usersService.deleteUsers(id); + return "redirect:/users/getAllUsers.action"; + } + + // AJAX通过主键删除数据 + @RequestMapping("xdeleteUsers.action") + @ResponseBody //将java对象转为json格式的数据 + public String xdeleteUsers(String id) { + int x = this.usersService.deleteUsers(id); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 批量删除数据 + @RequestMapping("deleteUsersByIds.action") + public String deleteUsersByIds() { + String[] ids = this.getRequest().getParameterValues("usersid"); + if (ids != null) { + 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"; + } + + // AJAX更新数据 + @RequestMapping("xupdateUsers.action") + @ResponseBody //将java对象转为json格式的数据 + public String xupdateUsers(Users users) { + int x = this.usersService.updateUsers(users); + JSONObject json = new JSONObject(); + json.put("result", x); + //System.out.println(json.toString()); + return json.toString(); + } + + // 显示全部数据 + @RequestMapping("getAllUsers.action") + public String getAllUsers(String number) { + List usersList = this.usersService.getAllUsers(); + PageHelper.getUserPage(usersList, "users", "getAllUsers", 10, number, this.getRequest()); + return "admin/listusers"; + } + + // AJAX显示全部数据 + @RequestMapping(value = "getDataList.action", produces = "application/json; charset=utf-8") + @ResponseBody //将java对象转为json格式的数据 + public Map getDataList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) { + // 定义一个Map对象 用来返回数据 + Map map = new HashMap(); + Page pager = com.github.pagehelper.PageHelper.startPage(page, limit);// 定义当前页和分页条数 + List list = this.usersService.getAllUsers(); + // 返回的map中定义Layui的数据格式 + map.put("count", pager.getTotal()); + map.put("data", list); + map.put("code", 0); + map.put("msg", ""); + return map; + } + + // 按条件查询数据 (模糊查询) + @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 nameList = new ArrayList(); + List valueList = new ArrayList(); + 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"; + } + + +} diff --git a/src/com/dao/AdminDAO.java b/src/com/dao/AdminDAO.java new file mode 100644 index 0000000..1130a4e --- /dev/null +++ b/src/com/dao/AdminDAO.java @@ -0,0 +1,41 @@ +package com.dao; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; +import com.entity.Admin; + +@Repository("adminDAO") // Repository标签定义数据库连接的访问 Spring中直接扫描加载 +@Mapper // 不需要在spring配置中设置扫描地址 spring将动态的生成Bean后注入到AdminServiceImpl中 +public interface AdminDAO { + + /** + * AdminDAO 接口 可以按名称直接调用admin.xml配置文件的SQL语句 + */ + + // 插入管理员表数据 调用mapper包admin.xml里的insertAdmin配置 返回值0(失败),1(成功) + public int insertAdmin(Admin admin); + + // 更新管理员表数据 调用mapper包admin.xml里的updateAdmin配置 返回值0(失败),1(成功) + public int updateAdmin(Admin admin); + + // 按主键删除管理员表数据 调用mapper包admin.xml里的deleteAdmin配置 返回值0(失败),1(成功) + public int deleteAdmin(String adminid); + + // 批量删除管理员表数据 调用mapper包admin.xml里的deleteAdminByIds配置 返回值0(失败),大于0(成功) + public int deleteAdminByIds(String[] ids); + + // 查询管理员表全部数据 调用mapper包admin.xml里的getAllAdmin配置 返回List类型的数据 + public List getAllAdmin(); + + // 按照Admin类里面的值精确查询 调用mapper包admin.xml里的getAdminByCond配置 返回List类型的数据 + public List getAdminByCond(Admin admin); + + // 按照Admin类里面的值模糊查询 调用mapper包admin.xml里的getAdminByLike配置 返回List类型的数据 + public List getAdminByLike(Admin admin); + + // 按主键查询管理员表返回单一的Admin实例 调用mapper包admin.xml里的getAdminById配置 + public Admin getAdminById(String adminid); + +} + + diff --git a/src/com/dao/ArticleDAO.java b/src/com/dao/ArticleDAO.java new file mode 100644 index 0000000..06aaaf8 --- /dev/null +++ b/src/com/dao/ArticleDAO.java @@ -0,0 +1,43 @@ +package com.dao; + +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; +import com.entity.Article; + +@Repository("articleDAO") // Repository标签定义数据库连接的访问 Spring中直接 +@Mapper +public interface ArticleDAO { + + /** + * ArticleDAO 接口 可以按名称直接调用article.xml配置文件的SQL语句 + */ + + // 插入数据 调用entity包article.xml里的insertArticle配置 返回值0(失败),1(成功) + public int insertArticle(Article article); + + // 更新数据 调用entity包article.xml里的updateArticle配置 返回值0(失败),1(成功) + public int updateArticle(Article article); + + // 删除数据 调用entity包article.xml里的deleteArticle配置 返回值0(失败),1(成功) + public int deleteArticle(String articleid); + + // 查询全部数据 调用entity包article.xml里的getAllArticle配置 返回List类型的数据 + public List
getAllArticle(); + + public List
getFlvArticle(); + + public List
getTopArticle(); + + public List
getArticleByBanner(String bannerid); + + // 按照Article类里面的值精确查询 调用entity包article.xml里的getArticleByCond配置 返回List类型的数据 + public List
getArticleByCond(Article article); + + // 按照Article类里面的值模糊查询 调用entity包article.xml里的getArticleByLike配置 返回List类型的数据 + public List
getArticleByLike(Article article); + + // 按主键查询表返回单一的Article实例 调用entity包article.xml里的getArticleById配置 + public Article getArticleById(String articleid); + +} diff --git a/src/com/dao/AsksDAO.java b/src/com/dao/AsksDAO.java new file mode 100644 index 0000000..b2c16ce --- /dev/null +++ b/src/com/dao/AsksDAO.java @@ -0,0 +1,41 @@ +package com.dao; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; +import com.entity.Asks; + +@Repository("asksDAO") // Repository标签定义数据库连接的访问 Spring中直接扫描加载 +@Mapper // 不需要在spring配置中设置扫描地址 spring将动态的生成Bean后注入到AsksServiceImpl中 +public interface AsksDAO { + + /** + * AsksDAO 接口 可以按名称直接调用asks.xml配置文件的SQL语句 + */ + + // 插入提示问题表数据 调用mapper包asks.xml里的insertAsks配置 返回值0(失败),1(成功) + public int insertAsks(Asks asks); + + // 更新提示问题表数据 调用mapper包asks.xml里的updateAsks配置 返回值0(失败),1(成功) + public int updateAsks(Asks asks); + + // 按主键删除提示问题表数据 调用mapper包asks.xml里的deleteAsks配置 返回值0(失败),1(成功) + public int deleteAsks(String asksid); + + // 批量删除提示问题表数据 调用mapper包asks.xml里的deleteAsksByIds配置 返回值0(失败),大于0(成功) + public int deleteAsksByIds(String[] ids); + + // 查询提示问题表全部数据 调用mapper包asks.xml里的getAllAsks配置 返回List类型的数据 + public List getAllAsks(); + + // 按照Asks类里面的值精确查询 调用mapper包asks.xml里的getAsksByCond配置 返回List类型的数据 + public List getAsksByCond(Asks asks); + + // 按照Asks类里面的值模糊查询 调用mapper包asks.xml里的getAsksByLike配置 返回List类型的数据 + public List getAsksByLike(Asks asks); + + // 按主键查询提示问题表返回单一的Asks实例 调用mapper包asks.xml里的getAsksById配置 + public Asks getAsksById(String asksid); + +} + + diff --git a/src/com/dao/BannerDAO.java b/src/com/dao/BannerDAO.java new file mode 100644 index 0000000..7e97f85 --- /dev/null +++ b/src/com/dao/BannerDAO.java @@ -0,0 +1,38 @@ +package com.dao; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; +import com.entity.Banner; + +@Repository("bannerDAO") // Repository标签定义数据库连接的访问 Spring中直接 +@Mapper +public interface BannerDAO { + + /** +* BannerDAO 接口 可以按名称直接调用banner.xml配置文件的SQL语句 + */ + + // 插入数据 调用entity包banner.xml里的insertBanner配置 返回值0(失败),1(成功) + public int insertBanner(Banner banner); + + // 更新数据 调用entity包banner.xml里的updateBanner配置 返回值0(失败),1(成功) + public int updateBanner(Banner banner); + + // 删除数据 调用entity包banner.xml里的deleteBanner配置 返回值0(失败),1(成功) + public int deleteBanner(String bannerid); + + // 查询全部数据 调用entity包banner.xml里的getAllBanner配置 返回List类型的数据 + public List getAllBanner(); + + // 按照Banner类里面的值精确查询 调用entity包banner.xml里的getBannerByCond配置 返回List类型的数据 + public List getBannerByCond(Banner banner); + + // 按照Banner类里面的值模糊查询 调用entity包banner.xml里的getBannerByLike配置 返回List类型的数据 + public List getBannerByLike(Banner banner); + + // 按主键查询表返回单一的Banner实例 调用entity包banner.xml里的getBannerById配置 + public Banner getBannerById(String bannerid); + +} + + diff --git a/src/com/dao/ComplainsDAO.java b/src/com/dao/ComplainsDAO.java new file mode 100644 index 0000000..a70e0fd --- /dev/null +++ b/src/com/dao/ComplainsDAO.java @@ -0,0 +1,41 @@ +package com.dao; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; +import com.entity.Complains; + +@Repository("complainsDAO") // Repository标签定义数据库连接的访问 Spring中直接扫描加载 +@Mapper // 不需要在spring配置中设置扫描地址 spring将动态的生成Bean后注入到ComplainsServiceImpl中 +public interface ComplainsDAO { + + /** + * ComplainsDAO 接口 可以按名称直接调用complains.xml配置文件的SQL语句 + */ + + // 插入意见反馈表数据 调用mapper包complains.xml里的insertComplains配置 返回值0(失败),1(成功) + public int insertComplains(Complains complains); + + // 更新意见反馈表数据 调用mapper包complains.xml里的updateComplains配置 返回值0(失败),1(成功) + public int updateComplains(Complains complains); + + // 按主键删除意见反馈表数据 调用mapper包complains.xml里的deleteComplains配置 返回值0(失败),1(成功) + public int deleteComplains(String complainsid); + + // 批量删除意见反馈表数据 调用mapper包complains.xml里的deleteComplainsByIds配置 返回值0(失败),大于0(成功) + public int deleteComplainsByIds(String[] ids); + + // 查询意见反馈表全部数据 调用mapper包complains.xml里的getAllComplains配置 返回List类型的数据 + public List getAllComplains(); + + // 按照Complains类里面的值精确查询 调用mapper包complains.xml里的getComplainsByCond配置 返回List类型的数据 + public List getComplainsByCond(Complains complains); + + // 按照Complains类里面的值模糊查询 调用mapper包complains.xml里的getComplainsByLike配置 返回List类型的数据 + public List getComplainsByLike(Complains complains); + + // 按主键查询意见反馈表返回单一的Complains实例 调用mapper包complains.xml里的getComplainsById配置 + public Complains getComplainsById(String complainsid); + +} + + diff --git a/src/com/dao/FavDAO.java b/src/com/dao/FavDAO.java new file mode 100644 index 0000000..caa193b --- /dev/null +++ b/src/com/dao/FavDAO.java @@ -0,0 +1,41 @@ +package com.dao; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; +import com.entity.Fav; + +@Repository("favDAO") // Repository标签定义数据库连接的访问 Spring中直接扫描加载 +@Mapper // 不需要在spring配置中设置扫描地址 spring将动态的生成Bean后注入到FavServiceImpl中 +public interface FavDAO { + + /** + * FavDAO 接口 可以按名称直接调用fav.xml配置文件的SQL语句 + */ + + // 插入用户收藏表数据 调用mapper包fav.xml里的insertFav配置 返回值0(失败),1(成功) + public int insertFav(Fav fav); + + // 更新用户收藏表数据 调用mapper包fav.xml里的updateFav配置 返回值0(失败),1(成功) + public int updateFav(Fav fav); + + // 按主键删除用户收藏表数据 调用mapper包fav.xml里的deleteFav配置 返回值0(失败),1(成功) + public int deleteFav(String favid); + + // 批量删除用户收藏表数据 调用mapper包fav.xml里的deleteFavByIds配置 返回值0(失败),大于0(成功) + public int deleteFavByIds(String[] ids); + + // 查询用户收藏表全部数据 调用mapper包fav.xml里的getAllFav配置 返回List类型的数据 + public List getAllFav(); + + // 按照Fav类里面的值精确查询 调用mapper包fav.xml里的getFavByCond配置 返回List类型的数据 + public List getFavByCond(Fav fav); + + // 按照Fav类里面的值模糊查询 调用mapper包fav.xml里的getFavByLike配置 返回List类型的数据 + public List getFavByLike(Fav fav); + + // 按主键查询用户收藏表返回单一的Fav实例 调用mapper包fav.xml里的getFavById配置 + public Fav getFavById(String favid); + +} + + diff --git a/src/com/dao/TopicDAO.java b/src/com/dao/TopicDAO.java new file mode 100644 index 0000000..46cd57e --- /dev/null +++ b/src/com/dao/TopicDAO.java @@ -0,0 +1,41 @@ +package com.dao; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; +import com.entity.Topic; + +@Repository("topicDAO") // Repository标签定义数据库连接的访问 Spring中直接扫描加载 +@Mapper // 不需要在spring配置中设置扫描地址 spring将动态的生成Bean后注入到TopicServiceImpl中 +public interface TopicDAO { + + /** + * TopicDAO 接口 可以按名称直接调用topic.xml配置文件的SQL语句 + */ + + // 插入用户评论表数据 调用mapper包topic.xml里的insertTopic配置 返回值0(失败),1(成功) + public int insertTopic(Topic topic); + + // 更新用户评论表数据 调用mapper包topic.xml里的updateTopic配置 返回值0(失败),1(成功) + public int updateTopic(Topic topic); + + // 按主键删除用户评论表数据 调用mapper包topic.xml里的deleteTopic配置 返回值0(失败),1(成功) + public int deleteTopic(String topicid); + + // 批量删除用户评论表数据 调用mapper包topic.xml里的deleteTopicByIds配置 返回值0(失败),大于0(成功) + public int deleteTopicByIds(String[] ids); + + // 查询用户评论表全部数据 调用mapper包topic.xml里的getAllTopic配置 返回List类型的数据 + public List getAllTopic(); + + // 按照Topic类里面的值精确查询 调用mapper包topic.xml里的getTopicByCond配置 返回List类型的数据 + public List getTopicByCond(Topic topic); + + // 按照Topic类里面的值模糊查询 调用mapper包topic.xml里的getTopicByLike配置 返回List类型的数据 + public List getTopicByLike(Topic topic); + + // 按主键查询用户评论表返回单一的Topic实例 调用mapper包topic.xml里的getTopicById配置 + public Topic getTopicById(String topicid); + +} + + diff --git a/src/com/dao/UsersDAO.java b/src/com/dao/UsersDAO.java new file mode 100644 index 0000000..a877633 --- /dev/null +++ b/src/com/dao/UsersDAO.java @@ -0,0 +1,41 @@ +package com.dao; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; +import com.entity.Users; + +@Repository("usersDAO") // Repository标签定义数据库连接的访问 Spring中直接扫描加载 +@Mapper // 不需要在spring配置中设置扫描地址 spring将动态的生成Bean后注入到UsersServiceImpl中 +public interface UsersDAO { + + /** + * UsersDAO 接口 可以按名称直接调用users.xml配置文件的SQL语句 + */ + + // 插入网站用户表数据 调用mapper包users.xml里的insertUsers配置 返回值0(失败),1(成功) + public int insertUsers(Users users); + + // 更新网站用户表数据 调用mapper包users.xml里的updateUsers配置 返回值0(失败),1(成功) + public int updateUsers(Users users); + + // 按主键删除网站用户表数据 调用mapper包users.xml里的deleteUsers配置 返回值0(失败),1(成功) + public int deleteUsers(String usersid); + + // 批量删除网站用户表数据 调用mapper包users.xml里的deleteUsersByIds配置 返回值0(失败),大于0(成功) + public int deleteUsersByIds(String[] ids); + + // 查询网站用户表全部数据 调用mapper包users.xml里的getAllUsers配置 返回List类型的数据 + public List getAllUsers(); + + // 按照Users类里面的值精确查询 调用mapper包users.xml里的getUsersByCond配置 返回List类型的数据 + public List getUsersByCond(Users users); + + // 按照Users类里面的值模糊查询 调用mapper包users.xml里的getUsersByLike配置 返回List类型的数据 + public List getUsersByLike(Users users); + + // 按主键查询网站用户表返回单一的Users实例 调用mapper包users.xml里的getUsersById配置 + public Users getUsersById(String usersid); + +} + + diff --git a/src/com/entity/Admin.java b/src/com/entity/Admin.java new file mode 100644 index 0000000..6a61d0a --- /dev/null +++ b/src/com/entity/Admin.java @@ -0,0 +1,89 @@ +package com.entity; + +import com.util.VeDate; +import com.alibaba.fastjson.JSONObject; + +// 管理员表的实体类 +public class Admin { + private String adminid = "A"+VeDate.getStringId(); // 生成主键编号 + private String username; // 用户名 + private String password; // 密码 + private String realname; // 姓名 + private String contact; // 联系方式 + private String addtime; // 创建日期 + + public String getAdminid() { + return this.adminid; + } + + public void setAdminid(String adminid) { + this.adminid = adminid; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRealname() { + return this.realname; + } + + public void setRealname(String realname) { + this.realname = realname; + } + + public String getContact() { + return this.contact; + } + + public void setContact(String contact) { + this.contact = contact; + } + + public String getAddtime() { + return this.addtime; + } + + public void setAddtime(String addtime) { + this.addtime = addtime; + } + + + // 重载方法 生成JSON类型字符串 + @Override + public String toString() { + return this.toJsonString(); + } + + //直接转换成JSON字符串 + private String toJsonString() { + JSONObject jsonString = new JSONObject(); + jsonString.put("adminid", this.adminid); // 主键编号 + jsonString.put("username", this.username); // 用户名 + jsonString.put("password", this.password); // 密码 + jsonString.put("realname", this.realname); // 姓名 + jsonString.put("contact", this.contact); // 联系方式 + jsonString.put("addtime", this.addtime); // 创建日期 + return jsonString.toString(); + } + + + + +} + + + + diff --git a/src/com/entity/Article.java b/src/com/entity/Article.java new file mode 100644 index 0000000..e49d4a7 --- /dev/null +++ b/src/com/entity/Article.java @@ -0,0 +1,105 @@ +package com.entity; + +import com.util.VeDate; + +public class Article { + private String articleid = "A" + VeDate.getStringId();// 生成主键编号 + private String title;// 标题 + private String bannerid;// 分类 + private String image;// 图片 + private String istop;// 是否置顶 + private String isflv;// 是否轮播 + private String contents;// 内容 + private String addtime;// 发布日期 + private String hits;// 点击数 + private String bannername;// 映射数据 + + public String getArticleid() { + return articleid; + } + + public void setArticleid(String articleid) { + this.articleid = articleid; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getBannerid() { + return this.bannerid; + } + + public void setBannerid(String bannerid) { + this.bannerid = bannerid; + } + + public String getImage() { + return this.image; + } + + public void setImage(String image) { + this.image = image; + } + + public String getIstop() { + return this.istop; + } + + public void setIstop(String istop) { + this.istop = istop; + } + + public String getIsflv() { + return this.isflv; + } + + public void setIsflv(String isflv) { + this.isflv = isflv; + } + + public String getContents() { + return this.contents; + } + + public void setContents(String contents) { + this.contents = contents; + } + + public String getAddtime() { + return this.addtime; + } + + public void setAddtime(String addtime) { + this.addtime = addtime; + } + + public String getHits() { + return this.hits; + } + + public void setHits(String hits) { + this.hits = hits; + } + + public String getBannername() { + return this.bannername; + } + + public void setBannername(String bannername) { + this.bannername = bannername; + } + + // 重载方法 生成JSON类型字符串 + @Override + public String toString() { + return "Article [articleid=" + this.articleid + ", title=" + this.title + ", bannerid=" + this.bannerid + ", image=" + this.image + + ", istop=" + this.istop + ", isflv=" + this.isflv + ", contents=" + this.contents + ", addtime=" + this.addtime + ", hits=" + + this.hits + ", bannername=" + this.bannername + "]"; + } + +} diff --git a/src/com/entity/Asks.java b/src/com/entity/Asks.java new file mode 100644 index 0000000..dc10110 --- /dev/null +++ b/src/com/entity/Asks.java @@ -0,0 +1,68 @@ +package com.entity; + +import com.util.VeDate; +import com.alibaba.fastjson.JSONObject; + +// 提示问题表的实体类 +public class Asks { + private String asksid = "A"+VeDate.getStringId(); // 生成主键编号 + private String question; // 问题 + private String addtime; // 创建日期 + private String memo; // 备注 + public String getAsksid() { + return this.asksid; + } + + public void setAsksid(String asksid) { + this.asksid = asksid; + } + + public String getQuestion() { + return this.question; + } + + public void setQuestion(String question) { + this.question = question; + } + + public String getAddtime() { + return this.addtime; + } + + public void setAddtime(String addtime) { + this.addtime = addtime; + } + + public String getMemo() { + return this.memo; + } + + public void setMemo(String memo) { + this.memo = memo; + } + + + // 重载方法 生成JSON类型字符串 + @Override + public String toString() { + return this.toJsonString(); + } + + //直接转换成JSON字符串 + private String toJsonString() { + JSONObject jsonString = new JSONObject(); + jsonString.put("asksid", this.asksid); // 主键编号 + jsonString.put("question", this.question); // 问题 + jsonString.put("addtime", this.addtime); // 创建日期 + jsonString.put("memo", this.memo); // 备注 + return jsonString.toString(); + } + + + + +} + + + + diff --git a/src/com/entity/Banner.java b/src/com/entity/Banner.java new file mode 100644 index 0000000..140e4db --- /dev/null +++ b/src/com/entity/Banner.java @@ -0,0 +1,62 @@ +package com.entity; + +import java.util.ArrayList; +import java.util.List; +import com.util.VeDate; + +public class Banner { + private String bannerid = "B" + VeDate.getStringId();// 生成主键编号 + private String bannername;// 分类名称 + private String addtime;// 创建日期 + private String memo;// 备注 + + public String getBannerid() { + return bannerid; + } + + public void setBannerid(String bannerid) { + this.bannerid = bannerid; + } + + public String getBannername() { + return this.bannername; + } + + public void setBannername(String bannername) { + this.bannername = bannername; + } + + public String getAddtime() { + return this.addtime; + } + + public void setAddtime(String addtime) { + this.addtime = addtime; + } + + public String getMemo() { + return this.memo; + } + + public void setMemo(String memo) { + this.memo = memo; + } + + private List
articleList = new ArrayList
(); + + public List
getArticleList() { + return articleList; + } + + public void setArticleList(List
articleList) { + this.articleList = articleList; + } + + // 重载方法 生成JSON类型字符串 + @Override + public String toString() { + return "Banner [bannerid=" + this.bannerid + ", bannername=" + this.bannername + ", addtime=" + this.addtime + ", memo=" + this.memo + + "]"; + } + +} diff --git a/src/com/entity/Complains.java b/src/com/entity/Complains.java new file mode 100644 index 0000000..b0c82e9 --- /dev/null +++ b/src/com/entity/Complains.java @@ -0,0 +1,118 @@ +package com.entity; + +import com.util.VeDate; +import com.alibaba.fastjson.JSONObject; + +// 意见反馈表的实体类 +public class Complains { + private String complainsid = "C"+VeDate.getStringId(); // 生成主键编号 + private String usersid; // 用户 + private String title; // 标题 + private String contents; // 内容 + private String addtime; // 日期 + private String status; // 状态 + private String reps; // 管理员回复 + private String username; // 映射数据 + private Users users;// 多对一映射类 + public String getComplainsid() { + return this.complainsid; + } + + public void setComplainsid(String complainsid) { + this.complainsid = complainsid; + } + + public String getUsersid() { + return this.usersid; + } + + public void setUsersid(String usersid) { + this.usersid = usersid; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContents() { + return this.contents; + } + + public void setContents(String contents) { + this.contents = contents; + } + + public String getAddtime() { + return this.addtime; + } + + public void setAddtime(String addtime) { + this.addtime = addtime; + } + + public String getStatus() { + return this.status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getReps() { + return this.reps; + } + + public void setReps(String reps) { + this.reps = reps; + } + + public Users getUsers() { + return this.users; + } + + public void setUsers(Users users) { + this.users = users; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + + // 重载方法 生成JSON类型字符串 + @Override + public String toString() { + return this.toJsonString(); + } + + //直接转换成JSON字符串 + private String toJsonString() { + JSONObject jsonString = new JSONObject(); + jsonString.put("complainsid", this.complainsid); // 主键编号 + jsonString.put("usersid", this.usersid); // 用户 + jsonString.put("title", this.title); // 标题 + jsonString.put("contents", this.contents); // 内容 + jsonString.put("addtime", this.addtime); // 日期 + jsonString.put("status", this.status); // 状态 + jsonString.put("reps", this.reps); // 管理员回复 + jsonString.put("Users", this.users); // 多对一映射类 + jsonString.put("username", this.username); // 映射数据 + return jsonString.toString(); + } + + + + +} + + + + diff --git a/src/com/entity/Fav.java b/src/com/entity/Fav.java new file mode 100644 index 0000000..328098a --- /dev/null +++ b/src/com/entity/Fav.java @@ -0,0 +1,109 @@ +package com.entity; + +import com.util.VeDate; +import com.alibaba.fastjson.JSONObject; + +// 用户收藏表的实体类 +public class Fav { + private String favid = "F"+VeDate.getStringId(); // 生成主键编号 + private String usersid; // 用户 + private String articleid; // 新闻 + private String addtime; // 收藏日期 + private String username; // 映射数据 + private String title; // 映射数据 + private Users users;// 多对一映射类 + private Article article;// 多对一映射类 + + public String getFavid() { + return this.favid; + } + + public void setFavid(String favid) { + this.favid = favid; + } + + public String getUsersid() { + return this.usersid; + } + + public void setUsersid(String usersid) { + this.usersid = usersid; + } + + public String getArticleid() { + return this.articleid; + } + + public void setArticleid(String articleid) { + this.articleid = articleid; + } + + public String getAddtime() { + return this.addtime; + } + + public void setAddtime(String addtime) { + this.addtime = addtime; + } + + public Users getUsers() { + return this.users; + } + + public void setUsers(Users users) { + this.users = users; + } + + public Article getArticle() { + return this.article; + } + + public void setArticle(Article article) { + this.article = article; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + + // 重载方法 生成JSON类型字符串 + @Override + public String toString() { + return this.toJsonString(); + } + + //直接转换成JSON字符串 + private String toJsonString() { + JSONObject jsonString = new JSONObject(); + jsonString.put("favid", this.favid); // 主键编号 + jsonString.put("usersid", this.usersid); // 用户 + jsonString.put("articleid", this.articleid); // 新闻 + jsonString.put("addtime", this.addtime); // 收藏日期 + jsonString.put("Users", this.users); // 多对一映射类 + jsonString.put("Article", this.article); // 多对一映射类 + jsonString.put("username", this.username); // 映射数据 + jsonString.put("title", this.title); // 映射数据 + return jsonString.toString(); + } + + + + +} + + + + diff --git a/src/com/entity/Topic.java b/src/com/entity/Topic.java new file mode 100644 index 0000000..bb00dfb --- /dev/null +++ b/src/com/entity/Topic.java @@ -0,0 +1,119 @@ +package com.entity; + +import com.util.VeDate; +import com.alibaba.fastjson.JSONObject; + +// 用户评论表的实体类 +public class Topic { + private String topicid = "T"+VeDate.getStringId(); // 生成主键编号 + private String usersid; // 用户 + private String articleid; // 新闻 + private String contents; // 内容 + private String addtime; // 日期 + private String username; // 映射数据 + private String title; // 映射数据 + private Users users;// 多对一映射类 + private Article article;// 多对一映射类 + + public String getTopicid() { + return this.topicid; + } + + public void setTopicid(String topicid) { + this.topicid = topicid; + } + + public String getUsersid() { + return this.usersid; + } + + public void setUsersid(String usersid) { + this.usersid = usersid; + } + + public String getArticleid() { + return this.articleid; + } + + public void setArticleid(String articleid) { + this.articleid = articleid; + } + + public String getContents() { + return this.contents; + } + + public void setContents(String contents) { + this.contents = contents; + } + + public String getAddtime() { + return this.addtime; + } + + public void setAddtime(String addtime) { + this.addtime = addtime; + } + + public Users getUsers() { + return this.users; + } + + public void setUsers(Users users) { + this.users = users; + } + + public Article getArticle() { + return this.article; + } + + public void setArticle(Article article) { + this.article = article; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + + // 重载方法 生成JSON类型字符串 + @Override + public String toString() { + return this.toJsonString(); + } + + //直接转换成JSON字符串 + private String toJsonString() { + JSONObject jsonString = new JSONObject(); + jsonString.put("topicid", this.topicid); // 主键编号 + jsonString.put("usersid", this.usersid); // 用户 + jsonString.put("articleid", this.articleid); // 新闻 + jsonString.put("contents", this.contents); // 内容 + jsonString.put("addtime", this.addtime); // 日期 + jsonString.put("Users", this.users); // 多对一映射类 + jsonString.put("Article", this.article); // 多对一映射类 + jsonString.put("username", this.username); // 映射数据 + jsonString.put("title", this.title); // 映射数据 + return jsonString.toString(); + } + + + + +} + + + + diff --git a/src/com/entity/Users.java b/src/com/entity/Users.java new file mode 100644 index 0000000..6b4b646 --- /dev/null +++ b/src/com/entity/Users.java @@ -0,0 +1,137 @@ +package com.entity; + +import com.alibaba.fastjson.JSONObject; +import com.util.VeDate; + +// 网站用户表的实体类 +public class Users { + private String usersid = "U" + VeDate.getStringId(); // 生成主键编号 + private String username; // 用户名 + private String password; // 密码 + private String realname; // 姓名 + private String sex; // 性别 + private String birthday; // 出生日期 + private String contact; // 联系方式 + private String regdate; // 注册日期 + private String asksid; // 提示问题 + private String answer; // 问题答案 + private Asks asks;// 多对一映射类 + private String questions; + + public String getQuestions() { + return questions; + } + + public void setQuestions(String questions) { + this.questions = questions; + } + + public String getAsksid() { + return asksid; + } + + public void setAsksid(String asksid) { + this.asksid = asksid; + } + + public String getAnswer() { + return answer; + } + + public void setAnswer(String answer) { + this.answer = answer; + } + + public Asks getAsks() { + return asks; + } + + public void setAsks(Asks asks) { + this.asks = asks; + } + + public String getUsersid() { + return this.usersid; + } + + public void setUsersid(String usersid) { + this.usersid = usersid; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRealname() { + return this.realname; + } + + public void setRealname(String realname) { + this.realname = realname; + } + + public String getSex() { + return this.sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public String getBirthday() { + return this.birthday; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public String getContact() { + return this.contact; + } + + public void setContact(String contact) { + this.contact = contact; + } + + public String getRegdate() { + return this.regdate; + } + + public void setRegdate(String regdate) { + this.regdate = regdate; + } + + // 重载方法 生成JSON类型字符串 + @Override + public String toString() { + return this.toJsonString(); + } + + // 直接转换成JSON字符串 + private String toJsonString() { + JSONObject jsonString = new JSONObject(); + jsonString.put("usersid", this.usersid); // 主键编号 + jsonString.put("username", this.username); // 用户名 + jsonString.put("password", this.password); // 密码 + jsonString.put("realname", this.realname); // 姓名 + jsonString.put("sex", this.sex); // 性别 + jsonString.put("birthday", this.birthday); // 出生日期 + jsonString.put("contact", this.contact); // 联系方式 + jsonString.put("regdate", this.regdate); // 注册日期 + return jsonString.toString(); + } + +} diff --git a/src/com/service/AdminService.java b/src/com/service/AdminService.java new file mode 100644 index 0000000..9a6caee --- /dev/null +++ b/src/com/service/AdminService.java @@ -0,0 +1,32 @@ +package com.service; +import java.util.List; +import org.springframework.stereotype.Service; +import com.entity.Admin; +@Service("adminService") // 自动注册到Spring容器,不需要再在xml文件定义bean +public interface AdminService { + // 插入管理员表数据 调用adminDAO里的insertAdmin配置 + public int insertAdmin(Admin admin); + + // 更新管理员表数据 调用adminDAO里的updateAdmin配置 + public int updateAdmin(Admin admin); + + // 按主键删除管理员表数据 调用adminDAO里的deleteAdmin配置 + public int deleteAdmin(String adminid); + + // 批量删除管理员表数据 调用mapper包admin.xml里的deleteAdminByIds配置 返回值0(失败),大于0(成功) + public int deleteAdminByIds(String[] ids); + + // 查询全部数据 调用adminDAO里的getAllAdmin配置 + public List getAllAdmin(); + + // 按照Admin类里面的字段名称精确查询 调用adminDAO里的getAdminByCond配置 + public List getAdminByCond(Admin admin); + + // 按照Admin类里面的字段名称模糊查询 调用adminDAO里的getAdminByLike配置 + public List getAdminByLike(Admin admin); + + // 按主键查询表返回单一的Admin实例 调用adminDAO里的getAdminById配置 + public Admin getAdminById(String adminid); + +} + diff --git a/src/com/service/ArticleService.java b/src/com/service/ArticleService.java new file mode 100644 index 0000000..126ea57 --- /dev/null +++ b/src/com/service/ArticleService.java @@ -0,0 +1,36 @@ +package com.service; + +import java.util.List; +import org.springframework.stereotype.Service; +import com.entity.Article; + +@Service("articleService") +public interface ArticleService { + // 插入数据 调用articleDAO里的insertArticle配置 + public int insertArticle(Article article); + + // 更新数据 调用articleDAO里的updateArticle配置 + public int updateArticle(Article article); + + // 删除数据 调用articleDAO里的deleteArticle配置 + public int deleteArticle(String articleid); + + // 查询全部数据 调用articleDAO里的getAllArticle配置 + public List
getAllArticle(); + + public List
getFlvArticle(); + + public List
getTopArticle(); + + public List
getArticleByBanner(String bannerid); + + // 按照Article类里面的字段名称精确查询 调用articleDAO里的getArticleByCond配置 + public List
getArticleByCond(Article article); + + // 按照Article类里面的字段名称模糊查询 调用articleDAO里的getArticleByLike配置 + public List
getArticleByLike(Article article); + + // 按主键查询表返回单一的Article实例 调用articleDAO里的getArticleById配置 + public Article getArticleById(String articleid); + +} diff --git a/src/com/service/AsksService.java b/src/com/service/AsksService.java new file mode 100644 index 0000000..5df2555 --- /dev/null +++ b/src/com/service/AsksService.java @@ -0,0 +1,32 @@ +package com.service; +import java.util.List; +import org.springframework.stereotype.Service; +import com.entity.Asks; +@Service("asksService") // 自动注册到Spring容器,不需要再在xml文件定义bean +public interface AsksService { + // 插入提示问题表数据 调用asksDAO里的insertAsks配置 + public int insertAsks(Asks asks); + + // 更新提示问题表数据 调用asksDAO里的updateAsks配置 + public int updateAsks(Asks asks); + + // 按主键删除提示问题表数据 调用asksDAO里的deleteAsks配置 + public int deleteAsks(String asksid); + + // 批量删除提示问题表数据 调用mapper包asks.xml里的deleteAsksByIds配置 返回值0(失败),大于0(成功) + public int deleteAsksByIds(String[] ids); + + // 查询全部数据 调用asksDAO里的getAllAsks配置 + public List getAllAsks(); + + // 按照Asks类里面的字段名称精确查询 调用asksDAO里的getAsksByCond配置 + public List getAsksByCond(Asks asks); + + // 按照Asks类里面的字段名称模糊查询 调用asksDAO里的getAsksByLike配置 + public List getAsksByLike(Asks asks); + + // 按主键查询表返回单一的Asks实例 调用asksDAO里的getAsksById配置 + public Asks getAsksById(String asksid); + +} + diff --git a/src/com/service/BannerService.java b/src/com/service/BannerService.java new file mode 100644 index 0000000..fd4550d --- /dev/null +++ b/src/com/service/BannerService.java @@ -0,0 +1,29 @@ +package com.service; +import java.util.List; +import org.springframework.stereotype.Service; +import com.entity.Banner; +@Service("bannerService") +public interface BannerService { + // 插入数据 调用bannerDAO里的insertBanner配置 + public int insertBanner(Banner banner); + + // 更新数据 调用bannerDAO里的updateBanner配置 + public int updateBanner(Banner banner); + + // 删除数据 调用bannerDAO里的deleteBanner配置 + public int deleteBanner(String bannerid); + + // 查询全部数据 调用bannerDAO里的getAllBanner配置 + public List getAllBanner(); + + // 按照Banner类里面的字段名称精确查询 调用bannerDAO里的getBannerByCond配置 + public List getBannerByCond(Banner banner); + + // 按照Banner类里面的字段名称模糊查询 调用bannerDAO里的getBannerByLike配置 + public List getBannerByLike(Banner banner); + + // 按主键查询表返回单一的Banner实例 调用bannerDAO里的getBannerById配置 + public Banner getBannerById(String bannerid); + +} + diff --git a/src/com/service/ComplainsService.java b/src/com/service/ComplainsService.java new file mode 100644 index 0000000..5aa38a4 --- /dev/null +++ b/src/com/service/ComplainsService.java @@ -0,0 +1,32 @@ +package com.service; +import java.util.List; +import org.springframework.stereotype.Service; +import com.entity.Complains; +@Service("complainsService") // 自动注册到Spring容器,不需要再在xml文件定义bean +public interface ComplainsService { + // 插入意见反馈表数据 调用complainsDAO里的insertComplains配置 + public int insertComplains(Complains complains); + + // 更新意见反馈表数据 调用complainsDAO里的updateComplains配置 + public int updateComplains(Complains complains); + + // 按主键删除意见反馈表数据 调用complainsDAO里的deleteComplains配置 + public int deleteComplains(String complainsid); + + // 批量删除意见反馈表数据 调用mapper包complains.xml里的deleteComplainsByIds配置 返回值0(失败),大于0(成功) + public int deleteComplainsByIds(String[] ids); + + // 查询全部数据 调用complainsDAO里的getAllComplains配置 + public List getAllComplains(); + + // 按照Complains类里面的字段名称精确查询 调用complainsDAO里的getComplainsByCond配置 + public List getComplainsByCond(Complains complains); + + // 按照Complains类里面的字段名称模糊查询 调用complainsDAO里的getComplainsByLike配置 + public List getComplainsByLike(Complains complains); + + // 按主键查询表返回单一的Complains实例 调用complainsDAO里的getComplainsById配置 + public Complains getComplainsById(String complainsid); + +} + diff --git a/src/com/service/FavService.java b/src/com/service/FavService.java new file mode 100644 index 0000000..28a0d55 --- /dev/null +++ b/src/com/service/FavService.java @@ -0,0 +1,32 @@ +package com.service; +import java.util.List; +import org.springframework.stereotype.Service; +import com.entity.Fav; +@Service("favService") // 自动注册到Spring容器,不需要再在xml文件定义bean +public interface FavService { + // 插入用户收藏表数据 调用favDAO里的insertFav配置 + public int insertFav(Fav fav); + + // 更新用户收藏表数据 调用favDAO里的updateFav配置 + public int updateFav(Fav fav); + + // 按主键删除用户收藏表数据 调用favDAO里的deleteFav配置 + public int deleteFav(String favid); + + // 批量删除用户收藏表数据 调用mapper包fav.xml里的deleteFavByIds配置 返回值0(失败),大于0(成功) + public int deleteFavByIds(String[] ids); + + // 查询全部数据 调用favDAO里的getAllFav配置 + public List getAllFav(); + + // 按照Fav类里面的字段名称精确查询 调用favDAO里的getFavByCond配置 + public List getFavByCond(Fav fav); + + // 按照Fav类里面的字段名称模糊查询 调用favDAO里的getFavByLike配置 + public List getFavByLike(Fav fav); + + // 按主键查询表返回单一的Fav实例 调用favDAO里的getFavById配置 + public Fav getFavById(String favid); + +} + diff --git a/src/com/service/TopicService.java b/src/com/service/TopicService.java new file mode 100644 index 0000000..5a6c760 --- /dev/null +++ b/src/com/service/TopicService.java @@ -0,0 +1,32 @@ +package com.service; +import java.util.List; +import org.springframework.stereotype.Service; +import com.entity.Topic; +@Service("topicService") // 自动注册到Spring容器,不需要再在xml文件定义bean +public interface TopicService { + // 插入用户评论表数据 调用topicDAO里的insertTopic配置 + public int insertTopic(Topic topic); + + // 更新用户评论表数据 调用topicDAO里的updateTopic配置 + public int updateTopic(Topic topic); + + // 按主键删除用户评论表数据 调用topicDAO里的deleteTopic配置 + public int deleteTopic(String topicid); + + // 批量删除用户评论表数据 调用mapper包topic.xml里的deleteTopicByIds配置 返回值0(失败),大于0(成功) + public int deleteTopicByIds(String[] ids); + + // 查询全部数据 调用topicDAO里的getAllTopic配置 + public List getAllTopic(); + + // 按照Topic类里面的字段名称精确查询 调用topicDAO里的getTopicByCond配置 + public List getTopicByCond(Topic topic); + + // 按照Topic类里面的字段名称模糊查询 调用topicDAO里的getTopicByLike配置 + public List getTopicByLike(Topic topic); + + // 按主键查询表返回单一的Topic实例 调用topicDAO里的getTopicById配置 + public Topic getTopicById(String topicid); + +} + diff --git a/src/com/service/UsersService.java b/src/com/service/UsersService.java new file mode 100644 index 0000000..c742dc3 --- /dev/null +++ b/src/com/service/UsersService.java @@ -0,0 +1,32 @@ +package com.service; +import java.util.List; +import org.springframework.stereotype.Service; +import com.entity.Users; +@Service("usersService") // 自动注册到Spring容器,不需要再在xml文件定义bean +public interface UsersService { + // 插入网站用户表数据 调用usersDAO里的insertUsers配置 + public int insertUsers(Users users); + + // 更新网站用户表数据 调用usersDAO里的updateUsers配置 + public int updateUsers(Users users); + + // 按主键删除网站用户表数据 调用usersDAO里的deleteUsers配置 + public int deleteUsers(String usersid); + + // 批量删除网站用户表数据 调用mapper包users.xml里的deleteUsersByIds配置 返回值0(失败),大于0(成功) + public int deleteUsersByIds(String[] ids); + + // 查询全部数据 调用usersDAO里的getAllUsers配置 + public List getAllUsers(); + + // 按照Users类里面的字段名称精确查询 调用usersDAO里的getUsersByCond配置 + public List getUsersByCond(Users users); + + // 按照Users类里面的字段名称模糊查询 调用usersDAO里的getUsersByLike配置 + public List getUsersByLike(Users users); + + // 按主键查询表返回单一的Users实例 调用usersDAO里的getUsersById配置 + public Users getUsersById(String usersid); + +} + diff --git a/src/com/service/impl/AdminServiceImpl.java b/src/com/service/impl/AdminServiceImpl.java new file mode 100644 index 0000000..5c02d73 --- /dev/null +++ b/src/com/service/impl/AdminServiceImpl.java @@ -0,0 +1,54 @@ +package com.service.impl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.dao.AdminDAO; +import com.entity.Admin; +import com.service.AdminService; + +@Service("adminService") // +public class AdminServiceImpl implements AdminService { + @Autowired // 它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作 + private AdminDAO adminDAO; + @Override // 继承接口的新增管理员表数据 返回值0(失败),1(成功) + public int insertAdmin(Admin admin) { + return this.adminDAO.insertAdmin(admin); + } + + @Override // 继承接口的更新管理员表数据 返回值0(失败),1(成功) + public int updateAdmin(Admin admin) { + return this.adminDAO.updateAdmin(admin); + } + + @Override // 继承接口的按主键删除管理员表数据 返回值0(失败),1(成功) + public int deleteAdmin(String adminid) { + return this.adminDAO.deleteAdmin(adminid); + } + + @Override // 继承接口的批量删除管理员表数据 返回值0(失败),大于0(成功) + public int deleteAdminByIds(String[] ids) { + return this.adminDAO.deleteAdminByIds(ids); + } + + @Override // 继承接口的查询管理员表全部数据 + public List getAllAdmin() { + return this.adminDAO.getAllAdmin(); + } + + @Override // 继承接口的按条件精确查询管理员表数据 + public List getAdminByCond(Admin admin) { + return this.adminDAO.getAdminByCond(admin); + } + + @Override // 继承接口的按条件模糊查询管理员表数据 + public List getAdminByLike(Admin admin) { + return this.adminDAO.getAdminByLike(admin); + } + + @Override // 继承接口的按主键查询管理员表数据 返回Entity实例 + public Admin getAdminById(String adminid) { + return this.adminDAO.getAdminById(adminid); + } + +} + diff --git a/src/com/service/impl/ArticleServiceImpl.java b/src/com/service/impl/ArticleServiceImpl.java new file mode 100644 index 0000000..44292f6 --- /dev/null +++ b/src/com/service/impl/ArticleServiceImpl.java @@ -0,0 +1,65 @@ +package com.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.dao.ArticleDAO; +import com.entity.Article; +import com.service.ArticleService; + +@Service("articleService") +public class ArticleServiceImpl implements ArticleService { + @Autowired + private ArticleDAO articleDAO; + + @Override // 继承接口的新增 返回值0(失败),1(成功) + public int insertArticle(Article article) { + return this.articleDAO.insertArticle(article); + } + + @Override // 继承接口的更新 返回值0(失败),1(成功) + public int updateArticle(Article article) { + return this.articleDAO.updateArticle(article); + } + + @Override // 继承接口的删除 返回值0(失败),1(成功) + public int deleteArticle(String articleid) { + return this.articleDAO.deleteArticle(articleid); + } + + @Override // 继承接口的查询全部 + public List
getAllArticle() { + return this.articleDAO.getAllArticle(); + } + + @Override + public List
getFlvArticle() { + return this.articleDAO.getFlvArticle(); + } + + @Override + public List
getTopArticle() { + return this.articleDAO.getTopArticle(); + } + + @Override + public List
getArticleByBanner(String bannerid) { + return this.articleDAO.getArticleByBanner(bannerid); + } + + @Override // 继承接口的按条件精确查询 + public List
getArticleByCond(Article article) { + return this.articleDAO.getArticleByCond(article); + } + + @Override // 继承接口的按条件模糊查询 + public List
getArticleByLike(Article article) { + return this.articleDAO.getArticleByLike(article); + } + + @Override // 继承接口的按主键查询 返回Entity实例 + public Article getArticleById(String articleid) { + return this.articleDAO.getArticleById(articleid); + } + +} diff --git a/src/com/service/impl/AsksServiceImpl.java b/src/com/service/impl/AsksServiceImpl.java new file mode 100644 index 0000000..3c27fb4 --- /dev/null +++ b/src/com/service/impl/AsksServiceImpl.java @@ -0,0 +1,54 @@ +package com.service.impl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.dao.AsksDAO; +import com.entity.Asks; +import com.service.AsksService; + +@Service("asksService") // +public class AsksServiceImpl implements AsksService { + @Autowired // 它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作 + private AsksDAO asksDAO; + @Override // 继承接口的新增提示问题表数据 返回值0(失败),1(成功) + public int insertAsks(Asks asks) { + return this.asksDAO.insertAsks(asks); + } + + @Override // 继承接口的更新提示问题表数据 返回值0(失败),1(成功) + public int updateAsks(Asks asks) { + return this.asksDAO.updateAsks(asks); + } + + @Override // 继承接口的按主键删除提示问题表数据 返回值0(失败),1(成功) + public int deleteAsks(String asksid) { + return this.asksDAO.deleteAsks(asksid); + } + + @Override // 继承接口的批量删除提示问题表数据 返回值0(失败),大于0(成功) + public int deleteAsksByIds(String[] ids) { + return this.asksDAO.deleteAsksByIds(ids); + } + + @Override // 继承接口的查询提示问题表全部数据 + public List getAllAsks() { + return this.asksDAO.getAllAsks(); + } + + @Override // 继承接口的按条件精确查询提示问题表数据 + public List getAsksByCond(Asks asks) { + return this.asksDAO.getAsksByCond(asks); + } + + @Override // 继承接口的按条件模糊查询提示问题表数据 + public List getAsksByLike(Asks asks) { + return this.asksDAO.getAsksByLike(asks); + } + + @Override // 继承接口的按主键查询提示问题表数据 返回Entity实例 + public Asks getAsksById(String asksid) { + return this.asksDAO.getAsksById(asksid); + } + +} + diff --git a/src/com/service/impl/BannerServiceImpl.java b/src/com/service/impl/BannerServiceImpl.java new file mode 100644 index 0000000..1ae7082 --- /dev/null +++ b/src/com/service/impl/BannerServiceImpl.java @@ -0,0 +1,49 @@ +package com.service.impl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.dao.BannerDAO; +import com.entity.Banner; +import com.service.BannerService; + +@Service("bannerService") +public class BannerServiceImpl implements BannerService { + @Autowired + private BannerDAO bannerDAO; + @Override // 继承接口的新增 返回值0(失败),1(成功) + public int insertBanner(Banner banner) { + return this.bannerDAO.insertBanner(banner); + } + + @Override // 继承接口的更新 返回值0(失败),1(成功) + public int updateBanner(Banner banner) { + return this.bannerDAO.updateBanner(banner); + } + + @Override // 继承接口的删除 返回值0(失败),1(成功) + public int deleteBanner(String bannerid) { + return this.bannerDAO.deleteBanner(bannerid); + } + + @Override // 继承接口的查询全部 + public List getAllBanner() { + return this.bannerDAO.getAllBanner(); + } + + @Override // 继承接口的按条件精确查询 + public List getBannerByCond(Banner banner) { + return this.bannerDAO.getBannerByCond(banner); + } + + @Override // 继承接口的按条件模糊查询 + public List getBannerByLike(Banner banner) { + return this.bannerDAO.getBannerByLike(banner); + } + + @Override // 继承接口的按主键查询 返回Entity实例 + public Banner getBannerById(String bannerid) { + return this.bannerDAO.getBannerById(bannerid); + } + +} + diff --git a/src/com/service/impl/ComplainsServiceImpl.java b/src/com/service/impl/ComplainsServiceImpl.java new file mode 100644 index 0000000..11c1cfa --- /dev/null +++ b/src/com/service/impl/ComplainsServiceImpl.java @@ -0,0 +1,54 @@ +package com.service.impl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.dao.ComplainsDAO; +import com.entity.Complains; +import com.service.ComplainsService; + +@Service("complainsService") // +public class ComplainsServiceImpl implements ComplainsService { + @Autowired // 它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作 + private ComplainsDAO complainsDAO; + @Override // 继承接口的新增意见反馈表数据 返回值0(失败),1(成功) + public int insertComplains(Complains complains) { + return this.complainsDAO.insertComplains(complains); + } + + @Override // 继承接口的更新意见反馈表数据 返回值0(失败),1(成功) + public int updateComplains(Complains complains) { + return this.complainsDAO.updateComplains(complains); + } + + @Override // 继承接口的按主键删除意见反馈表数据 返回值0(失败),1(成功) + public int deleteComplains(String complainsid) { + return this.complainsDAO.deleteComplains(complainsid); + } + + @Override // 继承接口的批量删除意见反馈表数据 返回值0(失败),大于0(成功) + public int deleteComplainsByIds(String[] ids) { + return this.complainsDAO.deleteComplainsByIds(ids); + } + + @Override // 继承接口的查询意见反馈表全部数据 + public List getAllComplains() { + return this.complainsDAO.getAllComplains(); + } + + @Override // 继承接口的按条件精确查询意见反馈表数据 + public List getComplainsByCond(Complains complains) { + return this.complainsDAO.getComplainsByCond(complains); + } + + @Override // 继承接口的按条件模糊查询意见反馈表数据 + public List getComplainsByLike(Complains complains) { + return this.complainsDAO.getComplainsByLike(complains); + } + + @Override // 继承接口的按主键查询意见反馈表数据 返回Entity实例 + public Complains getComplainsById(String complainsid) { + return this.complainsDAO.getComplainsById(complainsid); + } + +} + diff --git a/src/com/service/impl/FavServiceImpl.java b/src/com/service/impl/FavServiceImpl.java new file mode 100644 index 0000000..b8d67b5 --- /dev/null +++ b/src/com/service/impl/FavServiceImpl.java @@ -0,0 +1,54 @@ +package com.service.impl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.dao.FavDAO; +import com.entity.Fav; +import com.service.FavService; + +@Service("favService") // +public class FavServiceImpl implements FavService { + @Autowired // 它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作 + private FavDAO favDAO; + @Override // 继承接口的新增用户收藏表数据 返回值0(失败),1(成功) + public int insertFav(Fav fav) { + return this.favDAO.insertFav(fav); + } + + @Override // 继承接口的更新用户收藏表数据 返回值0(失败),1(成功) + public int updateFav(Fav fav) { + return this.favDAO.updateFav(fav); + } + + @Override // 继承接口的按主键删除用户收藏表数据 返回值0(失败),1(成功) + public int deleteFav(String favid) { + return this.favDAO.deleteFav(favid); + } + + @Override // 继承接口的批量删除用户收藏表数据 返回值0(失败),大于0(成功) + public int deleteFavByIds(String[] ids) { + return this.favDAO.deleteFavByIds(ids); + } + + @Override // 继承接口的查询用户收藏表全部数据 + public List getAllFav() { + return this.favDAO.getAllFav(); + } + + @Override // 继承接口的按条件精确查询用户收藏表数据 + public List getFavByCond(Fav fav) { + return this.favDAO.getFavByCond(fav); + } + + @Override // 继承接口的按条件模糊查询用户收藏表数据 + public List getFavByLike(Fav fav) { + return this.favDAO.getFavByLike(fav); + } + + @Override // 继承接口的按主键查询用户收藏表数据 返回Entity实例 + public Fav getFavById(String favid) { + return this.favDAO.getFavById(favid); + } + +} + diff --git a/src/com/service/impl/TopicServiceImpl.java b/src/com/service/impl/TopicServiceImpl.java new file mode 100644 index 0000000..8e2ebaa --- /dev/null +++ b/src/com/service/impl/TopicServiceImpl.java @@ -0,0 +1,54 @@ +package com.service.impl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.dao.TopicDAO; +import com.entity.Topic; +import com.service.TopicService; + +@Service("topicService") // +public class TopicServiceImpl implements TopicService { + @Autowired // 它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作 + private TopicDAO topicDAO; + @Override // 继承接口的新增用户评论表数据 返回值0(失败),1(成功) + public int insertTopic(Topic topic) { + return this.topicDAO.insertTopic(topic); + } + + @Override // 继承接口的更新用户评论表数据 返回值0(失败),1(成功) + public int updateTopic(Topic topic) { + return this.topicDAO.updateTopic(topic); + } + + @Override // 继承接口的按主键删除用户评论表数据 返回值0(失败),1(成功) + public int deleteTopic(String topicid) { + return this.topicDAO.deleteTopic(topicid); + } + + @Override // 继承接口的批量删除用户评论表数据 返回值0(失败),大于0(成功) + public int deleteTopicByIds(String[] ids) { + return this.topicDAO.deleteTopicByIds(ids); + } + + @Override // 继承接口的查询用户评论表全部数据 + public List getAllTopic() { + return this.topicDAO.getAllTopic(); + } + + @Override // 继承接口的按条件精确查询用户评论表数据 + public List getTopicByCond(Topic topic) { + return this.topicDAO.getTopicByCond(topic); + } + + @Override // 继承接口的按条件模糊查询用户评论表数据 + public List getTopicByLike(Topic topic) { + return this.topicDAO.getTopicByLike(topic); + } + + @Override // 继承接口的按主键查询用户评论表数据 返回Entity实例 + public Topic getTopicById(String topicid) { + return this.topicDAO.getTopicById(topicid); + } + +} + diff --git a/src/com/service/impl/UsersServiceImpl.java b/src/com/service/impl/UsersServiceImpl.java new file mode 100644 index 0000000..df0fc58 --- /dev/null +++ b/src/com/service/impl/UsersServiceImpl.java @@ -0,0 +1,54 @@ +package com.service.impl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.dao.UsersDAO; +import com.entity.Users; +import com.service.UsersService; + +@Service("usersService") // +public class UsersServiceImpl implements UsersService { + @Autowired // 它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作 + private UsersDAO usersDAO; + @Override // 继承接口的新增网站用户表数据 返回值0(失败),1(成功) + public int insertUsers(Users users) { + return this.usersDAO.insertUsers(users); + } + + @Override // 继承接口的更新网站用户表数据 返回值0(失败),1(成功) + public int updateUsers(Users users) { + return this.usersDAO.updateUsers(users); + } + + @Override // 继承接口的按主键删除网站用户表数据 返回值0(失败),1(成功) + public int deleteUsers(String usersid) { + return this.usersDAO.deleteUsers(usersid); + } + + @Override // 继承接口的批量删除网站用户表数据 返回值0(失败),大于0(成功) + public int deleteUsersByIds(String[] ids) { + return this.usersDAO.deleteUsersByIds(ids); + } + + @Override // 继承接口的查询网站用户表全部数据 + public List getAllUsers() { + return this.usersDAO.getAllUsers(); + } + + @Override // 继承接口的按条件精确查询网站用户表数据 + public List getUsersByCond(Users users) { + return this.usersDAO.getUsersByCond(users); + } + + @Override // 继承接口的按条件模糊查询网站用户表数据 + public List getUsersByLike(Users users) { + return this.usersDAO.getUsersByLike(users); + } + + @Override // 继承接口的按主键查询网站用户表数据 返回Entity实例 + public Users getUsersById(String usersid) { + return this.usersDAO.getUsersById(usersid); + } + +} + diff --git a/src/com/test/AdminTest.java b/src/com/test/AdminTest.java new file mode 100644 index 0000000..a071a5b --- /dev/null +++ b/src/com/test/AdminTest.java @@ -0,0 +1,32 @@ +package com.test; + +import java.util.UUID; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.dao.AdminDAO; +import com.entity.Admin; +import com.util.VeDate; + +public class AdminTest { + + @SuppressWarnings("resource") + public static void main(String[] args) { + ApplicationContext resource = new ClassPathXmlApplicationContext("springmvc-servlet.xml"); + AdminDAO adminDAO = (AdminDAO) resource.getBean(AdminDAO.class); + for (int i = 0; i < 45; i++) { + Admin admin = new Admin(); + admin.setAdminid(UUID.randomUUID().toString().replace("-", "")); + admin.setUsername("admin" + i); + admin.setPassword("admin" + i); + admin.setRealname("admin" + i); + admin.setContact("-" + i + i * i); + admin.setAddtime(VeDate.getStringDateShort()); + adminDAO.insertAdmin(admin); + } + } +} + + + diff --git a/src/com/test/UserTest.java b/src/com/test/UserTest.java new file mode 100644 index 0000000..db7bdfe --- /dev/null +++ b/src/com/test/UserTest.java @@ -0,0 +1,78 @@ +package com.test; + +import java.util.Random; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.dao.UsersDAO; +import com.entity.Users; +import com.util.VeDate; + +//用于生成测试用户的类 +public class UserTest { + + @SuppressWarnings("resource") + public static void main(String[] args) { + ApplicationContext resource = new ClassPathXmlApplicationContext("springmvc-servlet.xml"); + UsersDAO usersDAO = (UsersDAO) resource.getBean(UsersDAO.class); + String[] realname = { "郑伊雯", "雷进宝", "吴美隆", "吴心真", "王美珠", "郭芳天", "李雅惠", "陈文婷", "曹敏侑", "王依婷", "陈婉璇", "吴美玉", "蔡依婷", + "郑昌梦", "林家纶", "黄丽昆", "李育泉", "黄芸欢", "吴韵如", "李肇芬", "卢木仲", "李成白", "方兆玉", "刘翊惠", "丁汉臻", "吴佳瑞", "舒绿珮", "周白芷", + "张姿妤", "张虹伦", "周琼玟", "倪怡芳", "郭贵妃", "杨佩芳", "黄文旺", "黄盛玫", "郑丽青", "许智云", "张孟涵", "李小爱", "王恩龙", "朱政廷", "邓诗涵", + "陈政倩", "吴俊伯", "阮馨学", "翁惠珠", "吴思翰", "林佩玲", "邓海来", "陈翊依", "李建智", "武淑芬", "金雅琪", "赖怡宜", "黄育霖", "张仪湖", "王俊民", + "张诗刚", "林慧颖", "沈俊君", "陈淑妤", "李姿伶", "高咏钰", "黄彦宜", "周孟儒", "潘欣臻", "李祯韵", "叶洁启", "梁哲宇", "黄晓萍", "杨雅萍", "卢志铭", + "张茂以", "林婉婷", "蔡宜芸", "林珮瑜", "黄柏仪", "周逸珮", "夏雅惠", "王采珮", "林孟霖", "林竹水", "王怡乐", "王爱乐", "金佳蓉", "韩健毓", "李士杰", + "陈萱珍", "苏姿婷", "张政霖", "李志宏", "陈素达", "陈虹荣", "何美玲", "李仪琳", "张俞幸", "黄秋萍", "潘吉维", "陈智筠", "蔡国伟", "连俊达", "李雅婷", + "李礼娇", "李忆孝", "黄静雯", "陈淳宝", "李文育", "林佳蓉", "罗依茂", "李淑佩", "谢怡君", "王美玲", "黄慧学", "邓幸韵", "陈秀琬", "许岳平", "许爱礼", + "谢一忠", "简志雪", "赵若喜", "许承翰", "姚哲维", "苏俊安", "郭礼钰", "姜佩珊", "张鸿信", "秦欣瑜", "李旺劭", "陈怡爱", "陈秀德", "张佳伶", "郑凯婷", + "郑雅任", "黄国妹", "林芳江", "江骏生", "黄儒纯", "王培伦", "陈蕙侑", "蔡宜慧", "陈信意", "陈惠雯", "张琇纶", "黄碧仪", "陈志文", "谢懿富", "杨凡靖", + "蔡秀琴", "温惠玲", "林宗其", "林绍泰", "何佳慧", "蔡辰纶", "王雅雯", "叶怡财", "冯雅筑", "李伦圣", "彭正仁", "刘小紫", "温燕达", "刘佳雨", "吴婷婷", + "杨怡君", "黄康刚", "林辰和", "陈世人", "吴佩霖", "张伟杰", "刘友淳", "张瑞群", "洪紫芬", "邓家伟", "谢佩任", "戎郁文", "李治火", "林石美", "郑雅茜", + "胡台泰", "陈怡盈", "阙石意", "林盈威", "林志嘉", "李秀玲", "王彦霖", "叶惟芷", "郑星钰", "邱贞伟", "姚扬云", "涂武盛", "王雅顺", "唐欣仪", "陈政圣", + "陈育福", "吴惠雯", "李淑淑", "黄莉秋", "赖俊军", "荆彦璋", "白怡均", "林姿辛", "林雅慧", "詹允坚", "赖淑珍", "吴惠美", "李凯婷", "林承辰", "刘亭宝", + "宋慧元", "连书忠", "余仪礼", "袁哲仪", "杜怡臻", "潘孝东", "周志合", "刘力霞", "林钰婷", "林怡紫", "林俊凯", "蔡于纬", "蔡雅惠", "汪喜祥", "陈铭侑", + "郭子珠", "许伦吉", "陈佳雨", "赖英贤", "吴嘉茹", "陈永桂", "张文宏", "唐欣怡", "丁绍燕", "王雅谕", "叶柏宇", "王婉萍", "王宗清", "刘心霖", "吴柏廷", + "陈怡臻", "杜士豪", "李春勋", "黄雅慧", "吴乔茂", "郑婉如", "李育坚", "黄静雯", "赵一蓉", "邱萱俐", "周立妹", "李宝其", "张信豪", "李昆霖", "陈俊安", + "林建志", "黄韦伶", "李美麟", "张政达", "郑惠玲", "柳忠廷", "黄美娟", "许怡君", "吴崇南", "邱承芷", "叶得梅", "陈祯月", "杨宛儒", "阮肇宪", "杨益霞", + "唐盛人", "许平纬", "许雅如", "林秀绮", "刘昌东", "张家荣", "杨淑君", "吴俊民", "李彦瑜", "李彦文", "王崇以", "王威全", "彭琳以", "许志任", "陈嘉杰", + "蔡志远", "陈信文", "陈思廷", "吴家毓", "李宜紫", "杨毅民", "林志平", "陈伟孝", "刘信俊", "李美治", "徐景隆", "刘怡洁", "陈钰梦", "谢静宜", "戴惠如", + "王香君", "钟汉馨", "郑国玮", "张哲亚", "詹南勋", "潘秋福", "黄奕君", "郭琬婷", "冯家华", "吴佩仁", "周思颖", "张柏钧", "吴世伟", "朱佳琪", "陈宗馨", + "黄菁坚", "郑建泉", "许金志", "平信宏", "蔡佳麟", "杨佳宏", "陈皓雅", "吴翊意", "张佩珊", "温欣桦", "王诗铭", "许宜辰", "林孟哲", "黄善宇", "王怡贵", + "许淑玫", "张学玉", "黄美珍", "陈佳心", "宋其琪", "陈致昀", "王建福", "刘莹睿", "陈正莲", "冯萱雨", "金淑敏", "宋廷意", "吴承华", "陈家莲", "王志源", + "张佩君", "黄志伟", "吴孟吟", "蔡玮玉", "张心怡", "吴志绿", "何武霖", "杨中惟", "王佑诚", "徐承财", "温伟伦", "萧郁婷", "陈世伟", "林敬书", "谢孟南", + "项宜真", "崔美珠", "赖筱雯", "陈盛丰", "阮升云", "周怡季", "江佳芸", "郭惠君", "吕智文", "王琼龙", "陈姿茜", "张佩君", "李佩纬", "黄珮心", "李旭友", + "王健以", "蔡幸弘", "刘智钧", "张佳颖", "郭东欣", "黄志忠", "李娇郁", "许欣怡", "杜劭依", "荣美君", "陈翠昆", "陈昆绍", "黄志佩", "黄舜文", "刘丽卿", + "张倩纬", "施珮昆", "郑纬水", "林明玫", "郑琦希", "童家贤", "郭峻豪", "林雅豪", "曲祯妹", "林冠宇", "陈珍莹", "简玟君", "杜阳吟", "许雅菱", "叶木书", + "黄文其", "陈景彦", "蒋承凯", "黄依萍", "黄珮秋", "郑文贤", "柯元燕", "李思雄", "王绍玉", "金尧珊", "李政绍", "叶法盛", "苏琪山", "邱思妤", "王若芳", + "黎彦君", "冷翊瑜", "张明真", "李琪源", "林素侑", "孟敏宇", "怀雅惠", "吴士弘", "张世志", "袁志铭", "林千惠", "宋乐男", "黄淑贞", "王宗盛", "吴永臻", + "陈富财", "钱孟儒", "谢百宜", "曹振豪", "陈品妃", "吴升财", "陈昀雪", "高淑娟", "林智钧", "林秋平", "王汉季", "黄仁添", "詹雅如", "蔡佳麟", "张美君", + "孙姿吟", "陈孟善", "黄美君", "林盈秀", "王姿雯", "王旻峰", "郭淑卿", "谢盈冰", "魏淑华", "刘志宜", "张怡婷", "梁淑敏", "王白木", "方劭中", "田火劭", + "叶佩正", "程巧欢", "陈玮弘", "张毅琳", "吴念筠", "张美惠", "陈欣白", "李怡文", "曹珊贵", "梁家豪", "洪月瑄", "李铭茹", "金杰蕙", "杨冠霖", "吴明宜", + "陆怡雯", "黄立启", "林雅芸", "林佩毓", "李宜珊", "钱怡伶", "刘宗翰", "林台斌", "杨杰均", "连育如", "杨奕名", "郭玉婷", "王翊谦", "彭圣杰", "郑世杰", + "吴承翰", "张琦芸", "邓淑芬", "陈佳芳", "吴秋良", "陈舜文", "蔡靖玮", "林雅舜", "张真勇", "邱益勇", "林懿淳", "郭美慧", "蔡智强", "张智苹", "陈冰茹", + "李思纬", "郑馨仪", "程明辉", "陈弘善", "陈政勋", "卢琬杰", "黄柏菁", "刘佩儒", "陈韦贞", "许台法", "陶志祥", "吴俊宁", "李孟岳", "刘明宪", "吴耀英", + "陈思桦", "井弘坤", "黄明萍", "陈姿颖", "张成欢", "张燕佳", "李雪鸿", "叶志伟", "王石竹", "孙心桂", "舒大钧", "林秋萍", "柯美惠", "姜上宪", "林欣淳", + "郭雅娟", "宋采信", "韩贞仪", "李育羽", "冯玟泰", "林姿儒", "蔡敏坤", "林惠玲", "陈珮义", "林书祯", "黄政霖", "谢姿卿" }; + + for (int i = 0; i < 30; i++) { + Users users = new Users(); + users.setUsersid("U" + VeDate.getStringDatex() + VeDate.getRandom()); + users.setUsername("" + i); + users.setPassword("" + i); + if (i % 2 == 0) { + users.setSex("男"); + } else { + users.setSex("女"); + } + Random rand = new Random(); + int x = rand.nextInt(realname.length - 1); + users.setRealname(realname[x]); + users.setBirthday(VeDate.getStringDateShort()); + users.setRegdate(VeDate.getStringDateShort()); + users.setContact(VeDate.getTel()); + usersDAO.insertUsers(users); + } + + } + +} diff --git a/src/com/util/Excel.java b/src/com/util/Excel.java new file mode 100644 index 0000000..6e32d0e --- /dev/null +++ b/src/com/util/Excel.java @@ -0,0 +1,50 @@ +package com.util; +import java.io.File; +import java.util.List; +import jxl.Workbook; +import jxl.write.Label; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; +/** +* Excel报表生成工具类 使用JXL包生成Excel格式的文件 +* @param savePath 存储路径 +*/ + +public class Excel { + + public String getExcel(List strList, String[] strTitle, String banner, String paths) { + String fp = "upfiles\\" + VeDate.getStringDatex() + ".xls"; + String filepath = paths + fp; + try { + WritableWorkbook book = Workbook.createWorkbook(new File(filepath)); + WritableSheet sheet = book.createSheet(banner, 0); + for (int i = 0; i < strTitle.length; i++) { + sheet.addCell(new Label(i, 0, strTitle[i])); + } + for (int i = 0; i < strList.size(); i++) { + String[] str = strList.get(i); + for (int j = 0; j < str.length; j++) { + try { + Label label = new Label(j, i + 1, str[j]); + sheet.addCell(label); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + book.write(); + book.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return fp; + } + +} + + + + + + + diff --git a/src/com/util/MD5.java b/src/com/util/MD5.java new file mode 100644 index 0000000..ce7d22a --- /dev/null +++ b/src/com/util/MD5.java @@ -0,0 +1,65 @@ +package com.util; +import java.security.MessageDigest; +import java.util.Random; +/* +* MD5 加密类 +* 通过这个类把 +* 一个字符串转化成一个16进制32位的字符串 + * */ + +public final class MD5 { + + public final static String getMD5(String s) { + char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; // 创建一个16进制数的数组 + try { + byte[] strTemp = s.getBytes();// 把传入的字符串转化成数组 + MessageDigest mdTemp = MessageDigest.getInstance("MD5"); // 建立一个mdTemp + // 类的对象 + // 对象名称叫做MD5实例 + mdTemp.update(strTemp);// 更新strTemp 数组 + byte[] md = mdTemp.digest(); // 通过digest() 方法重新定义一个数组 + int j = md.length; // md数组的长度 + char str[] = new char[j * 2]; // 定义一个字符数组 数组的长度是md数组长度的2倍 + int k = 0; + for (int i = 0; i < j; i++) { + byte byte0 = md[i]; // 给byte0变量赋值 + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; // 通过hexDigits[] + // 把字符串s转化成16进制32位的字符串 + str[k++] = hexDigits[byte0 & 0xf]; + } + return new String(str); // 返回转换后的字符串 + } catch (Exception e) { + return null; + } + } + + // 返回MD5加盐加密数据 + public static String getMD5BySalt(String str, String salt) { + return getMD5(getMD5(str) + salt); + } + + // 生成一个10位的随机salt + public static String getSalt() { + String salt = ""; + Random rand = new Random(); + for (int i = 0; i < 10; i++) { + int num = rand.nextInt(3); + switch (num) { + case 0: + char c1 = (char) (rand.nextInt(26) + 'a');//生成随机小写字母 + salt += c1; + break; + case 1: + char c2 = (char) (rand.nextInt(26) + 'A');//生成随机大写字母 + salt += c2; + break; + case 2: + salt += rand.nextInt(10);//生成随机数字 + } + } + return salt; + } + +} + + diff --git a/src/com/util/PageHelper.java b/src/com/util/PageHelper.java new file mode 100644 index 0000000..194f7a1 --- /dev/null +++ b/src/com/util/PageHelper.java @@ -0,0 +1,211 @@ +package com.util; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +public class PageHelper { + + public static void getPage(List list, String name, List nameList, List valueList, int pageSize, String number, + HttpServletRequest request, String method) { + StringBuffer buffer = new StringBuffer(); + String name2 = name.substring(0, 1).toUpperCase() + name.substring(1); + String path = ""; + String action = "getAll" + name2 + ".action"; + if (method != null) { + action = "query" + name2 + "ByCond.action"; + } + + List objList = new ArrayList(); + if (nameList != null && valueList != null) { + for (int i = 0; i < nameList.size(); i++) { + path += "&" + nameList.get(i) + "=" + valueList.get(i); + } + } + int pageNumber = list.size(); + int maxPage = pageNumber; + if (maxPage % pageSize == 0) { + maxPage = maxPage / pageSize; + } else { + maxPage = maxPage / pageSize + 1; + } + if (number == null) { + number = "0"; + } + int start = Integer.parseInt(number) * pageSize; + int over = (Integer.parseInt(number) + 1) * pageSize; + int count = pageNumber - over; + if (count <= 0) { + over = pageNumber; + } + for (int i = start; i < over; i++) { + Object obj = list.get(i); + objList.add(obj); + } + buffer.append("  共为"); + buffer.append(maxPage); + buffer.append("页  共有"); + buffer.append(pageNumber); + buffer.append("条  当前为第"); + buffer.append((Integer.parseInt(number) + 1)); + buffer.append("页  "); + if ((Integer.parseInt(number) + 1) == 1) { + buffer.append("首页"); + } else { + buffer.append("首页"); + } + buffer.append("  "); + if ((Integer.parseInt(number) + 1) == 1) { + buffer.append("上一页"); + } else { + buffer.append("上一页"); + } + buffer.append("  "); + if (maxPage <= (Integer.parseInt(number) + 1)) { + buffer.append("下一页"); + } else { + buffer.append("下一页"); + } + buffer.append("  "); + if (maxPage <= (Integer.parseInt(number) + 1)) { + buffer.append("尾页"); + } else { + buffer.append("尾页"); + } + String html = buffer.toString(); + request.setAttribute("html", html); + request.setAttribute(name + "List", objList); + } + + public static void getUserPage(List list, String name, String actionName, int pageSize, String number, HttpServletRequest request) { + StringBuffer buffer = new StringBuffer(); + String path = ""; + String action = actionName + ".action"; + List objList = new ArrayList(); + int pageNumber = list.size(); + int maxPage = pageNumber; + if (maxPage % pageSize == 0) { + maxPage = maxPage / pageSize; + } else { + maxPage = maxPage / pageSize + 1; + } + if (number == null) { + number = "0"; + } + int start = Integer.parseInt(number) * pageSize; + int over = (Integer.parseInt(number) + 1) * pageSize; + int count = pageNumber - over; + if (count <= 0) { + over = pageNumber; + } + for (int i = start; i < over; i++) { + Object obj = list.get(i); + objList.add(obj); + } + buffer.append("  共为"); + buffer.append(maxPage); + buffer.append("页  共有"); + buffer.append(pageNumber); + buffer.append("条  当前为第"); + buffer.append((Integer.parseInt(number) + 1)); + buffer.append("页  "); + if ((Integer.parseInt(number) + 1) == 1) { + buffer.append("首页"); + } else { + buffer.append("首页"); + } + buffer.append("  "); + if ((Integer.parseInt(number) + 1) == 1) { + buffer.append("上一页"); + } else { + buffer.append("上一页"); + } + buffer.append("  "); + if (maxPage <= (Integer.parseInt(number) + 1)) { + buffer.append("下一页"); + } else { + buffer.append("下一页"); + } + buffer.append("  "); + if (maxPage <= (Integer.parseInt(number) + 1)) { + buffer.append("尾页"); + } else { + buffer.append("尾页"); + } + String html = buffer.toString(); + request.setAttribute("html", html); + request.setAttribute(name + "List", objList); + } + + public static void getIndexPage(List list, String name, String actionName, String id, int pageSize, String number, + HttpServletRequest request) { + StringBuffer buffer = new StringBuffer(); + String path = ""; + String action = actionName + ".action"; + if (!"".equals(id) && id != null) { + path = "&id=" + id + ""; + } + List objList = new ArrayList(); + int pageNumber = list.size(); + int maxPage = pageNumber; + if (maxPage % pageSize == 0) { + maxPage = maxPage / pageSize; + } else { + maxPage = maxPage / pageSize + 1; + } + if (number == null) { + number = "0"; + } + int start = Integer.parseInt(number) * pageSize; + int over = (Integer.parseInt(number) + 1) * pageSize; + int count = pageNumber - over; + if (count <= 0) { + over = pageNumber; + } + for (int i = start; i < over; i++) { + Object obj = list.get(i); + objList.add(obj); + } + buffer.append("  共为"); + buffer.append(maxPage); + buffer.append("页  共有"); + buffer.append(pageNumber); + buffer.append("条  当前为第"); + buffer.append((Integer.parseInt(number) + 1)); + buffer.append("页  "); + if ((Integer.parseInt(number) + 1) == 1) { + buffer.append("首页"); + } else { + buffer.append("首页"); + } + buffer.append("  "); + if ((Integer.parseInt(number) + 1) == 1) { + buffer.append("上一页"); + } else { + buffer.append("上一页"); + } + buffer.append("  "); + if (maxPage <= (Integer.parseInt(number) + 1)) { + buffer.append("下一页"); + } else { + buffer.append("下一页"); + } + buffer.append("  "); + if (maxPage <= (Integer.parseInt(number) + 1)) { + buffer.append("尾页"); + } else { + buffer.append("尾页"); + } + String html = buffer.toString(); + request.setAttribute("html", html); + request.setAttribute(name + "List", objList); + } + +} + + + + + + diff --git a/src/com/util/RandomValidateCode.java b/src/com/util/RandomValidateCode.java new file mode 100644 index 0000000..1de90f5 --- /dev/null +++ b/src/com/util/RandomValidateCode.java @@ -0,0 +1,113 @@ +package com.util; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.util.Random; + +import javax.imageio.ImageIO; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +public class RandomValidateCode { + public static final String RANDOMCODEKEY = "RANDOMVALIDATECODEKEY";// 放到session中的key + // private String randString = "0123456789";//随机产生只有数字的字符串 private String + private String randString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";// 随机产生只有字母的字符串 + // private String randString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生数字与字母组合的字符串 + private int width = 95;// 图片宽 + private int height = 25;// 图片高 + private int lineSize = 40;// 干扰线数量 + private int stringNum = 4;// 随机产生字符数量 + + private Random random = new Random(); + + /* + * 获得字体 + */ + private Font getFont() { + return new Font("Fixedsys", Font.CENTER_BASELINE, 18); + } + + /* + * 获得颜色 + */ + private Color getRandColor(int fc, int bc) { + if (fc > 255) + fc = 255; + if (bc > 255) + bc = 255; + int r = fc + random.nextInt(bc - fc - 16); + int g = fc + random.nextInt(bc - fc - 14); + int b = fc + random.nextInt(bc - fc - 18); + return new Color(r, g, b); + } + + /** + * 生成随机图片 + */ + public void getRandcode(HttpServletRequest request, HttpServletResponse response) { + HttpSession session = request.getSession(); + // BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类 + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); + Graphics g = image.getGraphics();// 产生Image对象的Graphics对象,改对象可以在图像上进行各种绘制操作 + g.fillRect(0, 0, width, height); + g.setFont(new Font("Times New Roman", Font.ROMAN_BASELINE, 18)); + g.setColor(getRandColor(110, 133)); + // 绘制干扰线 + for (int i = 0; i <= lineSize; i++) { + drowLine(g); + } + // 绘制随机字符 + String randomString = ""; + for (int i = 1; i <= stringNum; i++) { + randomString = drowString(g, randomString, i); + } + // 将生成的随机字符串保存到session中,而jsp界面通过session.getAttribute("RANDOMCODEKEY"), + // 获得生成的验证码,然后跟用户输入的进行比较 + session.removeAttribute(RANDOMCODEKEY); + session.setAttribute(RANDOMCODEKEY, randomString); + g.dispose(); + try { + // 将内存中的图片通过流动形式输出到客户端 + ImageIO.write(image, "JPEG", response.getOutputStream()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /* + * 绘制字符串 + */ + private String drowString(Graphics g, String randomString, int i) { + g.setFont(getFont()); + g.setColor(new Color(random.nextInt(101), random.nextInt(111), random.nextInt(121))); + String rand = String.valueOf(getRandomString(random.nextInt(randString.length()))); + randomString += rand; + g.translate(random.nextInt(3), random.nextInt(3)); + g.drawString(rand, 13 * i, 16); + return randomString; + } + + /* + * 绘制干扰线 + */ + private void drowLine(Graphics g) { + int x = random.nextInt(width); + int y = random.nextInt(height); + int xl = random.nextInt(13); + int yl = random.nextInt(15); + g.drawLine(x, y, x + xl, y + yl); + } + + /* + * 获取随机的字符 + */ + public String getRandomString(int num) { + return String.valueOf(randString.charAt(num)); + } +} + + + diff --git a/src/com/util/VeDate.java b/src/com/util/VeDate.java new file mode 100644 index 0000000..22f6007 --- /dev/null +++ b/src/com/util/VeDate.java @@ -0,0 +1,404 @@ +package com.util; + +import java.text.DecimalFormat; +import java.text.ParseException; +import java.text.ParsePosition; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.Random; +/* +* 日期工作类 +* 能够得到一些跟日期相关的应用、返回值 方便程序开发 + * */ + +public class VeDate { + + // 返回随机手机号码 + private static String[] telFirst = "130,131,132,133,134,135,136,137,138,139,150,151,152,157,158,159,180,181,182,183,184,185,186,187,188,189".split(","); + + public static String getTel() { + int index = getNum(0, telFirst.length - 1); + String first = telFirst[index]; + String second = String.valueOf(getNum(1, 188) + 10000).substring(1); + String third = String.valueOf(getNum(1, 9100) + 10000).substring(1); + return first + second + third; + } + + public static int getNum(int start, int end) { + return (int) (Math.random() * (end - start + 1) + start); + } + + public static double getDouble(double num) { + DecimalFormat df2 = new DecimalFormat("#.00"); + return Double.parseDouble(df2.format(num)); + } + + // 随机出三位整数 + public static int getRandom() { + int i = (int) (Math.random() * 900) + 10; + return i; + } + + public static String getStringDouble(double num) { + DecimalFormat df2 = new DecimalFormat("#.00"); + return df2.format(num); + } + + public static Date getNowDate() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(currentTime); + ParsePosition pos = new ParsePosition(8); + Date currentTime_2 = formatter.parse(dateString, pos); + return currentTime_2; + } + + public static Date getNowDateShort() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + String dateString = formatter.format(currentTime); + ParsePosition pos = new ParsePosition(8); + Date currentTime_2 = formatter.parse(dateString, pos); + return currentTime_2; + } + + public static String getStringDate() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(currentTime); + return dateString; + } + + public static String getStringDatex() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); + String dateString = formatter.format(currentTime); + return dateString; + } + + public static String getStringId() { + Random rand = new Random(); + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); + String dateString = formatter.format(currentTime); + return dateString + (rand.nextInt(900) + 100); + } + + public static String getStringDateShort() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + String dateString = formatter.format(currentTime); + return dateString; + } + + public static String getStringTimeShort() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); + String dateString = formatter.format(currentTime); + return dateString; + } + + public static String getYear() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy"); + String dateString = formatter.format(currentTime); + return dateString; + } + + public static String getTimeShort() { + SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); + Date currentTime = new Date(); + String dateString = formatter.format(currentTime); + return dateString; + } + + public static Date strToDateLong(String strDate) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + ParsePosition pos = new ParsePosition(0); + Date strtodate = formatter.parse(strDate, pos); + return strtodate; + } + + public static String dateToStrLong(java.util.Date dateDate) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(dateDate); + return dateString; + } + + public static String dateToStr(java.util.Date dateDate) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + String dateString = formatter.format(dateDate); + return dateString; + } + + public static Date strToDate(String strDate) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + ParsePosition pos = new ParsePosition(0); + Date strtodate = formatter.parse(strDate, pos); + return strtodate; + } + + public static Date getNow() { + Date currentTime = new Date(); + return currentTime; + } + + public static Date getLastDate(long day) { + Date date = new Date(); + long date_3_hm = date.getTime() - 3600000 * 34 * day; + Date date_3_hm_date = new Date(date_3_hm); + return date_3_hm_date; + } + + public static String getStringToday() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss"); + String dateString = formatter.format(currentTime); + return dateString; + } + + public static String getHour() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(currentTime); + String hour; + hour = dateString.substring(11, 13); + return hour; + } + + public static String getTime() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(currentTime); + String min; + min = dateString.substring(14, 16); + return min; + } + + public static String getUserDate(String sformat) { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat(sformat); + String dateString = formatter.format(currentTime); + return dateString; + } + + public static String getTwoHour(String st1, String st2) { + String[] kk = null; + String[] jj = null; + kk = st1.split(":"); + jj = st2.split(":"); + if (Integer.parseInt(kk[0]) < Integer.parseInt(jj[0])) + return "0"; + else { + double y = Double.parseDouble(kk[0]) + Double.parseDouble(kk[1]) / 60; + double u = Double.parseDouble(jj[0]) + Double.parseDouble(jj[1]) / 60; + if ((y - u) > 0) + return y - u + ""; + else + return "0"; + } + } + + public static String getTwoDay(String sj1, String sj2) { + SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); + long day = 0; + try { + java.util.Date date = myFormatter.parse(sj1); + java.util.Date mydate = myFormatter.parse(sj2); + day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000); + } catch (Exception e) { + return ""; + } + return day + ""; + } + + public static String getPreTime(String sj1, String jj) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String mydate1 = ""; + try { + Date date1 = format.parse(sj1); + long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60; + date1.setTime(Time * 1000); + mydate1 = format.format(date1); + } catch (Exception e) { + } + return mydate1; + } + + public static String getNextDay(String nowdate, String delay) { + try { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + String mdate = ""; + Date d = strToDate(nowdate); + long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24 * 60 * 60; + d.setTime(myTime * 1000); + mdate = format.format(d); + return mdate; + } catch (Exception e) { + return ""; + } + } + + public static boolean isLeapYear(String ddate) { + Date d = strToDate(ddate); + GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance(); + gc.setTime(d); + int year = gc.get(Calendar.YEAR); + if ((year % 400) == 0) + return true; + else if ((year % 4) == 0) { + if ((year % 100) == 0) + return false; + else + return true; + } else + return false; + } + + public static String getEDate(String str) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + ParsePosition pos = new ParsePosition(0); + Date strtodate = formatter.parse(str, pos); + String j = strtodate.toString(); + String[] k = j.split(" "); + return k[2] + k[1].toUpperCase() + k[5].substring(2, 4); + } + + public static String getEndDateOfMonth(String dat) {// yyyy-MM-dd + String str = dat.substring(0, 8); + String month = dat.substring(5, 7); + int mon = Integer.parseInt(month); + if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) { + str += "31"; + } else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) { + str += "30"; + } else { + if (isLeapYear(dat)) { + str += "29"; + } else { + str += "28"; + } + } + return str; + } + + public static boolean isSameWeekDates(Date date1, Date date2) { + Calendar cal1 = Calendar.getInstance(); + Calendar cal2 = Calendar.getInstance(); + cal1.setTime(date1); + cal2.setTime(date2); + int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR); + if (0 == subYear) { + if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR)) + return true; + } else if (1 == subYear && 11 == cal2.get(Calendar.MONTH)) { + if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR)) + return true; + } else if (-1 == subYear && 11 == cal1.get(Calendar.MONTH)) { + if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR)) + return true; + } + return false; + } + + public static String getSeqWeek() { + Calendar c = Calendar.getInstance(Locale.CHINA); + String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR)); + if (week.length() == 1) + week = "0" + week; + String year = Integer.toString(c.get(Calendar.YEAR)); + return year + week; + } + + public static String getWeek(String sdate, String num) { + Date dd = VeDate.strToDate(sdate); + Calendar c = Calendar.getInstance(); + c.setTime(dd); + if (num.equals("1")) + c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); + else if (num.equals("2")) + c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); + else if (num.equals("3")) + c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY); + else if (num.equals("4")) + c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY); + else if (num.equals("5")) + c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); + else if (num.equals("6")) + c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); + else if (num.equals("0")) + c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); + return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); + } + + public static String getWeek(String sdate) { + Date date = VeDate.strToDate(sdate); + Calendar c = Calendar.getInstance(); + c.setTime(date); + return new SimpleDateFormat("EEEE").format(c.getTime()); + } + + public static long getDays(String date1, String date2) { + if (date1 == null || date1.equals("")) + return 0; + if (date2 == null || date2.equals("")) + return 0; + SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); + java.util.Date date = null; + java.util.Date mydate = null; + try { + date = myFormatter.parse(date1); + mydate = myFormatter.parse(date2); + } catch (Exception e) { + } + long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000); + return day; + } + + public static String getNowMonth(String sdate) { + sdate = sdate.substring(0, 8) + "01"; + Date date = VeDate.strToDate(sdate); + Calendar c = Calendar.getInstance(); + c.setTime(date); + int u = c.get(Calendar.DAY_OF_WEEK); + String newday = VeDate.getNextDay(sdate, (1 - u) + ""); + return newday; + } + + public static String getNo(int k) { + return getUserDate("yyyyMMddhhmmss") + getRandom(k); + } + + public static String getRandom(int i) { + Random jjj = new Random(); + if (i == 0) + return ""; + String jj = ""; + for (int k = 0; k < i; k++) { + jj = jj + jjj.nextInt(9); + } + return jj; + } + + public static boolean RightDate(String date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + if (date == null) + return false; + if (date.length() > 10) { + sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + } else { + sdf = new SimpleDateFormat("yyyy-MM-dd"); + } + try { + sdf.parse(date); + } catch (ParseException pe) { + return false; + } + return true; + } +} + + diff --git a/src/log4j.properties b/src/log4j.properties new file mode 100644 index 0000000..7871fdb --- /dev/null +++ b/src/log4j.properties @@ -0,0 +1,23 @@ +log4j.rootLogger=INFO, stdout, logfile + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n + +log4j.appender.logfile=org.apache.log4j.RollingFileAppender +log4j.appender.logfile.MaxFileSize=512KB +log4j.appender.logfile.MaxBackupIndex=3 +log4j.appender.logfile.layout=org.apache.log4j.PatternLayout +log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n +log4j.logger.java.sql.ResultSet=INFO + +log4j.logger.org.apache=INFO +log4j.logger.java.sql.Connection=DEBUG +log4j.logger.java.sql.Statement=DEBUG +log4j.logger.java.sql.PreparedStatement=DEBUG +log4j.logger.com.dao=DEBUG + +#log4j 文件的作用是在控制台输出程序启动、SQL语句等程序运行时关键代码 + + + diff --git a/src/mapper/admin.xml b/src/mapper/admin.xml new file mode 100644 index 0000000..cc22ab2 --- /dev/null +++ b/src/mapper/admin.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + insert into admin(adminid , username , password , realname , contact , addtime ) values(#{adminid} , #{username} , #{password} , #{realname} , #{contact} , #{addtime} ) + + + + + update admin set username=#{username} , password=#{password} , realname=#{realname} , contact=#{contact} , addtime=#{addtime} where adminid=#{adminid} + + + + + delete from admin where adminid = #{adminid} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapper/article.xml b/src/mapper/article.xml new file mode 100644 index 0000000..6446de7 --- /dev/null +++ b/src/mapper/article.xml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + insert into article(articleid , title , bannerid , image , istop , isflv , contents , addtime , hits ) + values(#{articleid} , #{title} , #{bannerid} , #{image} , + #{istop} , #{isflv} , #{contents} , #{addtime} , #{hits} ) + + + + update article set title=#{title} , bannerid=#{bannerid} , image=#{image} , istop=#{istop} , isflv=#{isflv} , + contents=#{contents} , addtime=#{addtime} , + hits=#{hits} where articleid=#{articleid} + + + + delete from article where articleid = #{articleid} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapper/asks.xml b/src/mapper/asks.xml new file mode 100644 index 0000000..ce7aa12 --- /dev/null +++ b/src/mapper/asks.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + insert into asks(asksid , question , addtime , memo ) values(#{asksid} , #{question} , #{addtime} , #{memo} ) + + + + + update asks set question=#{question} , addtime=#{addtime} , memo=#{memo} where asksid=#{asksid} + + + + + delete from asks where asksid = #{asksid} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapper/banner.xml b/src/mapper/banner.xml new file mode 100644 index 0000000..914d6a3 --- /dev/null +++ b/src/mapper/banner.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + insert into banner(bannerid , bannername , addtime , memo ) values(#{bannerid} , #{bannername} , #{addtime} , + #{memo} ) + + + + update banner set bannername=#{bannername} , addtime=#{addtime} , memo=#{memo} where bannerid=#{bannerid} + + + + delete from banner where bannerid = #{bannerid} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapper/complains.xml b/src/mapper/complains.xml new file mode 100644 index 0000000..00bfddc --- /dev/null +++ b/src/mapper/complains.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + insert into complains(complainsid , usersid , title , contents , addtime , status , reps ) values(#{complainsid} , #{usersid} , #{title} , #{contents} , #{addtime} , #{status} , #{reps} ) + + + + + update complains set usersid=#{usersid} , title=#{title} , contents=#{contents} , addtime=#{addtime} , status=#{status} , reps=#{reps} where complainsid=#{complainsid} + + + + + delete from complains where complainsid = #{complainsid} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapper/fav.xml b/src/mapper/fav.xml new file mode 100644 index 0000000..1866fc4 --- /dev/null +++ b/src/mapper/fav.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + insert into fav(favid , usersid , articleid , addtime ) values(#{favid} , #{usersid} , #{articleid} , #{addtime} ) + + + + + update fav set usersid=#{usersid} , articleid=#{articleid} , addtime=#{addtime} where favid=#{favid} + + + + + delete from fav where favid = #{favid} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapper/topic.xml b/src/mapper/topic.xml new file mode 100644 index 0000000..d1f0124 --- /dev/null +++ b/src/mapper/topic.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + insert into topic(topicid , usersid , articleid , contents , addtime ) values(#{topicid} , #{usersid} , #{articleid} , #{contents} , #{addtime} ) + + + + + update topic set usersid=#{usersid} , articleid=#{articleid} , contents=#{contents} , addtime=#{addtime} where topicid=#{topicid} + + + + + delete from topic where topicid = #{topicid} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapper/users.xml b/src/mapper/users.xml new file mode 100644 index 0000000..2a369a6 --- /dev/null +++ b/src/mapper/users.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + insert into users(usersid , username , password , realname , sex , birthday , contact , regdate , asksid , answer + ) values(#{usersid} , #{username} , #{password} , #{realname} , + #{sex} , #{birthday} , #{contact} , #{regdate}, #{asksid} , #{answer} ) + + + + + update users set username=#{username} , password=#{password} , realname=#{realname} , sex=#{sex} , + birthday=#{birthday} , contact=#{contact} , regdate=#{regdate} where usersid=#{usersid} + + + + + delete from users where usersid = #{usersid} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mybatis.xml b/src/mybatis.xml new file mode 100644 index 0000000..8b0b349 --- /dev/null +++ b/src/mybatis.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/springmvc-servlet.xml b/src/springmvc-servlet.xml new file mode 100644 index 0000000..0f62616 --- /dev/null +++ b/src/springmvc-servlet.xml @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + mysql + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +