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

基于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等等


@RestController
public class BlogController {

    @Autowired
    BlogService blogService;
    @Autowired
    TypeService typeService;

    /*
    增加博客
     */
    @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);

@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;
     */
    @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() {
        return "admin/blogList";
    }

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

    public List<Blog> listHotBlog() {
        return blogService.listBlog();
    }

    /*
    游客 评论
     */
    @PostMapping("/commentWeb")
    public void addComet(HttpServletRequest request) {
        String nickname = request.getParameter("nickname");
        String email = request.getParameter("email");
        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 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);
        }

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

}

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);
        if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
            throw e;
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("url",request.getRequestURL());
        mv.addObject("exception", e);
        mv.setViewName("error/error");
        return mv;
    }
}
package com.sxw.blog.web;

@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() {
    }

    @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() {
        return "admin/typeEdit";
    }

    @GetMapping(value = "admin_atlas_list")
    public String photoManager() {
        return "admin/atlasList";
    }

    @GetMapping(value = "admin_atlas_input")
    public String photoInput() {
        return "admin/atlasInput";
    }

    @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";

@RestController
public class ForeRESTController {

    @Autowired
    BlogService blogService;
    @Autowired
    TypeService typeService;
    @Autowired
    AtlasService atlasService;
    @Autowired
    PictureService pictureService;
    @Autowired
    CommentService commentService;
    @Autowired
    ReplyService replyService;

    @GetMapping("/search")
    public List<Blog> list(@RequestParam("keyword") String keyword, @RequestParam("tid") int tid) {
        return blogService.search(keyword,tid);
    }

    /*
    获取分类进行分页
     */
    @GetMapping("/typesPage")
    public Page4Navigator<Type> listType(@RequestParam(value = "start", defaultValue = "0") int start,
                                     @RequestParam(value = "size", defaultValue = "10") int size) {
}
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);
        mv.setViewName("error/error");
        return mv;
    }
}
package com.sxw.blog.web;

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

        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 + '\'' +
                    ", classMethod='" + classMethod + '\'' +
                    ", 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);
    }
@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);
    }

    /*
    删除图集
     */
    @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();

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);
    }
}
package com.sxw.blog.web;


@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);
        mv.setViewName("error/error");
        return mv;
    }
}
package com.sxw.blog.web;

@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";
    }
@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);
        mv.setViewName("error/error");
        return mv;
    }
}
package com.sxw.blog.web;

@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")
    @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() {
        return "admin/typeEdit";
    }

    @GetMapping(value = "admin_atlas_list")
    public String photoManager() {
        return "admin/atlasList";
    }

    @GetMapping(value = "admin_atlas_input")
    public String photoInput() {
        return "admin/atlasInput";
    }

    @GetMapping(value = "admin_atlas_edit")
    public String atlasEdit() {
            List<Blog> blogs = blogService.listByTypeBlogs(type.getId());
            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();
    }

    /*
    游客 评论
     */
    @PostMapping("/commentWeb")
    public void addComet(HttpServletRequest request) {
        String nickname = request.getParameter("nickname");
        String email = request.getParameter("email");
        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);
    }

    /*
    删除图集
     */
    @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;
    }

    /*
    获取全部图集
     */
    @GetMapping("/atlases/all")
    public List<Atlas> listAll() {
        List<Atlas> atlases = atlasService.listAllOrderByCreateTime();

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


@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);
        mv.setViewName("error/error");
        return mv;
    }
}
package com.sxw.blog.web;

@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() {

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

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

    }

    /*
    获取分类进行分页
     */
    @GetMapping("/typesPage")
    public Page4Navigator<Type> listType(@RequestParam(value = "start", defaultValue = "0") int start,
                                     @RequestParam(value = "size", defaultValue = "10") int size) {
        start = start<0?0:start;
        return typeService.list(start, size, 5);  //5表示导航分页最多有5个,像 [1,2,3,4,5] 这样
    }

    /*
    获取图集进行分页
     */
    @GetMapping("/atlasesPage")
    public Page4Navigator<Atlas> listAtlas(@RequestParam(value = "start", defaultValue = "0") int start,
                                      @RequestParam(value = "size", defaultValue = "5") int size) {
        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) {

@RestController
public class BlogController {

    @Autowired
    BlogService blogService;
    @Autowired
    TypeService typeService;

    /*
    增加博客
     */
    @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;
//        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 + '\'' +
                    ", classMethod='" + classMethod + '\'' +
                    ", args=" + Arrays.toString(args) +
                    '}';
        }
    }
}
package com.sxw.blog.web;

                    ", ip='" + ip + '\'' +
                    ", classMethod='" + classMethod + '\'' +
                    ", 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);
    }

    /*
    修改图集
     */
    @PutMapping("/atlases/{tid}")
    public void updateType(@PathVariable("tid") int tid, @RequestParam("name") String name) {

请添加图片描述

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值