最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于SpringBoot和Vue3的博客平臺(tái)發(fā)布、編輯、刪除文章功能實(shí)現(xiàn)

 更新時(shí)間:2023年04月11日 09:43:41   作者:SYBH.  
在上一個(gè)教程中,我們已經(jīng)實(shí)現(xiàn)了基于Spring?Boot和Vue3的用戶注冊(cè)與登錄功能。本教程將繼續(xù)引導(dǎo)您實(shí)現(xiàn)博客平臺(tái)的發(fā)布、編輯、刪除文章功能,需要的朋友參考一下

在上一個(gè)教程中,我們已經(jīng)實(shí)現(xiàn)了基于Spring Boot和Vue3的用戶注冊(cè)與登錄功能。本教程將繼續(xù)引導(dǎo)您實(shí)現(xiàn)博客平臺(tái)的發(fā)布、編輯、刪除文章功能。

在這個(gè)博客教程中,我們實(shí)現(xiàn)了基于Spring Boot和Vue3的發(fā)布、編輯、刪除文章功能。整個(gè)實(shí)現(xiàn)過(guò)程可以分為以下幾個(gè)步驟:

  1. 后端Spring Boot實(shí)現(xiàn) 1.1. 創(chuàng)建Article實(shí)體類:定義文章的數(shù)據(jù)結(jié)構(gòu)。 1.2. 創(chuàng)建ArticleMapper接口:定義與數(shù)據(jù)庫(kù)交互的操作。 1.3. 創(chuàng)建ArticleService接口及其實(shí)現(xiàn):提供具體的業(yè)務(wù)邏輯,如查詢、創(chuàng)建、更新和刪除文章。 1.4. 創(chuàng)建ArticleController類:定義RESTful API接口,處理HTTP請(qǐng)求和響應(yīng)。
  2. 前端Vue3實(shí)現(xiàn) 2.1. 創(chuàng)建文章列表頁(yè)面組件:展示所有文章列表,以及編輯和刪除文章的操作按鈕。 2.2. 創(chuàng)建文章發(fā)布頁(yè)面組件:提供一個(gè)表單供用戶輸入文章標(biāo)題和內(nèi)容,以發(fā)布新文章。 2.3. 創(chuàng)建文章編輯頁(yè)面組件:提供一個(gè)表單顯示選定文章的標(biāo)題和內(nèi)容,允許用戶編輯并更新文章。

在這個(gè)過(guò)程中,我們首先實(shí)現(xiàn)了后端Spring Boot應(yīng)用程序,負(fù)責(zé)處理數(shù)據(jù)庫(kù)操作和提供API接口。然后,我們實(shí)現(xiàn)了前端Vue3應(yīng)用程序,提供用戶界面以展示文章列表、發(fā)布新文章和編輯現(xiàn)有文章。通過(guò)這種方式,我們實(shí)現(xiàn)了一個(gè)簡(jiǎn)單的博客平臺(tái),具有發(fā)布、編輯和刪除文章的功能。

1. 后端Spring Boot實(shí)現(xiàn)

我們將使用Spring Boot作為后端框架,并使用MySQL作為數(shù)據(jù)庫(kù)。

1.1 創(chuàng)建Article實(shí)體類

首先,在com.example.demo.entity包下創(chuàng)建一個(gè)名為Article.java的新類,并添加以下內(nèi)容:

public class Article {
    private Integer id;
    private String title;
    private String content;
    private Integer authorId;
 
    // Getter and Setter methods
}

1.2 創(chuàng)建ArticleMapper接口

com.example.demo.mapper包下創(chuàng)建一個(gè)名為ArticleMapper.java的新接口,并添加以下內(nèi)容:

@Mapper
public interface ArticleMapper {
    List<Article> findAll();
    Article findById(Integer id);
    void insert(Article article);
    void update(Article article);
    void delete(Integer id);
}

com.example.demo.service.impl包下創(chuàng)建一個(gè)名為ArticleServiceImpl.java的新類,并添加以下內(nèi)容:

@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;
 
    @Override
    public List<Article> findAll() {
        return articleMapper.findAll();
    }
 
    @Override
    public Article findById(Integer id) {
        return articleMapper.findById(id);
    }
 
    @Override
    public void create(Article article) {
        articleMapper.insert(article);
    }
 
    @Override
    public void update(Article article) {
        articleMapper.update(article);
    }
 
    @Override
    public void delete(Integer id) {
        articleMapper.delete(id);
    }
}

1.3創(chuàng)建ArticleController類

com.example.demo.controller包下創(chuàng)建一個(gè)名為ArticleController.java的新類,并添加以下內(nèi)容:

@RestController
@RequestMapping("/api/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
 
    @GetMapping
    public List<Article> list() {
        return articleService.findAll();
    }
 
    @GetMapping("/{id}")
    public Article detail(@PathVariable Integer id) {
        return articleService.findById(id);
    }
 
    @PostMapping
    public Result create(@RequestBody Article article) {
        articleService.create(article);
        return Result.success("文章發(fā)布成功");
    }
 
    @PutMapping("/{id}")
    public Result update(@PathVariable Integer id, @RequestBody Article article) {
        article.setId(id);
        articleService.update(article);
        return Result.success("文章更新成功");
    }
 
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        articleService.delete(id);
        return Result.success("文章刪除成功");
    }
}

至此,我們已經(jīng)完成了后端的發(fā)布、編輯、刪除文章功能。

2. 前端Vue3實(shí)現(xiàn)

2.1 創(chuàng)建文章列表頁(yè)面組件

src/views目錄下創(chuàng)建一個(gè)名為ArticleList.vue的新組件,并添加以下內(nèi)容:

<template>
  <div>
    <el-table :data="articles">
      <el-table-column prop="id" label="ID" width="80"></el-table-column>
      <el-table-column prop="title" label="標(biāo)題"></el-table-column>
      <el-table-column label="操作" width="180">
        <template v-slot="{ row }">
          <el-button @click="editArticle(row.id)">編輯</el-button>
          <el-button type="danger" @click="deleteArticle(row.id)">刪除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
 
<script>
import { ref } from "vue";
import axios from "axios";
 
export default {
  setup() {
    const articles = ref([]);
 
    const fetchArticles = async () => {
      const response = await axios.get("/api/article");
      articles.value = response.data;
    };
 
    const editArticle = (id) => {
      // 跳轉(zhuǎn)到編輯頁(yè)面
    };
 
    const deleteArticle = async (id) => {
      await axios.delete(`/api/article/${id}`);
      fetchArticles();
    };
 
    fetchArticles();
 
    return { articles, editArticle, deleteArticle };
  },
};
</script>

2.2 創(chuàng)建文章發(fā)布頁(yè)面組件

src/views目錄下創(chuàng)建一個(gè)名為CreateArticle.vue的新組件,并添加以下內(nèi)容:

<template>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="標(biāo)題" prop="title">
      <el-input v-model="form.title"></el-input>
    </el-form-item>
    <el-form-item label="內(nèi)容" prop="content">
      <el-input type="textarea" v-model="form.content"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('form')">發(fā)布文章</el-button>
    </el-form-item>
  </el-form>
</template>
 
<script>
import { reactive } from "vue";
import axios from "axios";
 
export default {
  setup() {
    const form = reactive({ title: "", content: "" });
 
    const submitForm = async () => {
      try {
        await axios.post("/api/article", form);
        alert("文章發(fā)布成功");
      } catch (error) {
        alert("文章發(fā)布失敗");
      }
    };
 
    return { form, submitForm };
  },
};
</script>

2.3 創(chuàng)建文章編輯頁(yè)面組件

src/views目錄下創(chuàng)建一個(gè)名為EditArticle.vue的新組件,并添加以下內(nèi)容:

<template>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="標(biāo)題" prop="title">
      <el-input v-model="form.title"></el-input>
    </el-form-item>
    <el-form-item label="內(nèi)容" prop="content">
      <el-input type="textarea" v-model="form.content"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm">更新文章</el-button>
    </el-form-item>
  </el-form>
</template>
 
<script>
import { ref, reactive, onMounted } from "vue";
import axios from "axios";
 
export default {
  props: {
    id: {
      type: Number,
      required: true,
    },
  },
  setup(props) {
    const form = reactive({ title: "", content: "" });
 
    const fetchArticle = async () => {
      const response = await axios.get(`/api/article/${props.id}`);
      form.title = response.data.title;
      form.content = response.data.content;
    };
 
    const submitForm = async () => {
      try {
        await axios.put(`/api/article/${props.id}`, form);
        alert("文章更新成功");
      } catch (error) {
        alert("文章更新失敗");
      }
    };
 
    onMounted(fetchArticle);
 
    return { form, submitForm };
  },
};
</script>

這段代碼定義了一個(gè)名為EditArticle.vue的新組件,該組件需要一個(gè)名為id的屬性。組件加載時(shí),會(huì)調(diào)用fetchArticle函數(shù)獲取文章信息并填充到表單中。點(diǎn)擊"更新文章"按鈕時(shí),會(huì)調(diào)用submitForm函數(shù),將表單數(shù)據(jù)發(fā)送到后端以更新文章。

現(xiàn)在,您已經(jīng)完成了基于Spring Boot和Vue3的發(fā)布、編輯、刪除文章功能的實(shí)現(xiàn)。您可以根據(jù)需要對(duì)這些功能進(jìn)行進(jìn)一步的優(yōu)化和擴(kuò)展。希望本教程對(duì)您有所幫助!

以上就是基于Spring Boot和Vue3的博客平臺(tái)發(fā)布、編輯、刪除文章功能實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于Spring Boot Vue3平臺(tái)文章發(fā)布、編輯、刪除的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 基于SpringBoot實(shí)現(xiàn)防盜鏈功能

    基于SpringBoot實(shí)現(xiàn)防盜鏈功能

    防盜鏈?zhǔn)潜Wo(hù)資源服務(wù)器的常用方法,旨在防止未經(jīng)授權(quán)的外部鏈接直接訪問(wèn)服務(wù)器上的資源,如圖片、音頻和視頻文件,在本文中,我們將探討防盜鏈的概念和原理,并結(jié)合 Spring Boot 提供一個(gè)完整的可運(yùn)行示例,需要的朋友可以參考下
    2024-12-12
  • spring-boot整合ehcache實(shí)現(xiàn)緩存機(jī)制的方法

    spring-boot整合ehcache實(shí)現(xiàn)緩存機(jī)制的方法

    spring-boot是一個(gè)快速的集成框架,其設(shè)計(jì)目的是用來(lái)簡(jiǎn)化新Spring應(yīng)用的初始搭建以及開(kāi)發(fā)過(guò)程。這篇文章主要介紹了spring-boot整合ehcache實(shí)現(xiàn)緩存機(jī)制,需要的朋友可以參考下
    2018-01-01
  • 一文詳解Redisson分布式鎖底層實(shí)現(xiàn)原理

    一文詳解Redisson分布式鎖底層實(shí)現(xiàn)原理

    這篇文章主要詳細(xì)介紹了Redisson分布式鎖底層實(shí)現(xiàn)原理,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-07-07
  • Spring Boot 中使用cache緩存的方法

    Spring Boot 中使用cache緩存的方法

    Spring Cache是Spring針對(duì)Spring應(yīng)用,給出的一整套應(yīng)用緩存解決方案。下面小編給大家?guī)?lái)了Spring Boot 中使用cache緩存的方法,感興趣的朋友參考下吧
    2018-01-01
  • Java結(jié)構(gòu)型設(shè)計(jì)模式中建造者模式示例詳解

    Java結(jié)構(gòu)型設(shè)計(jì)模式中建造者模式示例詳解

    建造者模式,是一種對(duì)象構(gòu)建模式 它可以將復(fù)雜對(duì)象的建造過(guò)程抽象出來(lái),使這個(gè)抽象過(guò)程的不同實(shí)現(xiàn)方法可以構(gòu)造出不同表現(xiàn)的對(duì)象。本文將通過(guò)示例講解建造者模式,需要的可以參考一下
    2022-09-09
  • java實(shí)現(xiàn)二分法的完整代碼

    java實(shí)現(xiàn)二分法的完整代碼

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)二分法的完整代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • JSON.toJSONString()方法在Java中的使用方法及應(yīng)用場(chǎng)景

    JSON.toJSONString()方法在Java中的使用方法及應(yīng)用場(chǎng)景

    這篇文章主要給大家介紹了關(guān)于JSON.toJSONString()方法在Java中的使用方法及應(yīng)用場(chǎng)景,JSON.toJSONString是將對(duì)象轉(zhuǎn)化為Json字符串,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-04-04
  • java反射_改變private中的變量及方法的簡(jiǎn)單實(shí)例

    java反射_改變private中的變量及方法的簡(jiǎn)單實(shí)例

    下面小編就為大家?guī)?lái)一篇java反射_改變private中的變量及方法的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-06-06
  • Springboot2.0自適應(yīng)效果錯(cuò)誤響應(yīng)過(guò)程解析

    Springboot2.0自適應(yīng)效果錯(cuò)誤響應(yīng)過(guò)程解析

    這篇文章主要介紹了Springboot2.0自適應(yīng)效果錯(cuò)誤響應(yīng)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • 為何Java8需要引入新的日期與時(shí)間庫(kù)

    為何Java8需要引入新的日期與時(shí)間庫(kù)

    這篇文章主要給大家介紹了關(guān)于Java8為什么需要引入新的日期與時(shí)間庫(kù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11

最新評(píng)論

淄博市| 临泽县| 洪湖市| 天津市| 岳阳县| 紫金县| 炎陵县| 武隆县| 仁怀市| 巴塘县| 龙州县| 莱芜市| 仙游县| 杭锦后旗| 电白县| 那坡县| 武功县| 武穴市| 高邮市| 伊宁县| 富源县| 江川县| 怀远县| 东乡| 南岸区| 济源市| 城市| 理塘县| 牡丹江市| 高碑店市| 珠海市| 海兴县| 益阳市| 元江| 泉州市| 中卫市| 漳州市| 江口县| 津南区| 宜丰县| 布拖县|