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

该平台是一个基于JavaWeb和SpringBoot构建的生活旅行分享系统,使用Mysql存储数据,结合JPA、Ajax和RESTfulAPI实现数据交互。支持图集的增删改查、评论功能以及最新图集的获取。适合作为课程设计、项目练习的实例。
摘要由CSDN通过智能技术生成

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

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

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

一、项目运行 环境配置:

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

项目技术:

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

    /*
    获取图集
     */
    @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);
    }

    /*
    删除图集
     */
    @DeleteMapping("/atlases/{aid}")
    public String delete(@PathVariable("aid") int aid) {
        atlasService.delete(aid);
        return null;
    }

    /*
    获取最新上传的图集
     */
    @GetMapping("/atlases")
    public Atlas getRecentlyAtlas() {
        Atlas atlas = atlasService.getRecentlyAtlas();
        int aid = atlas.getId();
        List<Picture> pictures = pictureService.list(aid);
        atlas.setPictures(pictures);
        return atlas;
    }

    /*
    获取全部图集
     */
    @Autowired
    BlogService blogService;
    @Autowired
    ReplyService replyService;

    @PostMapping("/comments/{bid}")
    public void save(@PathVariable("bid") int bid, HttpServletRequest request) {
        Blog blog = blogService.findOne(bid);
        Comment comment = new Comment();
        comment.setBlog(blog);
        comment.setContent(request.getParameter("content"));
        comment.setNickname(request.getParameter("nickname"));
        comment.setEmail(request.getParameter("email"));
        comment.setCreateTime(new Date());
        comment.setFlag(0);
        commentService.save(comment);
    }

    /*
    获取评论列表
     */
    @GetMapping("/comments")
    public List<Comment> list(@RequestParam("bid") int bid) {
        List<Comment> comments = commentService.list(bid);
        for(Comment comment: comments) {
            List<Reply> replies = replyService.findListByBlogAndComment(bid, comment.getId());
            comment.setReplies(replies);
        }
        return comments;
    }

}
package com.sxw.blog.web;


    @GetMapping(value = "admin_atlas_edit")
    public String atlasEdit() {
        return "admin/atlasEdit";
    }

    @GetMapping(value = "admin_picture_list")
    public String pictureList() {
        return "admin/pictureList";
    }

    @GetMapping(value = "admin_author_info")
    public String getAuthorPage() {
        return "admin/authorListInfo";
    }

}
package com.sxw.blog.web;

@RestController
public class CommentController {

    @Autowired
    CommentService commentService;
    @Autowired
    BlogService blogService;
    @Autowired
    ReplyService replyService;

    @PostMapping("/comments/{bid}")
    public void save(@PathVariable("bid") int bid, HttpServletRequest request) {
        Blog blog = blogService.findOne(bid);
        Comment comment = new Comment();
        comment.setBlog(blog);
        comment.setContent(request.getParameter("content"));
        comment.setNickname(request.getParameter("nickname"));

}

package com.sxw.blog.web;

@RestController
public class ReplyController {

    @Autowired
    ReplyService replyService;
    @Autowired
    CommentService commentService;

    @PostMapping("/replies")
    public void save(@RequestParam("content") String content, @RequestParam("cid") int cid) {
        Comment comment = commentService.findOne(cid);
        Blog blog = comment.getBlog();
        Reply reply = new Reply();
        reply.setComment(comment);
        reply.setContent(content);
        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);
    @PostMapping("blogs")
    public void save(MultipartFile image, HttpServletRequest request, @RequestParam("obj") String obj) throws IOException {
        Blog blog = new Blog();
        Type type = typeService.findOne(Integer.parseInt(request.getParameter("tid")));
        blog.setType(type);  //隶属分类
        blog.setTitle(request.getParameter("title"));  //标题
        blog.setContent(request.getParameter("content"));  //文章内容
        blog.setFlag(request.getParameter("flag"));   //状态
        blog.setCreateDate(new Date());  //创建日期
        blog.setUpdateDate(new Date());  //更新日期
        blog.setViews(0);  //查看数
        blog.setNums(request.getParameter("content").length());
        User user = (User) request.getSession().getAttribute("user");
        blog.setUser(user);  //当前隶属用户
        if(obj.equals("published")) {
            blog.setPublish(true);  //发布?
        } else {
            blog.setPublish(false);  //发布?
        }
        blogService.save(blog);
        //更新地址
        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] 这样
    }
        return atlases;
    }

}
package com.sxw.blog.web;

@Controller
public class AdminPageController {

    @GetMapping(value = "admin_login")
    public String adminLogin() {
        return "admin/login";
    }

    @GetMapping(value = "admin_logout")
    public String adminLogout(HttpSession session) {
        session.removeAttribute("user");
        return "redirect:admin_login";
    }

    @GetMapping(value = "admin_index")
    public String adminIndex() {
        return "admin/index";
    }

    @GetMapping(value = "admin_blog_list")
    public String blogList() {
        return "admin/blogList";
    }

    @GetMapping(value = "admin_blog_input")
    public String blogInput() {
        return "admin/blogInput";
    }

    @GetMapping(value = "admin_type_list")
    public String typeList() {
        return "admin/typeList";
    }

    @GetMapping(value = "admin_type_input")
    public String typeInput() {
        return "admin/typeInput";
    }

    @GetMapping(value = "admin_type_edit")
    public String typeEdit() {
    }

    /*
    获取分类专题
     */
    @GetMapping("/types/{tid}")
    public Type findOne(@PathVariable("tid") int tid) {
        return typeService.findOne(tid);
    }

    /*
    修改分类
     */
    @PutMapping("/types/{tid}")
    public void updateType(@PathVariable("tid") int tid, @RequestParam("name") String name) {
        Type type = typeService.findOne(tid);
        type.setName(name);
        System.out.println(type.toString());
        typeService.update(type);
    }

    /*
    删除分类
     */
    @DeleteMapping("/types/{tid}")
    public String delete(@PathVariable("tid") int tid) {
        typeService.delete(tid);
        return null;
    }

}
package com.sxw.blog.web;

        String content = request.getParameter("content");
        Blog blog = blogService.findOne(50);   //50这个id 专门用来记录游客留言的id
        Comment comment = new Comment();
        comment.setNickname(nickname);
        comment.setEmail(email);
        comment.setContent(content);
        comment.setCreateTime(new Date());
        comment.setBlog(blog);
        comment.setFlag(0);
        commentService.save(comment);
    }
}
package com.sxw.blog.web;

@RestController
public class BlogController {

    @Autowired
    BlogService blogService;
    @Autowired
    TypeService typeService;

    /*
    增加图片
     */
    @PostMapping("/pictures")
    public Object add(@RequestParam("aid") int aid, @RequestParam("title") String title,
                      HttpSession session, HttpServletRequest request, MultipartFile image) {
        Picture picture = new Picture();
        Atlas atlas = atlasService.findOne(aid);
        User user = (User) session.getAttribute("user");
        picture.setAtlas(atlas);
        picture.setUser(user);
        picture.setCreateDate(new Date());
        picture.setTitle(title);
        pictureService.add(picture);

        String folder = "img/pictureDetail";
        File imageFolder= new File(request.getServletContext().getRealPath(folder));
        File file = new File(imageFolder,picture.getId()+".jpg");
        String fileName = file.getName();
        if(!file.getParentFile().exists())
            file.getParentFile().mkdirs();
        try {
            image.transferTo(file);
            BufferedImage img = ImageUtil.change2jpg(file);
            ImageIO.write(img, "jpg", file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String imageFolder_middle = request.getServletContext().getRealPath("img/pictureThumbnail");
        File f_middle = new File(imageFolder_middle, fileName);
        f_middle.getParentFile().mkdirs();
        ImageUtil.resizeImage(file, 56, 56, f_middle);
        return picture;
    }

    /*
    删除图片
     */
    @DeleteMapping("/pictures/{pid}")
    public String delete(@PathVariable("pid") int pid, HttpServletRequest request) {
        Picture picture = pictureService.findOne(pid);
        pictureService.delete(picture);
        //删除详情图片
        String folder = "img/pictureDetail";
        File  imageFolder= new File(request.getServletContext().getRealPath(folder));
        }
    }
}
package com.sxw.blog.web;

@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);
    }

    /*
    删除图集
            type.setBlogs(blogs);
        }

        return types;
    }

    /*
    一个分类下的文章信息
     */
    @GetMapping("/typeBlogs/{tid}")
    public List<Blog> listTypeBlogs(@PathVariable("tid") int tid) {
        return blogService.listByType(tid);
    }

    /*
    归档页 获取全部文章
     */
    @GetMapping("/blogsAll")
    public List<Blog> listAllBlogs() {
        return blogService.listAllBlog();
    }

    /*
    获取图集下的图片
     */
    @GetMapping("/atlasesPicture/{aid}")
    public Atlas pictures(@PathVariable("aid") int aid) {
        Atlas atlas = atlasService.findOne(aid);
        List<Picture> pictures = pictureService.list(aid);
        atlas.setPictures(pictures);
        return atlas;
    }

    /*
    获取查看数最多的十条文章
     */
    @GetMapping("/blogsTen")
    public List<Blog> listHotBlog() {
        return blogService.listBlog();
    }

    /*
    游客 评论
public class LogAspect {

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

    @Pointcut("execution(* com.sxw.blog.web.*.*(..))")
    public void log() {}

    @Before("log()")
    public void doBefore(JoinPoint joinPoint) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String url = request.getRequestURL().toString();
        String ip = request.getRemoteAddr();
        String classMethod = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        RequestLog requestLog = new RequestLog(url, ip, classMethod, args);
        logger.info("Request : {}", requestLog);
    }

    @After("log()")
    public void doAfter() {
//        logger.info("--------doAfter--------");
    }

    @AfterReturning(returning = "result",pointcut = "log()")
    public void doAfterRuturn(Object result) {
        logger.info("Result : {}", result);
    }

    private class RequestLog {
        private String url;
        private String ip;
        private String classMethod;
        private Object[] args;

        public RequestLog(String url, String ip, String classMethod, Object[] args) {
            this.url = url;
            this.ip = ip;
            this.classMethod = classMethod;
            this.args = args;
        }

        @Override
        public String toString() {
@Controller
public class ForePageController {

    @GetMapping(value = "fore_blog_list")
    public String questionList() {
        return "fore/blog";
    }

    @GetMapping(value = "fore_blog_type")
    public String questionType() {
        return "fore/blogType";
    }

    @GetMapping(value = "fore_blog_author")
    public String authorPage() {
        return "fore/authorPage";
    }

    @GetMapping(value = "fore_blog_detail")
    public String questionDetail() {
        return "fore/blogDetail";
    }

    @GetMapping(value = "fore_question_travel")
    public String questionTravel() {
        return "fore/questionTravel";
    }

    @GetMapping(value = "fore_travel_photo")
    public String travelPhoto() {
        return "fore/travelPhoto";
    }

    @GetMapping(value = "fore_time_axis")
    public String timeAxis() {
        return "fore/timeAxis";
    }

    @GetMapping("fore_blog_search")
    public String searchBlog() {
        return "fore/blogSearchResult";
    }
    public void log() {}

    @Before("log()")
    public void doBefore(JoinPoint joinPoint) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String url = request.getRequestURL().toString();
        String ip = request.getRemoteAddr();
        String classMethod = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        RequestLog requestLog = new RequestLog(url, ip, classMethod, args);
        logger.info("Request : {}", requestLog);
    }

    @After("log()")
    public void doAfter() {
//        logger.info("--------doAfter--------");
    }

    @AfterReturning(returning = "result",pointcut = "log()")
    public void doAfterRuturn(Object result) {
        logger.info("Result : {}", result);
    }

    private class RequestLog {
        private String url;
        private String ip;
        private String classMethod;
        private Object[] args;

        public RequestLog(String url, String ip, String classMethod, Object[] args) {
            this.url = url;
            this.ip = ip;
            this.classMethod = classMethod;
            this.args = args;
        }

        @Override
        public String toString() {
            return "{" +
                    "url='" + url + '\'' +
                    ", ip='" + ip + '\'' +

@Aspect
@Component
public class LogAspect {

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

    @Pointcut("execution(* com.sxw.blog.web.*.*(..))")
    public void log() {}

    @Before("log()")
    public void doBefore(JoinPoint joinPoint) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String url = request.getRequestURL().toString();
        String ip = request.getRemoteAddr();
        String classMethod = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        RequestLog requestLog = new RequestLog(url, ip, classMethod, args);
        logger.info("Request : {}", requestLog);
    }

    @After("log()")
    public void doAfter() {
//        logger.info("--------doAfter--------");
    }

    @AfterReturning(returning = "result",pointcut = "log()")
    public void doAfterRuturn(Object result) {
        logger.info("Result : {}", result);
    }

    private class RequestLog {
        private String url;
        private String ip;
        private String classMethod;
        private Object[] args;

        public RequestLog(String url, String ip, String classMethod, Object[] args) {
            this.url = url;
            this.ip = ip;
            this.classMethod = classMethod;
            this.args = args;
        }
    @GetMapping("/atlases")
    public Atlas getRecentlyAtlas() {
        Atlas atlas = atlasService.getRecentlyAtlas();
        int aid = atlas.getId();
        List<Picture> pictures = pictureService.list(aid);
        atlas.setPictures(pictures);
        return atlas;
    }

    /*
    获取全部图集
     */
    @GetMapping("/atlases/all")
    public List<Atlas> listAll() {
        List<Atlas> atlases = atlasService.listAllOrderByCreateTime();
        for(Atlas atlas: atlases) {
            List<Picture> pictures = atlas.getPictures();
            atlas.setPictures(pictures);
            atlas.setFirstPictureID(pictures.get(0).getId());
        }
        return atlases;
    }

}
package com.sxw.blog.web;

@Controller
public class AdminPageController {

    @GetMapping(value = "admin_login")
    public String adminLogin() {
        return "admin/login";
    }

    @GetMapping(value = "admin_logout")
    public String adminLogout(HttpSession session) {
        session.removeAttribute("user");
        return "redirect:admin_login";
    }

    @GetMapping(value = "admin_index")
    public String adminIndex() {
        return "admin/index";
    }

    @GetMapping(value = "admin_blog_list")
    public String blogList() {
     */
    @GetMapping("/types/{tid}")
    public Type findOne(@PathVariable("tid") int tid) {
        return typeService.findOne(tid);
    }

    /*
    修改分类
     */
    @PutMapping("/types/{tid}")
    public void updateType(@PathVariable("tid") int tid, @RequestParam("name") String name) {
        Type type = typeService.findOne(tid);
        type.setName(name);
        System.out.println(type.toString());
        typeService.update(type);
    }

    /*
    删除分类
     */
    @DeleteMapping("/types/{tid}")
    public String delete(@PathVariable("tid") int tid) {
        typeService.delete(tid);
        return null;
    }

}
package com.sxw.blog.web;

@RestController
public class AuthorController {

    @Autowired
    AuthorService authorService;
    @Autowired
    UserService userService;

    @GetMapping("/authors")
    public Author get(HttpSession session) {
        User user = (User) session.getAttribute("user");
        return authorService.findOne(user.getId());
                    ", args=" + Arrays.toString(args) +
                    '}';
        }
    }
}
package com.sxw.blog.web;

@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);
    }

    /*
    修改图集

请添加图片描述

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值