基于javaweb的SpringBoot生活旅行分享平台(java+springboot+jpa+html+thymeleaf+js+ajax+maven+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

580023042402

590023042402

000023052402

010023052402

020023052402

242025011804

412025011804

102025021804

462025021804

262025031804

基于javaweb的SpringBoot生活旅行分享平台(java+springboot+jpa+html+thymeleaf+js+ajax+maven+mysql)

一、项目运行 环境配置:

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

项目技术:

Springboot+ SpringMVC + JPA + Html+ JavaScript + JQuery + Ajax + maven等等  

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
    start = start<0?0:start;
return atlasService.list(start, size, 5); //5表示导航分页最多有5个,像 [1,2,3,4,5] 这样
}

/*
获取查看次数最多的文章
*/
@GetMapping("/viewing")
public List<Blog> listViewsBlog() {
return blogService.listViews();
}

/*
搜索文章
*/
@GetMapping("/searchBlog")
public List<Blog> listBlogsByKeyword(@RequestParam("keyword") String keyword) {
return blogService.listBlogByKeyword(keyword);
}

/*
文章详情页 获取文章详情
*/
@GetMapping("/blogsDetail/{bid}")
public Blog findOne(@PathVariable("bid") int bid) {
return blogService.findOne(bid);
}

/*
获取相似推荐列表
*/
@GetMapping("/blogsLike/{bid}")
public List<Blog> listLikeBlog(@PathVariable("bid") int bid) {
Blog blog = blogService.findOne(bid);
Type type = blog.getType();
return blogService.listByType(type.getId());
}

/*
条件排序
*/
@GetMapping("/commentsSort")
public List<Comment> listSort(@RequestParam("bid") int bid, @RequestParam("sort") String sort) {
List<Comment> comments = commentService.listSort(bid, sort);
for(Comment comment: comments) {
List<Reply> replies = replyService.findListByBlogAndComment(bid, comment.getId());
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

@RestController
public class AtlasController {

@Autowired
AtlasService atlasService;
@Autowired
PictureService pictureService;

/*
增加图集
*/
@PostMapping("/atlases")
public void add(@RequestParam("name") String name) {
Atlas atlas = new Atlas();
atlas.setName(name);
atlas.setCreateDate(new Date());
atlasService.save(atlas);
}

/*
获取图集
*/
@GetMapping("/atlases/{aid}")
public Atlas findOne(@PathVariable("aid") int aid) {
return atlasService.findOne(aid);
}

/*
修改图集
*/
@PutMapping("/atlases/{tid}")
public void updateType(@PathVariable("tid") int tid, @RequestParam("name") String name) {
Atlas atlas = atlasService.findOne(tid);
atlas.setName(name);
atlasService.update(atlas);
}

/*
删除图集
*/
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
文章详情页 获取文章详情
*/
@GetMapping("/blogsDetail/{bid}")
public Blog findOne(@PathVariable("bid") int bid) {
return blogService.findOne(bid);
}

/*
获取相似推荐列表
*/
@GetMapping("/blogsLike/{bid}")
public List<Blog> listLikeBlog(@PathVariable("bid") int bid) {
Blog blog = blogService.findOne(bid);
Type type = blog.getType();
return blogService.listByType(type.getId());
}

/*
条件排序
*/
@GetMapping("/commentsSort")
public List<Comment> listSort(@RequestParam("bid") int bid, @RequestParam("sort") String sort) {
List<Comment> comments = commentService.listSort(bid, sort);
for(Comment comment: comments) {
List<Reply> replies = replyService.findListByBlogAndComment(bid, comment.getId());
comment.setReplies(replies);
}
return comments;
}

/*
检查是否登录
*/
@GetMapping("/check")
public Object checkLogin(HttpSession session) {
if(session == null) {
return Result.fail("未登录");
} else {
return Result.success();
}
}

/*
获取专题分类列表与列表下的文章信息
*/
@GetMapping("/foreTypes")
public List<Type> listType() {
List<Type> types = typeService.listType();
for(Type type: types) {
List<Blog> blogs = blogService.listByTypeBlogs(type.getId());
type.setBlogs(blogs);
}
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
        reply.setBlog(blog);
reply.setFlag(1);
reply.setCreateTime(new Date());
replyService.save(reply);
}

@GetMapping("/replies/{bid}")
public int getReplyCount(@PathVariable("bid") int bid) {
return replyService.replyCount(bid);
}
}
package com.sxw.blog.web;



@RestController
public class AdminController {

@Autowired
UserService userService;

@PostMapping("login")
public Object login(@RequestBody User user, HttpSession session) {
User u = userService.findByUsernameAndPassword(user.getUsername(),user.getPassword());
if(u != null) {
session.setAttribute("user", u);
return Result.success();
}
else {
return Result.fail("账户名或者密码错误");
}
}
}
package com.sxw.blog.web;

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

@GetMapping("/authors")
public Author get(HttpSession session) {
User user = (User) session.getAttribute("user");
return authorService.findOne(user.getId());
}

@PutMapping("/authors")
public void update(HttpSession session, @RequestParam("description") String description) {
User user = (User) session.getAttribute("user");
authorService.save(description,user.getId());
}

@GetMapping("authors/info")
public Author getAuthorInfo() {
Author author = authorService.findOne(1);
author.setUser(userService.getOne(1));
return author;
}
}
package com.sxw.blog.handler;




@ControllerAdvice
public class ControllerExceptionHandler {

private final Logger logger = LoggerFactory.getLogger(this.getClass());


@ExceptionHandler(Exception.class)
public ModelAndView exceptionHander(HttpServletRequest request, Exception e) throws Exception {
logger.error("Requst URL : {},Exception : {}", request.getRequestURL(),e);
if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
throw e;
}
ModelAndView mv = new ModelAndView();
mv.addObject("url",request.getRequestURL());
mv.addObject("exception", e);
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
        //更新地址
String firstPicture = saveOrUpdateImageFile(blog,image,request);
blogService.saveFistPicture(firstPicture,blog.getId());
}
public String saveOrUpdateImageFile(Blog bean, MultipartFile image, HttpServletRequest request) throws IOException {
File imageFolder= new File(request.getServletContext().getRealPath("img/picture"));
File file = new File(imageFolder,bean.getId() + ".jpg");
String firstPicture = file.toString();
if(!file.getParentFile().exists())
file.getParentFile().mkdirs();
image.transferTo(file);
BufferedImage img = ImageUtil.change2jpg(file);
ImageIO.write(img, "jpg", file);
return firstPicture;
}

/*
分类管理页 查询全部博客,并进行分页
*/
@GetMapping("blogs")
public Page4Navigator<Blog> list(@RequestParam(value = "start", defaultValue = "0") int start, @RequestParam(value = "size", defaultValue = "10") int size) {
start = start<0?0:start;
return blogService.list(start, size, 5); //5表示导航分页最多有5个,像 [1,2,3,4,5] 这样
}

/*
博客删除
*/
@DeleteMapping("blogs/{bid}")
public String delete(@PathVariable("bid") int bid) {
blogService.deleteBlog(bid);
return null;
}

/*
编辑博客
*/
@GetMapping("blogs/{bid}")
public Blog updateBlog(@PathVariable("bid") int bid) {
return blogService.findOne(bid);
}

@PutMapping("blogs/{bid}")
public void updateViews(@PathVariable("bid") int bid) {
int views = blogService.findOne(bid).getViews();
int new_views = ++views;
blogService.updateViews(new_views, bid);
}

}
package com.sxw.blog.web;


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