Java之Spring Boot+Vue+Element UI前后端分离项目(中-功能完善-实现查询) 【博客论坛项目高仿CSDN

},

created() {//编写构造函数

this.getInfo();

},

methods: {

getInfo() {

this.$axios.get(‘http://localhost:9090/blog/queryBlogByPage?title=’ + this.title + ‘&page=’ + this.page + ‘&rows=’ + this.rows)

.then(response => (

this.info = response.data,

this.total = this.info.total,

this.totalPage = this.info.totalPage,

this.items = this.info.items

)).catch(function (error) { // 请求失败处理

console.log(error);

});

},

current_change:function(currentPage){

this.page = currentPage;

this.getInfo();

}

},

watch: {

page: function () {

this.getInfo();

},

rows: function () {

this.getInfo();

},

}

}

访问http://localhost:8080/#/

在这里插入图片描述

点击翻页

在这里插入图片描述

三 、实现查询博客详情(后端功能实现)


1、修改BlogArticle

在这里插入图片描述

package cn.itbluebox.springbootcsdn.domain;

import lombok.AllArgsConstructor;

import lombok.Data;

import lombok.NoArgsConstructor;

import javax.persistence.Table;

import java.util.Date;

@Data

@NoArgsConstructor

@AllArgsConstructor

@Table(name = “blog_article”)

public class BlogArticle extends Blog{

private Long id;

private String context;

private Date last_update_time; //更新时间

private Character is_original;

}

2、完善BlogController实现通过id查询

在这里插入图片描述

@GetMapping(“queryBlogArticleById”)

public ResponseEntity queryBlogById(

@RequestParam(value = “id”) Long id

) {

return ResponseEntity.ok(blogService.queryBlogArticleById(id));

}

3、完善BlogService以及BlogServiceImpl

BlogService

在这里插入图片描述

在这里插入图片描述

package cn.itbluebox.springbootcsdn.service;

import cn.itbluebox.springbootcsdn.domain.Blog;

import cn.itbluebox.springbootcsdn.domain.BlogArticle;

import cn.itbluebox.springbootcsdn.vo.PageResult;

public interface BlogService {

PageResult queryBlogByPage(String title, Integer page, Integer rows);

BlogArticle queryBlogArticleById(Long id);

}

BlogServiceImpl

在这里插入图片描述

@Override

public BlogArticle queryBlogArticleById(Long id) {

return blogArticleMapper.queryBlogArticleById(id);

}

4、完善BlogArticleMapper

在这里插入图片描述

在这里插入图片描述

package cn.itbluebox.springbootcsdn.mapper;

import cn.itbluebox.springbootcsdn.domain.BlogArticle;

import org.apache.ibatis.annotations.Select;

import tk.mybatis.mapper.common.Mapper;

public interface BlogArticleMapper extends Mapper {

@Select(“select * from blog_article ba LEFT JOIN blog b on ba.id = b.blog_article_id where ba.id = #{id} LIMIT 0,1”)

BlogArticle queryBlogArticleById(Long id);

}

5、运行测试

在这里插入图片描述

访问:http://localhost:9090/blog/queryBlogArticleById?id=1

在这里插入图片描述

三 、实现查询博客详情(前端功能实现)


1、在HelloWorld.vue当中设置跳转页面的方法并携带参数

在这里插入图片描述

open(row) {

this.$router.push(“/Article?” + row.blog_article_id);

},

2、创建Article.vue

(1)实现通过id查询对应的详细内容

在这里插入图片描述

浏览量:

点赞数:

<img height=“50” @click=“like” src=“https://img2.baidu.com/it/u=966753824,2436291344&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500”>

(2)在router下的index.js当中设置页面跳转路径

在这里插入图片描述

import Vue from ‘vue’

import Router from ‘vue-router’

import HelloWorld from ‘@/components/HelloWorld’

import Article from ‘@/components/Article’

Vue.use(Router)

export default new Router({

routes: [

{

path: ‘/’,

name: ‘HelloWorld’,

component: HelloWorld

},

{

path: ‘/Article’,

name: ‘Article’,

component: Article

},

]

})

(3)点击测试

在这里插入图片描述

在这里插入图片描述

3、实现浏览量增加

实现浏览量的增加

(1)修改BlogController

在这里插入图片描述

@GetMapping(“queryBlogArticleById”)

public ResponseEntity queryBlogById(

@RequestParam(value = “id”) Long id

) {

//查询当前id 对应的博客信息

BlogArticle blogArticle = blogService.queryBlogArticleById(id);

Blog blog = blogService.queryBlogById(blogArticle.getId());

Long view_count = blog.getView_count();

//将访问量查询并自增后重新设置值

view_count = view_count + 1;

blog.setView_count(view_count);

//更新数据库大当中的值

blogService.updateBlog(blog);

return ResponseEntity.ok(blogArticle);

}

(2)对应的实现的查询和更新的接口和实现类

在这里插入图片描述

Blog queryBlogById(Long id);

void updateBlog(Blog blog);

在这里插入图片描述

@Override

public Blog queryBlogById(Long id) {

return blogMapper.queryBlogById(id);

}

@Transactional(rollbackFor = Exception.class)

public void updateBlog(Blog blog) {

blogMapper.updateByView(blog);

}

(2)对应的BlogMapper

在这里插入图片描述

@Select(“select * from blog where id = #{id} limit 0,1”)

Blog queryBlogById(Long id);

@Update(“UPDATE blog set view_count = #{view_count} WHERE id = #{id}”)

void updateByView(Blog blog);

4、实现点赞

(1)完善Article.vue设置事件和请求方式

在这里插入图片描述

对应的方法

在这里插入图片描述

放置手残实现全部代码

浏览量:

点赞数:

<img height=“50” @click=“like” src=“https://img2.baidu.com/it/u=966753824,2436291344&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500”>

  • 25
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
本文介绍了一个基于Spring BootSpring Cloud和Vue前后端分离项目实战。这个项目是一个简单的在线商城,包含了用户注册、登录、商品展示、购物车、订单管理等功能。通过这个项目,读者可以深入理解前后端分离的架构模式和互联网应用的开发方式。 首先,文章介绍了前后端分离的基本概念和优势。前后端分离是将应用的前端和后端代码分开来开发,使得前端和后端具有独立的开发周期和技术栈,进而提高了开发效率和代码质量。同时,前后端分离还可以提供更好的用户体验和灵活性,对于互联网应用来说尤为重要。 接下来,文章介绍了项目的架构和技术栈。项目采用了Spring BootSpring Cloud框架来实现后端代码,采用MyBatis作为ORM框架和Redis作为缓存间件。同时,项目还采用了Vue.js作为前端框架和Element UI组件库来实现前端页面。通过这些开源框架和组件,可以快速搭建一个前后端分离的互联网应用。 然后,文章介绍了项目的核心功能和代码实现。在用户注册和登录方面,项目采用了Spring Security框架和JWT令牌来实现用户认证和授权,保证了用户信息的安全性。在商品展示和购物车方面,项目采用了Vue.js实现前端页面和事件处理。在订单管理方面,项目采用了MyBatis Plus来实现订单数据的持久化和分页查询。 最后,文章介绍了项目的测试和优化。通过对项目的压力测试和性能测试,文章发现项目还存在一些性能瓶颈和安全隐患,可以通过优化数据库查询、缓存配置和代码实现来提高应用的性能和安全性。 总之,这篇文章介绍了一个基于Spring BootSpring Cloud和Vue前后端分离项目实战,通过实现一个在线商城的功能,展示了前后端分离的开发模式和互联网应用的开发技术栈。本文可以作为前后端分离开发的入门教程,也可以作为互联网应用开发的参考文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值