作者主页:源码空间站2022
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
管理员角色包含以下功能:
管理员登陆,用户管理,新闻管理,留言列表查看等功能。
用户角色包含以下功能:
查看所有新闻,市场资讯查看,科技推广查看,致富经栏目查看,网站留言,用户注册登陆等功能。
由于本程序规模不大,可供课程设计,毕业设计学习演示之用
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
技术栈
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:HTML+CSS+JavaScript+jsp
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
运行截图
代码相关
前台留言
@Controller("frontMessageController")
@RequestMapping("/")
public class MessagesAction {
@Autowired
private MessageService messageService;
@Autowired
private FrontCache frontCache;
@RequestMapping("message")
public String message() {
return "/front/message/message";
}
/**
* 前台留言
*
* @param e
* @param model
* @return
* @throws Exception
*/
@RequestMapping("message/leaveMessage")
@ResponseBody
public String leaveMessage(Messages e, ModelMap model) throws Exception {
messageService.insert(e);
frontCache.loadMessage();
return "ok";
}
@RequestMapping("checkVcode")
@ResponseBody
public String checkVcode(@ModelAttribute("e") Messages e, HttpServletResponse response) throws IOException {
String vcode = RequestHolder.getSession().getAttribute("validateCode").toString();
if(StringUtils.isNotBlank(vcode)&&!(vcode.toLowerCase()).equals(e.getVcode().toLowerCase())){
return "{\"error\":\"验证码不正确!\"}";
}
return null;
}
}
服务领域
@Controller("serviceActionController")
@RequestMapping("/")
public class ServiceAction {
/**
* 跳转到“服务领域”
* @return
* @throws Exception
*/
@RequestMapping("service")
public String service() throws Exception {
return "/front/service/serviceList";
}
@RequestMapping("service/{id}")
public String selectOne(HttpServletRequest request, @ModelAttribute("id")@PathVariable("id") String id, @ModelAttribute("e") Service service) throws Exception {
request.setAttribute("id", id);
return "/front/service/serviceList";
}
}
文章管理控制器
@Controller("frontArticleController")
@RequestMapping("/")
public class ArticleAction extends BaseController<Article>{
private static final String page_toList = "/front/article/articleList";
private static final String page_toEdit = "/front/article/articleInfo";
@Autowired
private ArticleService articleService;
@Override
public Services<Article> getService() {
return articleService;
}
public ArticleAction(){
super.page_toList = page_toList;
super.page_toEdit = page_toEdit;
}
/**
* 跳转到文章列表
* @param request
* @param article
* @return
* @throws Exception
*/
@RequestMapping("article")
public String article(HttpServletRequest request, @ModelAttribute("e") Article article) throws Exception {
this.initPageSelect();
setParamWhenInitQuery(article);
int offset = 0;
if(request.getParameter("pager.offset")!=null){
offset = Integer.parseInt(request.getParameter("pager.offset"));
}
if(offset < 0){
offset=0;
}
article.setOffset(offset);
PageModel page = getService().selectPageList(article);
if(page == null){
page = new PageModel();
}
page.setPageSize(10); //设置单页数据为10
page.setPagerSize((page.getTotal() + page.getPageSize() - 1)
/ page.getPageSize());
selectListAfter(page);
page.setPagerUrl("article");
request.setAttribute("pager", page);
return page_toList;
}
/**
* 文章详情
* @param code
* @param model
* @return
* @throws Exception
*/
@RequestMapping("article/{code}")
public String selectOne(HttpServletRequest request,@ModelAttribute("code")@PathVariable("code") String code,@ModelAttribute("e") Article article, ModelMap model) throws Exception {
if(isInteger(code)) { //如果是数字 则为id 按id进行文章查询
Article e = articleService.selectById(Integer.parseInt(code));
e.setHit(String.valueOf(Integer.parseInt(e.getHit())+1));
articleService.update(e); //更新浏览量 --优化建议:可使用缓存或者redis暂存 然后再刷入数据库
Article next = articleService.selectNext(Integer.parseInt(code));
if(next==null){
next = new Article();
}
Article previous = articleService.selectPrevious(Integer.parseInt(code));
if(previous==null){
previous = new Article();
}
model.addAttribute("e", e);
model.addAttribute("next", next);
model.addAttribute("previous", previous);
return page_toEdit;
}else{//不是数字,则为分类编码
for(ArticleCategory item: SystemManage.getInstance().getArticleCategory()){ //遍历分类缓存
if(code.equals(item.getCode())){ //当编码相等时
article.setCategoryId(String.valueOf(item.getId())); //把相等编码里的分类id值赋予文章中catagroyId中
break; //跳出循环
}
}
setParamWhenInitQuery(article);
int offset = 0;
if(request.getParameter("pager.offset")!=null){
offset = Integer.parseInt(request.getParameter("pager.offset"));
}
if(offset < 0){
offset=0;
}
article.setOffset(offset);
PageModel page = getService().selectPageList(article);
if(page == null){
page = new PageModel();
}
page.setPageSize(10); //设置单页数据为10
page.setPagerSize((page.getTotal() + page.getPageSize() - 1)
/ page.getPageSize());
selectListAfter(page);
page.setPagerUrl(code);
request.setAttribute("pager", page);
request.setAttribute("code", code);
return page_toList;
}
}
/**
*判断是不是数字
* @param code
* @return
*/
public static boolean isInteger(String code){
try {
Integer.parseInt(code);
return true;
}catch (NumberFormatException e){
return false;
}
}
}
文章分类管理控制器
@Controller
@RequestMapping("/manage/articleCategory/")
public class ArticleCategoryAction extends BaseController<ArticleCategory>{
private static final String page_toList = "/manage/articleCategory/articleCategoryList";
private static final String page_toEdit = "/manage/articleCategory/articleCategoryEdit";
private static final String page_toAdd = "/manage/articleCategory/articleCategoryEdit";
@Autowired
private ArticleCategoryService articleCategoryService;
@Autowired
private FrontCache frontCache;
@Override
public Services<ArticleCategory> getService() {
return articleCategoryService;
}
public ArticleCategoryAction(){
super.page_toList = page_toList;
super.page_toEdit = page_toEdit;
super.page_toAdd = page_toAdd;
}
@Override
public String insert(HttpServletRequest request, @ModelAttribute("e") ArticleCategory articleCategory, RedirectAttributes flushAttrs) throws Exception {
articleCategoryService.insert(articleCategory);
insertAfter(articleCategory);
addMessage(flushAttrs,"操作成功!");
frontCache.loadArticleCategroy();//加载缓存
return "redirect:selectList";
}
@Override
public String update(HttpServletRequest request, @ModelAttribute("e") ArticleCategory articleCategory, RedirectAttributes flushAttrs) throws Exception {
articleCategoryService.update(articleCategory);
insertAfter(articleCategory);
addMessage(flushAttrs, "操作成功!");
frontCache.loadArticleCategroy();//加载缓存
return "redirect:selectList";
}
@RequestMapping("delete")
public String delete(HttpServletRequest request, @ModelAttribute("e") ArticleCategory articleCategory, RedirectAttributes flushAttrs) throws Exception{
articleCategoryService.delete(articleCategory);
insertAfter(articleCategory);
addMessage(flushAttrs, "操作成功!");
frontCache.loadArticleCategroy();//加载缓存
return "redirect:selectList";
}
@RequestMapping("unique")
@ResponseBody
public String unique(@ModelAttribute("e") ArticleCategory e,HttpServletResponse response) throws IOException {
response.setCharacterEncoding("utf-8");//设置响应编码为utf-8
if(StringUtils.isNotBlank(e.getCatename())){
ArticleCategory articleCategory = new ArticleCategory();
articleCategory.setCatename(e.getCatename());
articleCategory = articleCategoryService.selectOne(articleCategory);
if(articleCategory==null){
return "{}";
}else{
if(e.getId()!=0 && e.getId()==articleCategory.getId()){
return "{}";
}else {
return "{\"error\":\"分类名称已经存在!\"}";
}
}
}else if(StringUtils.isNotBlank(e.getCode())){
ArticleCategory articleCategory = new ArticleCategory();
articleCategory.setCode(e.getCode());
articleCategory = articleCategoryService.selectOne(articleCategory);
if(articleCategory==null){
return "{}";
}else{
if(e.getId()!=0 && e.getId()==articleCategory.getId()){
return "{}";
}else {
return "{\"error\":\"编码已经存在!\"}";
}
}
}
return null;
}
}
如果也想学习本系统,下面领取。关注并回复:104ssm