基于javaweb+springboot的新闻发布管理系统

基于javaweb+springboot的新闻发布管理系统,第1张

基于javaweb+springboot的新闻发布管理系统(java+Springboot+ssm+mysql+maven)

一、项目简述
功能: 区分为管理员用户和普通用户,管理员用户能删除评论, 调整新闻显示/隐藏,修改新闻,删除普通用户,普通用户能 登陆浏览,新用户可以注册基本功能实现了新闻增加,新 闻删除,新闻修改,新闻搜索其他功能:用户评论,管理 员删除差评,新闻分类,前台分类显示新闻,用户注册, 登录,个人信息修改等等功能。

二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP + SpringBoot + Servlert + htm l+ css + JavaScript + ECharts+ JQuery + Maven 等等



适用

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

    public String search(){
        String search = request.getParameter("search");
        request.setAttribute("searchStr", search);
        List<News> newsList = newsDao.queryAll();
        newsList=newsList.stream().filter(x -> x.getTitle().contains(search)).collect(Collectors.toList());
        newsList=	newsList.stream().map(x->{
            String title = x.getTitle();
            /*			String[] split = title.split(search);
             */
			/*if(split.length>=2){
				for(int i=0;i<font color='red'>"+search+"font>"+split[i+1];
				}
			}else{
				title=split[0]+"<font color='red'>"+search+"font>";
			}*/
        g.setColor(Color.BLUE);
        // 边框区域
        g.drawRect(1, 1, WIDTH - 2, HEIGHT - 2);
    }
    /**
     * 在图片上画随机线条
     *
     * @param g
     */
    private void drawRandomLine(Graphics g) {
        // 设置颜色
        g.setColor(Color.GREEN);
        // 设置线条个数并画线
        for (int i = 0; i < 5; i++) {
            int x1 = new Random().nextInt(WIDTH);
            int y1 = new Random().nextInt(HEIGHT);
            int x2 = new Random().nextInt(WIDTH);
            int y2 = new Random().nextInt(HEIGHT);
            g.drawLine(x1, y1, x2, y2);
        }
    }
    /**
     * 画随机字符
        g.drawRect(1, 1, WIDTH - 2, HEIGHT - 2);
    }
    /**
     * 在图片上画随机线条
     *
     * @param g
     */
    private void drawRandomLine(Graphics g) {
        // 设置颜色
        g.setColor(Color.GREEN);
        // 设置线条个数并画线
        for (int i = 0; i < 5; i++) {
            int x1 = new Random().nextInt(WIDTH);
            int y1 = new Random().nextInt(HEIGHT);
            int x2 = new Random().nextInt(WIDTH);
            int y2 = new Random().nextInt(HEIGHT);
            g.drawLine(x1, y1, x2, y2);
        }
    }
    /**
        int x = 5;
        String ch = "";
        // 控制字数
        for (int i = 0; i < 4; i++) {
            // 设置字体旋转角度
            int degree = new Random().nextInt() % 30;
            ch = baseChar.charAt(new Random().nextInt(baseChar.length())) + "";
            sb.append(ch);
            // 正向角度
            g.rotate(degree * Math.PI / 180, x, 20);
            g.drawString(ch, x, 20);
            // 反向角度
            g.rotate(-degree * Math.PI / 180, x, 20);
            x += 30;
        }
        return sb.toString();
    }
}
新闻信息控制层:
@Controller
@RequestMapping("NewsServlet")
public class NewsController {
    @Autowired
    private HttpServletRequest request;
        request.setAttribute("categoryList",
                categoryList.stream().filter(x -> x.getState().equals("1")).collect(Collectors.toList()));
        return "searchnews";
    }
}
用户信息控制层:
@Controller
@RequestMapping("UsersServlet")
public class UsersController {
    private UsersDao usersDao = new UsersDao();
    @Autowired
    private HttpServletRequest request;
    @RequestMapping("/loginadmin")
    public String loginadmin() {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        Users users = usersDao.login(username, password);
        if (users != null) {
            request.getSession().setAttribute("loginUsers", users);
            return "admin_index";
        } else {
        // String random = drawRandomNum((Graphics2D) g,"ch");//生成中文验证码图片
        // String random = drawRandomNum((Graphics2D) g,"nl");//生成数字和字母组合的验证码图片
        // String random = drawRandomNum((Graphics2D) g,"n");//生成纯数字的验证码图片
        // String random = drawRandomNum((Graphics2D) g,"l");//生成纯字母的验证码图片
        String random = drawRandomNum((Graphics2D) g, createTypeFlag);// 根据客户端传递的createTypeFlag标识生成验证码图片
        // 7.将随机数存在session中
        request.getSession().setAttribute("checkcode", random);
        // 8.设置响应头通知浏览器以图片的形式打开
        response.setContentType("image/jpeg");// 等同于response.setHeader("Content-Type",
        // "image/jpeg");
        // 9.设置响应头控制浏览器不要缓存
        response.setDateHeader("expries", -1);
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        // 10.将图片写给浏览器
        ImageIO.write(bi, "jpg", response.getOutputStream());
    }
    /**
     * 设置图片的背景色
     *
     * @param g
     */
    private void setBackGround(Graphics g) {
        // 设置颜色
        g.setColor(Color.WHITE);
        // 填充区域
        g.fillRect(0, 0, WIDTH, HEIGHT);
    @RequestMapping("/listforadmin")
    public String listforadmin(){
        List<News> newsList = newsDao.queryAll();
        request.setAttribute("list", newsList);
        return "listnews";
    }
    @RequestMapping("/toaddnews")
    public String toaddnews(){
        List<News> newsList = newsDao.queryAll();
        request.setAttribute("list", newsList);
        List<Category> categoryList = categoryDao.queryAll();
        request.setAttribute("categoryList", categoryList);
        return "addnews";
    }
    @RequestMapping("/edit")
    public String edit(){
        String title = request.getParameter("title");
        String content = request.getParameter("content");
        String categoryid = request.getParameter("categoryid");
        News news = new News();
        news.setCategoryid(Integer.parseInt(categoryid));
        request.setAttribute("categoryList",
                categoryList.stream().filter(x -> x.getState().equals("1")).collect(Collectors.toList()));
        return "detailnews";
    }
    @RequestMapping("/search")
    public String search(){
        String search = request.getParameter("search");
        request.setAttribute("searchStr", search);
        List<News> newsList = newsDao.queryAll();
        newsList=newsList.stream().filter(x -> x.getTitle().contains(search)).collect(Collectors.toList());
        newsList=	newsList.stream().map(x->{
            String title = x.getTitle();
            /*			String[] split = title.split(search);
             */
            }
        } else {
            // 默认截取数字和字母的组合
            return createRandomChar(g, baseNumLetter);
        }
        return "";
    }
    /**
     * 创建随机字符
     *
     * @param g
     * @param baseChar
     * @return 随机字符
     */
    private String createRandomChar(Graphics2D g, String baseChar) {
        StringBuffer sb = new StringBuffer();
        int x = 5;
        String ch = "";
        // 控制字数
        for (int i = 0; i < 4; i++) {
            // 设置字体旋转角度
        // 控制字数
        for (int i = 0; i < 4; i++) {
            // 设置字体旋转角度
            int degree = new Random().nextInt() % 30;
            ch = baseChar.charAt(new Random().nextInt(baseChar.length())) + "";
            sb.append(ch);
            // 正向角度
            g.rotate(degree * Math.PI / 180, x, 20);
            g.drawString(ch, x, 20);
            // 反向角度
            g.rotate(-degree * Math.PI / 180, x, 20);
            x += 30;
        }
        return sb.toString();
    }
}
新闻信息控制层:
@Controller
@RequestMapping("NewsServlet")

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/729603.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存