当前位置:   article > 正文

基于javaweb+mysql的springboot新闻发布系统(java+springboot+jsp+layui+maven+mysql)_基于spring boot layui文章发布

基于spring boot layui文章发布

基于javaweb+mysql的springboot新闻发布系统(java+springboot+jsp+layui+maven+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

基于javaweb+mysql的SpringBoot新闻发布系统(java+springboot+jsp+layui+maven+mysql)

一、项目运行 环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。


}*/

title=title.replace(search, "<font color='red'>"+search+"</font>");

System.out.println(title);

x.setTitle(title);

return x;

}).collect(Collectors.toList());

request.setAttribute("list",newsList

);

List<Category> categoryList = categoryDao.queryAll();

request.setAttribute("categoryList",

categoryList.stream().filter(x -> x.getState().equals("1")).collect(Collectors.toList()));

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

public String show(){

List<Category> categoryList = categoryDao.queryAll();

categoryList=categoryList.stream().filter(x->x.getState().equals("1")).collect(Collectors.toList());

if(categoryList.size()>=5)

request.setAttribute("list", categoryDao.queryAll());

request.setAttribute("msg","设置栏目显示失败,前台栏目最多显示5个");

return "listcategory";

}else {

categoryDao.show(Integer.parseInt(request.getParameter("id")));

return "redirect:listforadmin";

@RequestMapping("/hidden")

public String hidden(){

categoryDao.hidden(Integer.parseInt(request.getParameter("id")));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
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");

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
request.setAttribute("commentsList", commentsList);

request.setAttribute("contentstr", content);

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());

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

@Autowired

private HttpServletRequest request;

private NewsDao newsDao = new NewsDao();

private CategoryDao categoryDao = new CategoryDao();

private CommentsDao commentsDao = new CommentsDao();

@RequestMapping("/publish")

public String publish(){

String title = request.getParameter("title");

String content = request.getParameter("content");

String categoryid = request.getParameter("categoryid");

Users users = (Users) request.getSession().getAttribute("loginUsers");

Integer usersId = users.getId();

Integer deptid = users.getDeptid();

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
List<Users> list = usersDao.getUsers();

request.setAttribute("list", list);

return "listusers";

分类管理控制层:

@Controller

@RequestMapping("CategoryServlet")

public class CategoryController {

@Autowired

private HttpServletRequest request;

private CategoryDao categoryDao=new CategoryDao();

@RequestMapping("/listforadmin")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

}else{

title=split[0]+"<font color='red'>"+search+"</font>";

}*/

title=title.replace(search, "<font color='red'>"+search+"</font>");

System.out.println(title);

x.setTitle(title);

return x;

}).collect(Collectors.toList());

request.setAttribute("list",newsList

);

List<Category> categoryList = categoryDao.queryAll();

request.setAttribute("categoryList",

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

return "login";

@RequestMapping("/userreg")

public String userreg() {

String username = request.getParameter("username");

String password = request.getParameter("password");

String account = request.getParameter("account");

String email = request.getParameter("email");

String password2 = request.getParameter("password2");

if (!password.equals(password2)) {

request.setAttribute("error", "注册失败,密码与确认密码不一致!");

return "reg";

} else {

boolean isSuccess = usersDao.isReg(account);

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
private HttpServletRequest request;

private CategoryDao categoryDao=new CategoryDao();

@RequestMapping("/listforadmin")

public String listforadmin(){

List<Category> categoryList = categoryDao.queryAll();

request.setAttribute("list", categoryList);

return "listcategory";

@RequestMapping("/show")

public String show(){

List<Category> categoryList = categoryDao.queryAll();

categoryList=categoryList.stream().filter(x->x.getState().equals("1")).collect(Collectors.toList());
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
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 {

request.setAttribute("msg", "登录失败,账号密码不匹配");

return "admin_login";

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

@Autowired

private HttpServletRequest request;

private NewsDao newsDao = new NewsDao();

private CategoryDao categoryDao = new CategoryDao();

private CommentsDao commentsDao = new CommentsDao();

@RequestMapping("/publish")

public String publish(){

String title = request.getParameter("title");

String content = request.getParameter("content");

String categoryid = request.getParameter("categoryid");

Users users = (Users) request.getSession().getAttribute("loginUsers");

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
public String userlogin() {

String userName = request.getParameter("username");

String password = request.getParameter("password");

String clientCheckcode = request.getParameter("validateCode");

String serverCheckcode = (String) request.getSession().getAttribute("checkcode");

if (clientCheckcode.equals(serverCheckcode)) {

// 2. 去访问dao , 看看是否满足登录。

Users Users = usersDao.userlogin(userName, password);

// 3. 针对dao的返回结果,做出响应

if (Users != null) {

request.getSession().setAttribute("usersLogin", Users);

CategoryDao categoryDao = new CategoryDao();

List<Category> categoryList = categoryDao.queryAll();

request.setAttribute("categoryList", categoryList.stream().filter(x -> x.getState().equals("1")).collect(Collectors.toList()));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

@RequestMapping("/listforadmin")

public String listforadmin() {

List<Users> list = usersDao.getUsers();

request.setAttribute("list", list);

return "listusers";

@RequestMapping("/del")

public String del(Integer id) {

usersDao.del(id);

List<Users> list = usersDao.getUsers();

request.setAttribute("list", list);

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

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();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

@RequestMapping("/detail")

public String detail(){

//测试

String id =  request.getParameter("id");

if(id.contains(".jsp"))

id= request.getParameter("id").replaceAll(".jsp","");

News news = newsDao.queryByid(Integer.parseInt(id));

news.setClicks(news.getClicks() + 1);

newsDao.setClicksIncrement(news);

NewsDetail detail = new NewsDetail();

detail.setNews(news);

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

public String show(){

List<Category> categoryList = categoryDao.queryAll();

categoryList=categoryList.stream().filter(x->x.getState().equals("1")).collect(Collectors.toList());

if(categoryList.size()>=5)

request.setAttribute("list", categoryDao.queryAll());

request.setAttribute("msg","设置栏目显示失败,前台栏目最多显示5个");

return "listcategory";

}else {

categoryDao.show(Integer.parseInt(request.getParameter("id")));

return "redirect:listforadmin";

@RequestMapping("/hidden")

public String hidden(){
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

String categoryid = request.getParameter("categoryid");

News news = new News();

news.setCategoryid(Integer.parseInt(categoryid));

news.setContent(content);

news.setPbdate(new Date());

news.setId(Integer.parseInt(request.getParameter("id")));

news.setTitle(title);

newsDao.edit(news);

return "redirect:listforadmin";

@RequestMapping("/del")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
List<Category> categoryList = categoryDao.queryAll();

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")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

请添加图片描述

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

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号