基于javaweb+mysql的ssm新闻发布管理系统(java+ssm+jsp+bootstrap+jquery+mysql)

基于javaweb+mysql的ssm新闻发布管理系统(java+ssm+jsp+bootstrap+jquery+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SSM新闻发布管理系统(java+ssm+jsp+bootstrap+jquery+mysql)

项目介绍

本项目分为前后台,分为管理员与普通用户角色,前台为普通用户登录,后台为管理员登录;

用户角色包含以下功能: 新闻搜索,查看新闻,用户首页,评论新闻等功能。

管理员角色包含以下功能: 分类管理,新闻管理,管理员登录,评论管理等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;

技术栈

  1. 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jquery+bootstrap

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中config/db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入http://localhost:8080/News 登录
	/**
	 * 菜单修改
	 * @param menu
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> edit(Menu menu){
		Map<String, String> ret = new HashMap<String, String>();
		if(menu == null){
			ret.put("type", "error");
			ret.put("msg", "请选择正确的菜单信息!");
			return ret;
		}
		if(StringUtils.isEmpty(menu.getName())){
			ret.put("type", "error");
			ret.put("msg", "请填写菜单名称!");
			return ret;
		}
		if(StringUtils.isEmpty(menu.getIcon())){
			ret.put("type", "error");
			ret.put("msg", "请填写菜单图标类!");
			return ret;
		}
		if(menu.getParentId() == null){
			menu.setParentId(0l);
		}
		if(menuService.edit(menu) <= 0){
			ret.put("type", "error");
			ret.put("msg", "修改失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "修改成功!");
		return ret;
	}
	
	/**
	 * 删除菜单信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> delete(
			@RequestParam(name="id",required=true) Long id
			){
		Map<String, String> ret = new HashMap<String, String>();
		if(id == null){
			ret.put("type", "error");
		}
		if(user.getRoleId() == null){
			ret.put("type", "error");
			ret.put("msg", "请选择所属角色!");
			return ret;
		}
		if(isExist(user.getUsername(), 0l)){
			ret.put("type", "error");
			ret.put("msg", "该用户名已经存在,请重新输入!");
			return ret;
		}
		if(userService.add(user) <= 0){
			ret.put("type", "error");
			ret.put("msg", "用户添加失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "角色添加成功!");
		return ret;
	}
	
	/**
	 * 编辑用户
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> edit(User user){
		Map<String, String> ret = new HashMap<String, String>();
		if(user == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的用户信息!");
			return ret;
		}
		if(StringUtils.isEmpty(user.getUsername())){
			ret.put("type", "error");
			ret.put("msg", "请填写用户名!");
			return ret;
		}
//		if(StringUtils.isEmpty(user.getPassword())){
//			ret.put("type", "error");
//			ret.put("msg", "请填写密码!");
//			return ret;
//		}
		if(user.getRoleId() == null){
			ret.put("type", "error");
			ret.put("msg", "请选择所属角色!");
			return ret;
		}
		return ret;
	} 
	
	/**
	 * 本系统所有的验证码均采用此方法
	 * @param vcodeLen
	 * @param width
	 * @param height
	 * @param cpachaType:用来区别验证码的类型,传入字符串
	 * @param request
	 * @param response
	 */
	@RequestMapping(value="/get_cpacha",method=RequestMethod.GET)
	public void generateCpacha(
			@RequestParam(name="vl",required=false,defaultValue="4") Integer vcodeLen,
			@RequestParam(name="w",required=false,defaultValue="100") Integer width,
			@RequestParam(name="h",required=false,defaultValue="30") Integer height,
			@RequestParam(name="type",required=true,defaultValue="loginCpacha") String cpachaType,
			HttpServletRequest request,
			HttpServletResponse response){
		CpachaUtil cpachaUtil = new CpachaUtil(vcodeLen, width, height);
		String generatorVCode = cpachaUtil.generatorVCode();
		request.getSession().setAttribute(cpachaType, generatorVCode);
		BufferedImage generatorRotateVCodeImage = cpachaUtil.generatorRotateVCodeImage(generatorVCode, true);
		try {
			ImageIO.write(generatorRotateVCodeImage, "gif", response.getOutputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
package com.yuanma.programmer.controller.admin;

		if(user == null)return false;
		if(user.getId().longValue() == id.longValue())return false;
		return true;
	}
}
package com.yuanma.programmer.controller.home;

/**
 * 前台页面首页控制器
 *
 */
@RequestMapping("/index")
@Controller
public class IndexController {
	
			ret.put("msg", "请选择jpg,jpeg,gif,png格式的图片!");
			return ret;
		}
		String savePath = request.getServletContext().getRealPath("/")
				+ "/resources/upload/";
		File savePathFile = new File(savePath);
		if (!savePathFile.exists()) {
			// 若不存在改目录,则创建目录
			savePathFile.mkdir();
		}
		String filename = new Date().getTime() + "." + suffix;
		try {
			// 将文件保存至指定目录
			photo.transferTo(new File(savePath + filename));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			ret.put("type", "error");
			ret.put("msg", "保存文件异常!");
			e.printStackTrace();
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "用户上传图片成功!");
		ret.put("filepath", request.getServletContext().getContextPath()
				+ "/resources/upload/" + filename);
		return ret;
	}
	
	
	/**
	 * 去除敏感信息
	 * @param news
	 * @return
	 */

	public static News minganInfo(News news) {
		
		// 去除敏感标题
		if (SensitiveWord.checkSenstiveWord(news.getTitle())) {
			news.setTitle(SensitiveWord.filterInfoAfter(news.getTitle()));
		}

		// 去除敏感正文
		if (SensitiveWord.checkSenstiveWord(news.getContent())) {
			news.setContent(SensitiveWord.filterInfoAfter(news.getContent()));
		}
		// 去除敏感摘要
		if (SensitiveWord.checkSenstiveWord(news.getAbstrs())) {
	/**
	 * 删除新闻评论
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, String> delete(String ids) {
		Map<String, String> ret = new HashMap<String, String>();
		if (ids == null) {
			ret.put("type", "error");
			ret.put("msg", "请选择要删除的评论信息!");
			return ret;
		}
		if (ids.contains(",")) {
			ids = ids.substring(0, ids.length() - 1);
		}
		if (commentService.delete(ids) <= 0) {
			ret.put("type", "error");
			ret.put("msg", "评论删除失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "删除成功!");
		return ret;
	}

	/**
	 * 分页模糊搜索查询列表
	 * 
	 * @param name
	 * @param page
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getList(
			@RequestParam(name = "nickname", required = false, defaultValue = "") String nickname,
			@RequestParam(name = "content", required = false, defaultValue = "") String content,
			Page page) {
		Map<String, Object> ret = new HashMap<String, Object>();
			ret.put("msg", "新闻标签不能为空!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getPhoto())) {
			ret.put("type", "error");
			ret.put("msg", "新闻封面图片必须上传!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getAuthor())) {
			ret.put("type", "error");
			ret.put("msg", "新闻作者不能为空!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getContent())) {
			ret.put("type", "error");
			ret.put("msg", "新闻内容不能为空!");
			return ret;
		}
		if (newsService.edit(news) <= 0) {
			ret.put("type", "error");
			ret.put("msg", "修改失败,请联系管理员!");
			return ret;
		}
		

		// 去除敏感信息
		NewsController.minganInfo(news);
		
		ret.put("type", "success");
		ret.put("msg", "修改成功!");
		return ret;
	}

	/**
	 * 删除新闻
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, String> delete(Long id) {
		Map<String, String> ret = new HashMap<String, String>();
		if (id == null) {
			ret.put("type", "error");
			ret.put("msg", "请选择要删除的信息!");
			return ret;
		}
		try {
			if (newsService.delete(id) <= 0) {
				ret.put("type", "error");
			ret.put("msg", "请选择要评论的新闻!");
			return ret;
		}
		if (StringUtils.isEmpty(comment.getNickname())) {
			ret.put("type", "error");
			ret.put("msg", "评论昵称不能为空!");
			return ret;
		}
		if (StringUtils.isEmpty(comment.getContent())) {
			ret.put("type", "error");
			ret.put("msg", "评论内容不能为空!");
			return ret;
		}
		comment.setCreateTime(new Date());
		if (commentService.add(comment) <= 0) {
			ret.put("type", "error");
			ret.put("msg", "评论添加失败,请联系管理员!");
			return ret;
		}

		ret.put("type", "success");
		ret.put("msg", "添加成功!");
		// 新闻评论数量加1
		newsService.updateCommentNumber(comment.getNewsId());
		return ret;
	}

	/**
	 * 新闻评论信息编辑
	 * 
	 * @param newsCategory
	 * @return
	 */
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, String> edit(Comment comment) {
		// 去除敏感信息
		CommentController.minganInfo(comment);
		Map<String, String> ret = new HashMap<String, String>();
		if (comment == null) {
			ret.put("type", "error");
			ret.put("msg", "请填写正确的评论信息!");
			return ret;
		}
		if (comment.getNewsId() == null) {
			ret.put("type", "error");
			ret.put("msg", "请选择要评论的新闻!");
			return ret;
		}
		if (StringUtils.isEmpty(comment.getNickname())) {
			ret.put("type", "error");
			ret.put("msg", "评论昵称不能为空!");
	public Map<String, String> delete(String ids) {
		Map<String, String> ret = new HashMap<String, String>();
		if (ids == null) {
			ret.put("type", "error");
			ret.put("msg", "请选择要删除的评论信息!");
			return ret;
		}
		if (ids.contains(",")) {
			ids = ids.substring(0, ids.length() - 1);
		}
		if (commentService.delete(ids) <= 0) {
			ret.put("type", "error");
			ret.put("msg", "评论删除失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "删除成功!");
		return ret;
	}

	/**
	 * 分页模糊搜索查询列表
	 * 
	 * @param name
	 * @param page
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getList(
			@RequestParam(name = "nickname", required = false, defaultValue = "") String nickname,
			@RequestParam(name = "content", required = false, defaultValue = "") String content,
			Page page) {
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("nickname", nickname);
		queryMap.put("content", content);
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		ret.put("rows", commentService.findList(queryMap));
		ret.put("total", commentService.getTotal(queryMap));
		return ret;
	}

	/**
	 * 去除敏感信息

/**
 * 日志管理控制器
 *
 */
@RequestMapping("/admin/log")
@Controller
public class LogController {
	@Autowired
	private LogService logService;
	
	/**
	 * 日志列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public ModelAndView list(ModelAndView model){
		model.setViewName("log/list");
		return model;
	}
	
	/**
	 * 获取日志列表
	 * @param page
	 * @param content
	 * @param roleId
	 * @param sex
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getList(Page page,
			@RequestParam(name="content",required=false,defaultValue="") String content

/**
 * 新闻控制器
 * 
 *
 */
@RequestMapping("/admin/news")
@Controller
public class NewsController {

	@Autowired
	private NewsCategoryService newsCategoryService;

	@Autowired
	private NewsService newsService;

	/**
	 * 新闻列表页面
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ModelAndView list(ModelAndView model) {
		model.addObject("newsCategoryList", newsCategoryService.findAll());
			ret.put("msg", "新闻标题不能为空!");
			return ret;
		}
		if (news.getCategoryId() == null) {
			ret.put("type", "error");
			ret.put("msg", "请选择新闻分类!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getAbstrs())) {
			ret.put("type", "error");
			ret.put("msg", "新闻摘要不能为空!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getTags())) {
			ret.put("type", "error");
			ret.put("msg", "新闻标签不能为空!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getPhoto())) {
			ret.put("type", "error");
			ret.put("msg", "新闻封面图片必须上传!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getAuthor())) {
			ret.put("type", "error");
			ret.put("msg", "新闻作者不能为空!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getContent())) {
			ret.put("type", "error");
			ret.put("msg", "新闻内容不能为空!");
			return ret;
		}
		if (newsService.edit(news) <= 0) {
			ret.put("type", "error");
			ret.put("msg", "修改失败,请联系管理员!");
			return ret;
		}
		

		// 去除敏感信息
		NewsController.minganInfo(news);
			ret.put("type", "error");
			ret.put("msg", "分类名称不能为空!");
			return ret;
		}
		if(newsCategoryService.add(newsCategory) <= 0){
			ret.put("type", "error");
			ret.put("msg", "分类添加失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "添加成功!");
		return ret;
	}
	
	/**
	 * 新闻分类信息编辑
	 * @param newsCategory
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,String> edit(NewsCategory newsCategory){
		Map<String,String> ret = new HashMap<String, String>();
		if(newsCategory == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的分类信息!");
			return ret;
		}
		if(StringUtils.isEmpty(newsCategory.getName())){
			ret.put("type", "error");
			ret.put("msg", "分类名称不能为空!");
			return ret;
		}
		if(newsCategoryService.edit(newsCategory) <= 0){
			ret.put("type", "error");
			ret.put("msg", "分类修改失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "修改成功!");
		return ret;
	}
			Authority authority = new Authority();
			authority.setMenuId(Long.valueOf(id));
			authority.setRoleId(roleId);
			authorityService.add(authority);
		}
		ret.put("type", "success");
		ret.put("msg", "权限编辑成功!");
		return ret;
	}
	
	/**
	 * 获取某个角色的所有权限
	 * @param roleId
	 * @return
	 */
	@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
	@ResponseBody
	public List<Authority> getRoleAuthority(
			@RequestParam(name="roleId",required=true) Long roleId
		){
		return authorityService.findListByRoleId(roleId);
	}
}
package com.yuanma.programmer.controller.admin;

/**
 * 新闻评论控制器
	@Autowired
	private NewsService newsService;
	
	@Autowired
	private CommentService commentService;
	
	
	/**
	 * 查看新闻详情
	 * @param model
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/detail",method=RequestMethod.GET)
	public ModelAndView detail(ModelAndView model,Long id){
		model.addObject("newsCategoryList", newsCategoryService.findAll());
		News news = newsService.find(id);
		model.addObject("news", news);
		model.addObject("title", news.getTitle());
		model.addObject("tags", news.getTags().split(","));
		model.setViewName("home/news/detail");
		//查看数加1
		newsService.updateViewNumber(id);
		return model;
	}
	
	/**
	 * 按照分类显示新闻列表
	 * @param model
	 * @param cid
	 * @return
	 */
	@RequestMapping(value="/category_list",method=RequestMethod.GET)
	public ModelAndView categoryList(ModelAndView model,
			@RequestParam(name="cid",required=true) Long cid,
			Page page
			){
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("offset", 0);
		queryMap.put("pageSize", 10);
		News news = newsService.find(id);
		model.addObject("news", news);
		model.addObject("title", news.getTitle());
		model.addObject("tags", news.getTags().split(","));
		model.setViewName("home/news/detail");
		//查看数加1
		newsService.updateViewNumber(id);
		return model;
	}
	
	/**
	 * 按照分类显示新闻列表
	 * @param model
	 * @param cid
	 * @return
	 */
	@RequestMapping(value="/category_list",method=RequestMethod.GET)
	public ModelAndView categoryList(ModelAndView model,
			@RequestParam(name="cid",required=true) Long cid,
			Page page
			){
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("offset", 0);
		queryMap.put("pageSize", 10);
		queryMap.put("categoryId", cid);
		model.addObject("newsCategoryList", newsCategoryService.findAll());
		model.addObject("newsList", newsService.findList(queryMap));
		NewsCategory newsCategory = newsCategoryService.find(cid);
		model.addObject("newsCategory", newsCategory);
		model.addObject("title", newsCategory.getName() + "分类下的新闻信息");
		model.setViewName("home/news/category_list");
		return model;
	}
	
	/**
	 * 获取按评论数排序的最新n条信息
	 * @return
	 */
	@RequestMapping(value="/last_comment_list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> lastCommentList(){
		Map<String, Object> ret = new HashMap<String, Object>();
		ret.put("type", "success");
		ret.put("newsList", newsService.findLastCommentList(5));
		return ret;
	}
			@RequestParam(name="vl",required=false,defaultValue="4") Integer vcodeLen,
			@RequestParam(name="w",required=false,defaultValue="100") Integer width,
			@RequestParam(name="h",required=false,defaultValue="30") Integer height,
			@RequestParam(name="type",required=true,defaultValue="loginCpacha") String cpachaType,
			HttpServletRequest request,
			HttpServletResponse response){
		CpachaUtil cpachaUtil = new CpachaUtil(vcodeLen, width, height);
		String generatorVCode = cpachaUtil.generatorVCode();
		request.getSession().setAttribute(cpachaType, generatorVCode);
		BufferedImage generatorRotateVCodeImage = cpachaUtil.generatorRotateVCodeImage(generatorVCode, true);
		try {
			ImageIO.write(generatorRotateVCodeImage, "gif", response.getOutputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
package com.yuanma.programmer.controller.admin;

/**
	public Map<String, String> edit(Menu menu){
		Map<String, String> ret = new HashMap<String, String>();
		if(menu == null){
			ret.put("type", "error");
			ret.put("msg", "请选择正确的菜单信息!");
			return ret;
		}
		if(StringUtils.isEmpty(menu.getName())){
			ret.put("type", "error");
			ret.put("msg", "请填写菜单名称!");
			return ret;
		}
		if(StringUtils.isEmpty(menu.getIcon())){
			ret.put("type", "error");
			ret.put("msg", "请填写菜单图标类!");
			return ret;
		}
		if(menu.getParentId() == null){
			menu.setParentId(0l);
		}
		if(menuService.edit(menu) <= 0){
			ret.put("type", "error");
			ret.put("msg", "修改失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "修改成功!");
		return ret;
	}
	
	/**
	 * 删除菜单信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> delete(
			@RequestParam(name="id",required=true) Long id
			){
		Map<String, String> ret = new HashMap<String, String>();
		if(id == null){
			ret.put("type", "error");
			ret.put("msg", "请选择要删除的菜单信息!");
			return ret;
		}
		List<Menu> findChildernList = menuService.findChildernList(id);
		if(findChildernList != null && findChildernList.size() > 0){
			//表示该分类下存在子分类,不能删除
	 */
	@RequestMapping(value="/edit_password",method=RequestMethod.GET)
	public ModelAndView editPassword(ModelAndView model){
		model.setViewName("system/edit_password");
		return model;
	}
	
	@RequestMapping(value="/edit_password",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> editPasswordAct(String newpassword,String oldpassword,HttpServletRequest request){
		Map<String, String> ret = new HashMap<String, String>();
		if(StringUtils.isEmpty(newpassword)){
			ret.put("type", "error");
			ret.put("msg", "请填写新密码!");
			return ret;
		}
		User user = (User)request.getSession().getAttribute("admin");
		if(!user.getPassword().equals(oldpassword)){
			ret.put("type", "error");
			ret.put("msg", "原密码错误!");
			return ret;
		}
		user.setPassword(newpassword);
		if(userService.editPassword(user) <= 0){
			ret.put("type", "error");
			ret.put("msg", "密码修改失败,请联系管理员!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "密码修改成功!");
		logService.add("用户名为{"+user.getUsername()+"},的用户成功修改密码!");
		return ret;
	} 
	
	/**
	 * 本系统所有的验证码均采用此方法
	 * @param vcodeLen
	 * @param width
	 * @param height
	 * @param cpachaType:用来区别验证码的类型,传入字符串
	 * @param request
	 * @param response
	 */
	@RequestMapping(value="/get_cpacha",method=RequestMethod.GET)
	public void generateCpacha(
			@RequestParam(name="vl",required=false,defaultValue="4") Integer vcodeLen,
			@RequestParam(name="w",required=false,defaultValue="100") Integer width,
			@RequestParam(name="h",required=false,defaultValue="30") Integer height,

/**
 * 日志管理控制器
 *
 */
@RequestMapping("/admin/log")
@Controller
public class LogController {
	@Autowired
	private LogService logService;
	
	/**
	 * 日志列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public ModelAndView list(ModelAndView model){
		model.setViewName("log/list");
		return model;
	}
	
	/**
	 * 获取日志列表
	 * @param page
	 * @param content
	 * @param roleId
	 * @param sex
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getList(Page page,
			@RequestParam(name="content",required=false,defaultValue="") String content
			){
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();

/**
 * 前台页面首页控制器
 *
 */
@RequestMapping("/index")
@Controller
public class IndexController {
	
	@Autowired
	private NewsCategoryService newsCategoryService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private NewsService newsService;
	
	@Autowired
	private LogService logService;
	
	/**
	 * 系统首页
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public ModelAndView index(ModelAndView model){
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("offset", 0);
		queryMap.put("pageSize", 10);
		model.addObject("newsCategoryList", newsCategoryService.findAll());
		model.addObject("newsList", newsService.findList(queryMap));
		model.setViewName("home/index/index");
		return model;
	}
	
	/**

/**
 * 菜单管理控制器
 *
 */
@RequestMapping("/admin/menu")
@Controller
public class MenuController {
	
	@Autowired
	private MenuService menuService;
	
	
	/**
	 * 菜单管理列表页
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public ModelAndView list(ModelAndView model){
		model.addObject("topList", menuService.findTopList());
		model.setViewName("menu/list");
		return model;
	}
	
	/**
	 * 获取菜单列表
	 * @param page
	 * @param name
	 * @return
	 */
	 * @param keyword
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value="/get_search_list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getSearchList(Page page,
			@RequestParam(name="keyword",required=false,defaultValue="") String keyword
			) throws UnsupportedEncodingException{
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		queryMap.put("title", new String(keyword.getBytes("UTF-8"),"UTF-8"));
		ret.put("type", "success");
		ret.put("newsList", newsService.findList(queryMap));
		return ret;
	}
	
	/**
	 * 添加评论
	 * @param comment
	 * @return
	 */
	@RequestMapping(value="/comment_news",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> commentNews(Comment comment){
		Map<String, Object> ret = new HashMap<String, Object>();
		if(comment == null){
			ret.put("type", "error");
			ret.put("msg", "请填写完整的评论信息!");
			return ret;
		}
		if(comment.getNewsId() == null){
			ret.put("type", "error");
			ret.put("msg", "请选择一个文章进行评论!");
			return ret;
		}
		if(StringUtils.isEmpty(comment.getNickname())){
			ret.put("type", "error");
			ret.put("msg", "请填写昵称!");
			return ret;
		}
		if(StringUtils.isEmpty(comment.getContent())){
			ret.put("type", "error");
			ret.put("msg", "请填写评论内容!");
			return ret;
		}
		comment.setCreateTime(new Date());
	 * 新闻信息编辑
	 * 
	 * @param newsCategory
	 * @return
	 */
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, String> edit(News news) {
		Map<String, String> ret = new HashMap<String, String>();
		if (news == null) {
			ret.put("type", "error");
			ret.put("msg", "请填写正确的信息!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getTitle())) {
			ret.put("type", "error");
			ret.put("msg", "新闻标题不能为空!");
			return ret;
		}
		if (news.getCategoryId() == null) {
			ret.put("type", "error");
			ret.put("msg", "请选择新闻分类!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getAbstrs())) {
			ret.put("type", "error");
			ret.put("msg", "新闻摘要不能为空!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getTags())) {
			ret.put("type", "error");
			ret.put("msg", "新闻标签不能为空!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getPhoto())) {
			ret.put("type", "error");
			ret.put("msg", "新闻封面图片必须上传!");
			return ret;
		}
		if (StringUtils.isEmpty(news.getAuthor())) {
			ret.put("type", "error");
			ret.put("msg", "新闻作者不能为空!");
			return ret;
		}
		}
		if(StringUtils.isEmpty(comment.getContent())){
			ret.put("type", "error");
			ret.put("msg", "请填写评论内容!");
			return ret;
		}
		comment.setCreateTime(new Date());
		if(commentService.add(comment) <= 0){
			ret.put("type", "error");
			ret.put("msg", "评论失败,请联系管理员!");
			return ret;
		}
		//文章评论数加1
		newsService.updateCommentNumber(comment.getNewsId());
		ret.put("type", "success");
		ret.put("createTime", comment.getCreateTime());
		return ret;
	}
	
	/**
	 * 分页获取某一文章的评论
	 * @param page
	 * @return
	 */
	@RequestMapping(value="/get_comment_list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getCommentList(Page page,Long newsId){
		Map<String, Object> ret = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		queryMap.put("newsId", newsId);
		ret.put("type", "success");
		ret.put("commentList", commentService.findList(queryMap));
		return ret;
	}
}
package com.yuanma.programmer.controller.admin;

	}
	
	
	/**
	 * 添加用户
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/user/login",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> login(User user,String cpacha,HttpServletRequest request){
		Map<String, String> ret = new HashMap<String, String>();
		Object loginCpacha = request.getSession().getAttribute("loginCpacha");
		if(!cpacha.toUpperCase().equals(loginCpacha.toString().toUpperCase())){
			ret.put("type", "error");
			ret.put("msg", "验证码错误!");
			logService.add("用户名为"+user.getUsername()+"的用户登录时输入验证码错误!");
			return ret;
		}
		
		if(user == null){
			ret.put("type", "error");
			ret.put("msg", "请填写正确的用户信息!");
			return ret;
		}
		if(StringUtils.isEmpty(user.getUsername())){
			ret.put("type", "error");
			ret.put("msg", "请填写用户名!");
			return ret;
		}
		if(StringUtils.isEmpty(user.getPassword())){
			ret.put("type", "error");
			ret.put("msg", "请填写密码!");
			return ret;
		}
		if(isExistUser(user.getUsername(), user.getPassword())){
			request.getSession().setAttribute("user", user.getUsername());
			ret.put("type", "success");
			ret.put("msg", "登录成功!");
			return ret;
		}
		ret.put("type", "error");
		ret.put("msg", "登录失败!");
		return ret;
	}
	
	/**
	 * 判断该用户名是否存在
	 * @param username
	 * @param id
	 * @return
	 */

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值