基于javaweb的SpringBoot协同过滤算法新闻推荐管理系统(java+ssm+javascript+html+thymeleaf+ajax+mysql+maven)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

000923571103

010923571103

020923571103

030923571103

040923571103

050923571103

基于javaweb的SpringBoot协同过滤算法新闻推荐管理系统(java+ssm+javascript+html+thymeleaf+ajax+mysql+maven)

项目介绍

本项目新闻推荐管理系统;

前台:

登录、首页、全部新闻、系统特色、猜你喜欢、分类、评论

后台: (1)文件管理:文件列表。 (2)用户管理:用户管理。 (3)新闻管理:新闻管理。 (4)三联管理:联动管理。 (5)新闻审核:新闻的审核和管理。

技术栈

SSM+mysql+layui+CSS+JavaScript

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080 访问

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    return response;
}

/**
* 第二种文件下载/回显方法
* @param id tb_sys_file.id
* @param fileName 实际下载的文件名字
* @return
*/
@ApiOperation(value = "根据ID文件下载/回显",notes = "path里面传文件ID")
@RequestMapping(value = "/fileDown/{id}",method = {RequestMethod.POST,RequestMethod.GET})
public ResponseEntity<byte[]> fileDown(@PathVariable Long id, String fileName){
SysFile sysFile = fileService.getById(id);
byte [] body = null;
String fileUrl=sysFile.getFileUrl();
try {
//获取到文件流
InputStream in = new FileSystemResource(fileUrl).getInputStream();
body = new byte[in.available()];
in.read(body);
} catch (IOException e1) {
logger.debug("文件读入出错,文件路径为:"+fileUrl);
e1.printStackTrace();
}
//添加响应头
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename="+fileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
HttpStatus statusCode = HttpStatus.OK;
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(body, headers, statusCode);
return response;
}
//通用从classpath下载文件文件
@RequestMapping(value = "/export")
public ResponseEntity<byte[]> fileExport(String fileName){
byte [] body = null;
InputStream in=null;
try {
//获取到文件流
in = FileController.class.getClassLoader().getResourceAsStream(fileName);
if(in.available()<1){
in=new FileInputStream(new File(configJsonPath+File.separator+fileName));
}
logger.debug("需要导出的模板:{},获取的流为:{}",fileName,in);
body = new byte[in.available()];
logger.debug("导出模板大小:{},读入body大小:{}",in.available(),body.length);
in.read(body);
//添加响应头
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename="+ URLEncoder.encode(fileName,"UTF-8"));
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
HttpStatus statusCode = HttpStatus.OK;
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(body, headers, statusCode);
return response;
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

/**
* #娱乐明星 4-20074
*
* #娱乐电影 4-20075
* #娱乐音乐 4-20077
*
*
*/

@Controller
@RequestMapping("grap")
public class GrapNewsController {

@Autowired
SysNewsService newsService;

@Autowired
SysUserService userService;

@Autowired
NewsCategoryService categoryService;

private static final Logger logger= LoggerFactory.getLogger(GrapNewsController.class);

//设置爬取网页
private static String baseUrlStar="https://ent.ifeng.com/star/";//娱乐·明星首页
private static String baseUrlMovie="https://ent.ifeng.com/movie/";//娱乐·电影首页
private static String baseUrlMusic="https://ent.ifeng.com/music/";//娱乐·音乐首页

//爬取文件存放路径
//
@Value("${com.cgx.file.baseFilePath}")
private String baseFilePath;

private static String yuleyiyueUrl="https://shankapi.ifeng.com/shanklist/_/getColumnInfo/_/default/{id}/{idTimeMills}/20/4-20077-/getColumnInfoCallback?callback=getColumnInfoCallback&_={currTimeMills}";
private static String yulestarUrl="https://shankapi.ifeng.com/shanklist/_/getColumnInfo/_/default/{id}/{idTimeMills}/20/4-20074-/getColumnInfoCallback?callback=getColumnInfoCallback&_={currTimeMills}";
private static String yulefilmUrl="https://shankapi.ifeng.com/shanklist/_/getColumnInfo/_/default/{id}/{idTimeMills}/20/4-20075-/getColumnInfoCallback?callback=getColumnInfoCallback&_={currTimeMills}";

private String defaultYuLeId="6760584714211311643";//娱乐音乐
private String defaultYuLeTimeMills="1611846336000";//娱乐音乐

private String defaultYuLeStarId="6776520715089744701";//娱乐明星
private String defaultYuLeStarTimeMills="1615739836000";//娱乐明星
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

/**
* <p>
* 新闻分类表 前端控制器
* </p>
*
*/
@Controller
@RequestMapping({"/category","/home/category"})
public class NewsCategoryController {

private static final Logger logger= LoggerFactory.getLogger(NewsCategoryController.class);

private static final String page_prefix="news/category/";


@Autowired
SysNewsService newsService;

@Autowired
NewsCategoryService categoryService;

/**
* 跳到添加页面
* @param model
* @return
*/
@RequestMapping("addPage")
public String addPage(Model model){
return page_prefix+"add";
}

//新闻分类添加
@RequestMapping("add")
@ResponseBody
public ResponseBean addNews(NewsCategory category, HttpSession session){
logger.debug("addNewsCategory:"+category);
String name = category.getName();
String code = category.getCode();
QueryWrapper<NewsCategory> queryWrapper=new QueryWrapper<>();
queryWrapper.like("code",code).like("name",name);
List<NewsCategory> list = categoryService.list(queryWrapper);
if(!ToolsUtils.isEmpty(list)){
return ResultUtil.error("名称或编码已经存在!");
}
boolean i = categoryService.save(category);
logger.debug("保存后的NewsCategory:"+category);
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
        QueryWrapper<NewsFavor> queryWrapper=new QueryWrapper<>();
String newsTitle = queryParam.getNewsTitle();
String userName = queryParam.getUserName();
queryWrapper.like(!StringUtils.isEmpty(newsTitle),"news_title",newsTitle)
.like(!StringUtils.isEmpty(userName),"user_name",userName);
IPage<NewsFavor> indexPage = new Page<>(pageNum, pageSize);
IPage<NewsFavor> listPage = favorService.page(indexPage, queryWrapper);
logger.debug("获取的新闻点赞列表:"+listPage);
//调用工具类对结果进行封装然后返回
Map resultMap = ToolsUtils.wrapperResult(listPage, "favorList");
return ResultUtil.successData(resultMap);
}

/**
* 批量删除点赞
* @param idList
* @return
*/
@RequestMapping("deleteBatchByIds")
@ResponseBody
public ResponseBean deleteBatchByIds(@RequestParam List<Long> idList){
logger.debug("deleteBatchByIds:"+idList);
if(idList==null||idList.isEmpty()){
return ResultUtil.error(CommonEnum.BAD_PARAM);
}
boolean delete = favorService.removeByIds(idList);
logger.debug("批量删除结果:"+delete);
return ResultUtil.success() ;
}

@RequestMapping("deleteById")
@ResponseBody
public ResponseBean deleteById(@RequestParam Long id){
if(id==null||id<0){
return ResultUtil.error(CommonEnum.BAD_PARAM);
}
boolean delete = favorService.removeById(id);
return ResultUtil.success() ;
}


}
package com.news.common.file;


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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    NewsFavorService favorService;

@Autowired
SysUserService userService;

@Autowired
NewsForwardService forwardService;

@Autowired
NewsCommentService commentService;

@Value("${com.cgx.file.baseFilePath}")
private String baseFilePath;

// private static String schema="https";
//
// private static String baseurl="https://www.toutiao.com/";
//
// private static String yuleUrl="https://www.toutiao.com/ch/news_entertainment/";


//获取新闻分类
@ModelAttribute
public void addModelAttribute(Model model){
List<NewsCategory> categoryList = newsCategoryService.list();
model.addAttribute("categoryList",categoryList);
}

/**
* 获取网络图片保存到本地
* */
public String saveFileByUrl(String imgUrl) throws IOException {
//创建io流
FileOutputStream out = null;
BufferedInputStream in = null;
HttpURLConnection connection = null;
//创建缓冲区
byte[] buf = new byte[1024];
int len = 0;
//文件名字,随机一个id,并且去除-
String saveFileName= UUID.randomUUID().toString().replaceAll("-","")+".jpg";
try {
URL url = new URL(imgUrl);
connection = (HttpURLConnection)url.openConnection();
connection.connect();
//将文件传入缓冲区中
in = new BufferedInputStream(connection.getInputStream());
//将文件读取出来


项目链接:
https://javayms.github.io?id=421023491103200yr
https://javayms.pages.dev?id=421023491103200yr