文本----富文本数据如何存入到数据库当中,解决方法,看其他大佬写的文章

简介: 文本----富文本数据如何存入到数据库当中,解决方法,看其他大佬写的文章

搜富文本数据如何存入到数据库当中

想要的效果,点击标题能够提交数据:

这里能够存入到数据库当中:

解决方法是看资料,第一步先定义数据模型

实战篇-81_大事件_添加文章_接口调用_哔哩哔哩_bilibili

第二步:先定义好数据模型

第三步:参考文章管理接口编写内容

第四步:添加文章数据接口

第五步:接口自己之前编写的不一样,应该要编写成这样

第六步:按照接口的名字进行导入

第七步组件进行导入

相关资料后端接口资料:

content类

package worldtolingyidianke.file.bean;
import lombok.Data;
@Data
public class Content {
    private Integer id;//主键ID
    private String title;//分类别名
    private String content;//文章内容
}

Controller层

package worldtolingyidianke.file.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import worldtolingyidianke.file.bean.Content;
import worldtolingyidianke.file.bean.Result;
import worldtolingyidianke.file.service.CategoryService;
import worldtolingyidianke.file.service.ContentService;
 
import javax.servlet.http.HttpServletResponse;
 
@RestController
@RequestMapping("/content")
@CrossOrigin
public class ContentController {
    @Autowired
    private ContentService contentService;
    @PostMapping("/article")
//    public Result<String> list(){
//        return Result.success("所有的文章数据");
//    }
    public Result content(@RequestBody Content content){
//         调用方法,添加
        contentService.content(content);
        return Result.success();
    }
}

ContentMapper的资料

package worldtolingyidianke.file.mappers;
 
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import worldtolingyidianke.file.bean.Content;
 
@Mapper
public interface ContentMapper {
    // 根据用户名进行添加,
    @Insert("insert into content(title,content)" +
            " values(#{title},#{content})")
    void add(Content content);
}

impl的类:

package worldtolingyidianke.file.service.impl;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import worldtolingyidianke.file.bean.Content;
import worldtolingyidianke.file.mappers.ContentMapper;
import worldtolingyidianke.file.service.ContentService;
 
 
@Service
public class ContentServiceImpl implements ContentService {
    @Autowired
    private ContentMapper contentMapper;
    @Override
    public void content(Content content){
        contentMapper.add(content);
    }
}

contentSerivce

package worldtolingyidianke.file.service;
 
import worldtolingyidianke.file.bean.Content;
 
public interface ContentService {
    void content(Content content);
}

前端组件:

<template>
    <div class="editorContainer">
        <el-form ref="ruleFormRef" style="max-width: 900px" :model="ruleForm" :rules="rules" label-width="auto"
            class="demo-ruleForm" :size="formSize" status-icon>
            <el-form-item label="标题" prop="name">
                <el-input v-model="articleData.title" />
            </el-form-item>
            <div class="editorContent">
                <div class="leftcontentContainer">内容</div>
                <div class="editor">
                    <quill-editor content-type='html' v-model:content='articleData.content' :options='options'
                        @blur='editorBlur($event)' />
                    <!-- <quill-editor content-type='html' :content='content' :options='options'
                        @blur='editorBlur($event)' /> -->
                    <!-- <quill-editor content-type='html' :content='content' :options='options'
                        @blur='editorBlur($event)' /> -->
                </div>
            </div>
            <div class="mb-4">
                <el-button round>保存</el-button>
                <el-button type="primary" round @click="addArticle">提交</el-button>
            </div>
        </el-form>
    </div>
</template>
 
<script setup>
import { ref } from 'vue';
import { contentService } from '@/api/content.js'
import { ElMessage } from 'element-plus';
const articleData = ref({
    title: '',
    content: ''
})
 
const addArticle = async () => {
    let result = await contentService(articleData.value);
    ElMessage.success(result.msg ? result.msg : '添加成功')
}
// let content = ref("<p> 初始内容。。。</p>");
let options = {
    modules: {
        toolbar: [
            ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线
            [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
            [{ align: [] }], // 对齐方式
            [{ size: ['small', false, 'large', 'huge'] }], // 字体大小
            [{ font: [] }], // 字体种类
            [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
            [{ direction: 'ltl' }], // 文本方向
            [{ direction: 'rtl' }], // 文本方向
            [{ indent: '-1' }, { indent: '+1' }], // 缩进
            [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表
            [{ script: 'sub' }, { script: 'super' }], // 上标/下标
            ['blockquote', 'code-block'], // 引用  代码块
            ['clean'], // 清除文本格式
            ['link', 'image', 'video'], // 链接、图片、视频
        ],
    },
};
 
</script>
<script>
 
</script>
<style lang="less">
.demo-ruleForm {
    margin: 0 auto;
}
 
.div span {
    text-align: left;
}
 
.editorContent {
    display: flex;
}
 
.editorContainer {
    margin-top: 15px;
}
 
.leftcontentContainer {
    margin-right: 9px;
}
 
.editor {
    width: 857px;
    margin-bottom: 60px;
}
 
.ql-container {
    height: 400px;
}
 
.demo-ruleForm {
    width: 1000px;
}
 
.mb-4 button {
    margin: 0 0 0 760px;
}
</style>

until的工具类

import axios from "axios";
import { ElMessage } from "element-plus";
 
const baseURL = '/api';
const instance = axios.create({
    baseURL: baseURL
});
import { useTokenStore } from '@/stores/token.js'
//添加请求拦截器
instance.interceptors.request.use(
    (config) => {
        //请求前的回调
        //添加token
        const tokenStore = useTokenStore();
        //判断有没有token
        if (tokenStore.token) {
            config.headers.Authorization = tokenStore.token
        }
        return config;
    },
    (err) => {
        //请求错误的回调
        Promise.reject(err)
    }
)
instance.interceptors.response.use(
    result => {
        // 判断业务状态代码
        if (result.data.code === 0) {
            return result.data;
        }
        // 操作失败
        // alert(result.data.msg ? result.data.msg : '服务异常')
        ElMessage.error(result.data.msg ? result.data.msg : '服务异常')
        return Promise.reject(result.data)
    },
    err => {
        alert('服务异常');
        return Promise.reject(err);
    }
)
// 导出axios自定义函数
export default instance

contentAPI的接口

// 导入request.js工具
import request from '@/utils/request.js'
// 提供调用注册接口的函数
export const contentService = (articleData) => {
    // 借助于ContentService完成传递
    return request.post('/content/article', articleData)
}
相关文章
|
6月前
|
数据采集 关系型数据库 MySQL
python爬取数据存入数据库
Python爬虫结合Scrapy与SQLAlchemy,实现高效数据采集并存入MySQL/PostgreSQL/SQLite。通过ORM映射、连接池优化与批量提交,支持百万级数据高速写入,具备良好的可扩展性与稳定性。
|
7月前
|
存储 数据管理 数据库
数据字典是什么?和数据库、数据仓库有什么关系?
在数据处理中,你是否常困惑于字段含义、指标计算或数据来源?数据字典正是解答这些问题的关键工具,它清晰定义数据的名称、类型、来源、计算方式等,服务于开发者、分析师和数据管理者。本文详解数据字典的定义、组成及其与数据库、数据仓库的关系,助你夯实数据基础。
数据字典是什么?和数据库、数据仓库有什么关系?
|
6月前
|
人工智能 Java 关系型数据库
使用数据连接池进行数据库操作
使用数据连接池进行数据库操作
191 11
|
7月前
|
存储 关系型数据库 数据库
【赵渝强老师】PostgreSQL数据库的WAL日志与数据写入的过程
PostgreSQL中的WAL(预写日志)是保证数据完整性的关键技术。在数据修改前,系统会先将日志写入WAL,确保宕机时可通过日志恢复数据。它减少了磁盘I/O,提升了性能,并支持手动切换日志文件。WAL文件默认存储在pg_wal目录下,采用16进制命名规则。此外,PostgreSQL提供pg_waldump工具解析日志内容。
718 0
|
6月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
480 158
|
6月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
6月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
1143 152
|
6月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
878 156
|
6月前
|
缓存 监控 关系型数据库
使用MYSQL Report分析数据库性能(中)
使用MYSQL Report分析数据库性能
483 156

热门文章

最新文章