Springboot+Vue实现发表文章功能

article/2025/10/28 9:31:17

点击上方[全栈开发者社区]右上角[...][设为星标⭐]

效果图

前端编辑页面


文章列表页面

文章详情页面

环境介绍

JDK:1.8

数据库:Mysql5.6

前端:Vue

后端:SpringBoot

核心代码介绍

AtricleCtrle.class

@RestController
@RequestMapping("/article")
@CrossOrigin
public class ArticleCtrler 
{@Autowiredprivate ArticleService articleService;@ApiOperation(value="添加文章")@PostMapping("/addarticle")public Object addarticle(@Valid Article vo){try {articleService.insert(vo); return Result.success(null);}catch (Exception e) {e.printStackTrace();}return Result.error(CodeMsg.SERVER_ERROR);}@PostMapping("/loadPage")@ApiOperation(value="文章分页列表")public Object loadPage(@Valid Article_Condit vo){try {PageInfo<Article> loadPage = articleService.loadPage(vo);return Result.success(loadPage);}catch (Exception e) {e.printStackTrace();}return Result.error(CodeMsg.SERVER_ERROR);}
}

ArticleService.interface

public interface ArticleService 
{void insert(Article vo);PageInfo<Article> loadPage(Article_Condit vo);
}

ArticleServiceImpl.class

@Service
@Transactional
public class ArticleServiceImpl implements ArticleService 
{@Autowiredprivate ArticleDao articleDao;@Overridepublic void insert(Article vo) 
{vo.setCreatedatetime(new Timestamp(new Date().getTime()));vo.setCreateuserid("system");articleDao.save(vo);}@Overridepublic PageInfo<Article> loadPage(Article_Condit vo) 
{PageHelper.startPage(vo.getPageIndex()==null?0:vo.getPageIndex(), vo.getPageSize()==null?0:vo.getPageSize());List<Article> findByCondit = articleDao.findByCondit(vo);return new PageInfo<Article>(findByCondit);}
}

ArticleDao.class

@Repository
public interface ArticleDao 
{void save(Article vo);List<Article> findByCondit(Article_Condit vo);
}

Helloworld.vue

@ApiModel(value="发布文章", description="发布文章")
public class Article implements Serializable
{private static final long serialVersionUID = 1L;@ApiModelProperty(value = "文章编号",hidden = true)private Long id;@ApiModelProperty(value = "文章标题",required = true)@NotBlank(message = "标题不能为空")private String title;@ApiModelProperty(value = "文章描述",required = true)@NotBlank(message = "文章描述不能为空")private String description;@ApiModelProperty(value = "文章内容",required = true)@NotBlank(message = "文章内容不能为空")private String content;@ApiModelProperty(value = "文章类型",required = false)private String articletype;@ApiModelProperty(value = "创建时间",hidden = true)@JsonFormat(pattern="yyyy-MM-dd HH:mm", timezone="GMT+8")private Timestamp createdatetime;@ApiModelProperty(value = "创建人",hidden = true)private String createuserid;public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getDescription() {return description;}public void setDescription(String description) {this.description = description;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}public Timestamp getCreatedatetime() {return createdatetime;}public void setCreatedatetime(Timestamp createdatetime) {this.createdatetime = createdatetime;}public String getCreateuserid() {return createuserid;}public void setCreateuserid(String createuserid) {this.createuserid = createuserid;}public String getArticletype() {return articletype;}public void setArticletype(String articletype) {this.articletype = articletype;}@Overridepublic String toString() {return "Article [id=" + id + ", title=" + title + ", description=" + description + ", content=" + content+ ", articletype=" + articletype + ", createdatetime=" + createdatetime + ", createuserid="+ createuserid + "]";}
}

articleMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yxyz.dao.ArticleDao"><insert id="save" parameterType="com.yxyz.vo.Article">insert into t_article(title,description,content,articletype,createdatetime,createuserid)values(#{title,jdbcType=VARCHAR},#{description,jdbcType=VARCHAR},#{content,jdbcType=LONGVARCHAR},#{articletype,jdbcType=VARCHAR},#{createdatetime,jdbcType=TIMESTAMP},#{createuserid,jdbcType=VARCHAR})</insert><select id="findByCondit" parameterType="com.yxyz.condit.Article_Condit" resultType="com.yxyz.vo.Article">select t1.* from t_article t1 where 1=1<if test="articletype != null and articletype !=''">and t1.articletype like concat('%',#{articletype},'%')</if><if test="createuserid != null and createuserid !=''">and t1.createuserid = #{createuserid}</if></select>
</mapper>

main.js

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'Vue.use(ElementUI)
Vue.config.productionTip = falsenew Vue({router,render: (h) => h(App),
}).$mount('#app')

About.vue

<template><div class><h3>编辑页面</h3><el-form ref="form" :model="form" label-width="80px"><el-form-item label="标题"><el-input v-model="form.title"></el-input></el-form-item><el-form-item label="描述"><el-input v-model="form.description"></el-input></el-form-item><el-form-item label="正文"><quill-editorref="myQuillEditor"class="editor"v-model="form.content":options="editorOption"@blur="onEditorBlur($event)"@focus="onEditorFocus($event)"@ready="onEditorReady($event)"/></el-form-item><el-button class="btn" block type="primary" @click="submit">提交</el-button></el-form></div>
</template><script>
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'import { quillEditor } from 'vue-quill-editor'
import axios from 'axios'
export default {components: { quillEditor },props: {},data() {return {form: {title: '',description: '',content: '',},editorOption: {modules: {toolbar: [['bold', 'italic', 'underline', 'strike'], //加粗,斜体,下划线,删除线['blockquote', 'code-block'], //引用,代码块[{ header: 1 }, { header: 2 }], // 标题,键值对的形式;1、2表示字体大小[{ list: 'ordered' }, { list: 'bullet' }], //列表[{ script: 'sub' }, { script: 'super' }], // 上下标[{ indent: '-1' }, { indent: '+1' }], // 缩进[{ direction: 'rtl' }], // 文本方向[{ size: ['small', false, 'large', 'huge'] }], // 字体大小[{ header: [1, 2, 3, 4, 5, 6, false] }], //几级标题[{ color: [] }, { background: [] }], // 字体颜色,字体背景颜色[{ font: [] }], //字体[{ align: [] }], //对齐方式['clean'], //清除字体样式// ['image', 'video'], //上传图片、上传视频],},theme: 'snow',},}},computed: {},created() {},mounted() {},watch: {},methods: {onEditorBlur(quill) {console.log('editor blur!', quill)},onEditorFocus(quill) {console.log('editor focus!', quill)},onEditorReady(quill) {console.log('editor ready!', quill)},submit() {if (!this.form.title) {this.$message('请输入标题')}if (!this.form.description) {this.$message('请输入描述')}if (!this.form.content) {this.$message('请输入正文')}let formData = new FormData()formData.append('title', this.form.title)formData.append('description', this.form.description)formData.append('content', this.form.content)// 发送 POST 请求axios({method: 'post',url: 'http://139.159.147.237:8080/yxyz/article/addarticle',data: formData,headers: {'Content-Type': 'application/x-www-form-urlencoded',},}).then(function(response) {if (res.code === 0) {this.$message('提交成功')}// this.form = {//   title: '',//   description: '',//   content: '',// }this.$router.goBack()}).catch(function(error) {console.log(error)})},},
}
</script><style scoped lang="less">
.editor {height: 500px;
}
.btn {margin-top: 100px;
}
</style>

Detail.vue

<template><div class=""><h2>文章详情</h2><el-card><div class="title">{{ detail.title }}</div><div class="des">{{ detail.description }}</div><div class="con" v-html="detail.content"></div><div class="time">{{ detail.createdatetime }}</div></el-card></div>
</template><script>
export default {components: {},props: {},data() {return {detail: {},}},computed: {},created() {console.log(this.$route)let item = this.$route.params.itemthis.detail = item},mounted() {},watch: {},methods: {},
}
</script><style scoped lang="less">
.title {font-weight: bold;font-size: 16px;text-align: left;margin-bottom: 10px;
}
.des {font-size: 14px;text-align: left;margin-bottom: 10px;
}
.con {font-size: 14px;text-align: left;margin-bottom: 10px;
}
.time {font-size: 14px;text-align: left;
}
</style>

Home.vue

<template><div class=""><h2>文章详情</h2><el-card><div class="title">{{ detail.title }}</div><div class="des">{{ detail.description }}</div><div class="con" v-html="detail.content"></div><div class="time">{{ detail.createdatetime }}</div></el-card></div>
</template><script>
export default {components: {},props: {},data() {return {detail: {},}},computed: {},created() {console.log(this.$route)let item = this.$route.params.itemthis.detail = item},mounted() {},watch: {},methods: {},
}
</script><style scoped lang="less">
.title {font-weight: bold;font-size: 16px;text-align: left;margin-bottom: 10px;
}
.des {font-size: 14px;text-align: left;margin-bottom: 10px;
}
.con {font-size: 14px;text-align: left;margin-bottom: 10px;
}
.time {font-size: 14px;text-align: left;
}
</style>

application.yml

spring:profiles:active: dev

application-dev.yml

server:port: 8080servlet:context-path: /yxyz
spring:datasource:name: yxyzurl: jdbc:mysql://localhost/test?serverTimezone=GMT%2b8&characterEncoding=UTF8username: rootpassword: 123# 使用druid数据源type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverfilters: statmaxActive: 20initialSize: 1maxWait: 60000minIdle: 1timeBetweenEvictionRunsMillis: 60000minEvictableIdleTimeMillis: 300000validationQuery: select 'x'testWhileIdle: truetestOnBorrow: falsetestOnReturn: falsepoolPreparedStatements: truemaxOpenPreparedStatements: 20
## 该配置节点为独立的节点
mybatis:mapper-locations: classpath:mapping/*Mapper.xml #注意:一定要对应mapper映射xml文件的所在路径type-aliases-package: com.yxyz.vo # 注意:对应实体类的路径
#打印sql最终填充的参数值log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
觉得本文对你有帮助?请分享给更多人关注「全栈开发者社区」加星标,提升全栈技能
本公众号会不定期给大家发福利,包括送书、学习资源等,敬请期待吧!
如果感觉推送内容不错,不妨右下角点个在看转发朋友圈或收藏,感谢支持。
好文章,留言、点赞、在看和分享一条龙吧❤️

http://chatgpt.dhexx.cn/article/ELgu2CMW.shtml

相关文章

使用hexo发布文章

前言: 如何用指令去创建一篇文章,然后发布? .我们先来看一下hexo的目录结构,了解每个目录的作用,这将让我们对hexo的运行原理有一个大概的认识,对于我们后面美化主题是有帮助的, 然后再来创建文章,并发布到本地服务器,最后查看效果. 一、Hexo的目录分析: &#xff11;&#…

微信公众号发布

微信公众号如何发文章 输入微信公众号 打开百度浏览器&#xff0c;搜索栏输入微信公众号&#xff0c;点击百度一下。 打开微信公众平台 页面显示搜索结果&#xff0c;页面选择微信公众平台官方链接点击打开。 扫一扫二维码 进入微信公众平台页面&#xff0c;使用你的微信扫一扫…

软件测试培训:等价类划分法概述

等价类划分法是一种常用的黑盒测试方法&#xff0c;它主张从大量数据中选择一部分数据用于测试&#xff0c;即尽可能使用最少的测试用例覆盖最多的数据&#xff0c;以发现更多的软件缺陷。 一个程序可以有多个输入&#xff0c;等价类划分就是将这些数据按照输入需求进行分类&am…

等价类划分法+边界值法

一、测试用例&#xff08;案例&#xff09; 1.1 定义&#xff1a; ​ 是在测试执行之前&#xff0c;由测试人员编写的指导测试过程的重要文档&#xff0c;主要包括&#xff1a;用例编号、测试目的、测试步骤&#xff08;用例描述&#xff09;&#xff0c;预期结果 1.2 介绍编…

什么是等价类划分法?

1.等价类划分法&#xff1f; 等价类划分是把所有可能输入的数据分为若干个区域&#xff0c;然后从每个区域中取少量有代表性的数据进行测试即可。 等价类 &#xff1a;何为等价类&#xff0c;某个输入域的集合&#xff0c;在这个集合中每个输入条件都是等效的。 2.分类 一般…

等价类划分法实验

一、使用等价类划分法分析三角形问题 要求一&#xff1a;需包含有效等价类及无效等价类划分表格 以及 测试用例表格 要求二&#xff1a;代码实现 实现 方式一&#xff1a;设计 三个输入框 一个判断按钮 点击按钮后显示结果 实现方式二&#xff1a;Java控制台进行测试判断【本实…

解决typora beta版本过期提示

现在beta版的typora打开都会有这个弹窗提示&#xff0c;想要把弹窗提示解决其实很简单&#xff0c;只要按照下面这个办法解决就可以了。 winr打开运行窗口&#xff0c;输入regedit&#xff0c;点确定打开注册表&#xff0c;依次展开计算机\HKEY_CURRENT_USER\SOFTWARE\Typora&…

Beta版本发布说明

2 Beta版本发布说明 2.1 列出这一版本的功能 Beta版本基于Alpha版本&#xff08;实现博主登录、发布博文、设置博客、搜索博文、点击标签显示相应博文、点击分类显示相应博文、留言功能&#xff09;上&#xff0c;主要新增以下几个功能&#xff1a; Message页面的信息推送功能、…

Elasticsearch5.0 beta版本安装错误

转载请注明出处&#xff1a;http://blog.csdn.net/gamer_gyt 博主微博&#xff1a;http://weibo.com/234654758 Github&#xff1a;https://github.com/thinkgamer 写在前边的话 elasticsearch的alpha版本早已经在github上了&#xff0c;但是beta版本却是最近才正式发布&#…

【AIGC】Photoshop AI Beta版本安装使用(永久免费)

AIGC 大爆发 Adobe近日宣布&#xff0c;Photoshop&#xff08;测试版&#xff09;应用程序发布了生成式AI绘图&#xff0c;这是世界上第一个创意和设计工作流程的副驾驶&#xff0c;为用户提供了一种神奇的新工作方式。生成式AI绘图由Adobe Firefly提供支持&#xff0c;Adobe的…

Beta版本软件使用说明

北京航空航天大学计算机学院 远航1617 小组 产品版本&#xff1a; Beta版本 产品名称&#xff1a;Crawling is going on 文档作者&#xff1a;杨帆 文档日期&#xff1a;2013/12/24 1. 引言 1.1 编写目的 编写本使用说明的目的是充分叙述本软件所能实现的功能及其…

Beta版本测试报告以及Beta版本发布说明

Beta版本测试报告 请根据团队项目中软件的需求文档、功能说明、系统设计和Beta阶段的计划安排&#xff0c;写出软件的测试过程和测试结果&#xff0c;并回答下述问题。 在测试过程中总共发现了多少bug&#xff1f;每个类别的bug分别为多少个&#xff1f;bug的分类&#xff1a; …

Beta版本测试报告

新发现的问题&战略调整&#xff1a; 这里的问题主要包含两种&#xff1a; 优化问题和不影响整体使用的bug&#xff0c;主要针对即时聊天以及UI交互部分&#xff1b;我们安排六位同学两两组队&#xff0c;在一周时间内分别对产品进行覆盖性的体验测试&#xff0c;提出了以…

微软发布 Windows 11 首个 Beta 版本

近日&#xff0c;微软向开发频道发布了 Windows 11 Insider Preview Build 22000.100&#xff0c;在没有发现重大问题之后&#xff0c;微软现在又向更稳定的 Beta 频道发布了同样的版本&#xff0c;这也是 Windows 11 首个 Beta 频道的预览版。微软建议那些想尝试 Windows 11 版…

软件版本号讲解:什么是Alpha, Beta, RC,Release

1. 软件版本阶段说明 Alpha版: 此版本表示该软件在此阶段主要是以实现软件功能为主&#xff0c;通常只在软件开发者内部交流&#xff0c;一般而言&#xff0c;该版本软件的Bug较多&#xff0c;需要继续修改。Beta版: 该版本相对于α版已有了很大的改进&#xff0c;消除了严重的…

WhiteHole Base beta版本正式发布!

体验 当前版本为基础测试版本&#xff0c;测试效果可以前往演示视频查看&#xff1a;https://www.bilibili.com/video/BV18Y411D7sA/?spm_id_from333.999.0.0&vd_source641e71dfd1a118fb834c4a5d156688d5 在线体验地址为&#xff1a; http://47.100.239.95 数据将保存~ …

版本详解:Beta、Dev、Canary、Stable、Chromium等版本

以Edge浏览器为例&#xff0c;各个版本有着不同的区别&#xff0c;或者说各个版本是测试版&#xff1a; 以Edge浏览器来说&#xff1a; Canary(金丝雀)版本浏览器&#xff0c;命名金丝雀&#xff0c;以为着“版本金贵且易碎”&#xff0c;这意味着该版本会融入很多新功能或者说…

UDS学习笔记(三)——协议的理解

在理解了CAN总线之后&#xff0c;我们就需要学习UDS协议了。百度一下UDS协议&#xff0c;出现很多的两个标准是ISO14229&#xff0c;ISO15765。ISO14229就是我们说的UDS诊断协议了&#xff0c;那还有一个ISO15765又是什么呢&#xff1f;这么多的标准要把脑袋都搞大了。那我们就…

UDS协议中常见的NRC

UDS诊断协议中常见的NRC NRC&#xff1a;Negative Response Code&#xff0c;否定响应码

解读UDS协议中NRC以及NRC优先级

最近被新东方转型之举震撼,让自己震撼的不是销售业绩、不是俞敏洪再创业启航,震撼的是多读书是真的可以改变一个人的,多读的这些书不是应用工作的功利书,是能慰藉心灵的“闲书”。为使自己摆脱高知识低文化宿命,分享一段文字,开始今天的主题: “ 我当然很希望自己可以得…