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

效果图

前端编辑页面

文章列表页面

文章详情页面

环境介绍

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
觉得本文对你有帮助?请分享给更多人关注「全栈开发者社区」加星标,提升全栈技能
本公众号会不定期给大家发福利,包括送书、学习资源等,敬请期待吧!
如果感觉推送内容不错,不妨右下角点个在看转发朋友圈或收藏,感谢支持。
好文章,留言、点赞、在看和分享一条龙吧❤️

Springboot+Vue实现发表文章功能相关推荐

  1. 添加数据功能java,SpringBoot+Vue实现数据添加功能

    一.添加代码生成器 用来自动为数据库映射类建立:mapper.service.controller package com.hanmh.utils; import com.baomidou.mybat ...

  2. springboot+vue实现手机验证码功能

    springboot+vue实现手机验证码功能 榛子云短信平台用户中心注册登录(有免费的一条消息,剩下的需要买)(阿里云个人得备案) 在springboot中加入依赖,用到了redis,阿里的fast ...

  3. Springboot+Vue实现富文本发表文章功能

    案例功能效果图 前端编辑页面 文章列表页面 文章详情页面 环境介绍 前端:vue 后端:springboot jdk:1.8及以上 数据库:mysql 完整源码获取方式 关注+私信"文本编辑 ...

  4. 【vue】vue组件发表评论功能

    今天看了vue相关的视频,所以跟着做一个小demo把知识串联起来,内容很简单但是也算是学习道路上的一点进步. 1 思路分析 发表评论模块写入一个组件,提高复用性. 关键点: 子组件通过localSto ...

  5. 笔记: SpringBoot + VUE实现数据字典展示功能

    最近一直在写前端,写得我贼难受,从能看懂一些基础的代码到整个前端框架撸下来鬼知道我经历了啥(:´д`)ゞ 项目中所用到的下拉菜单的值全部都是有数据库中的数据字典表来提供的,显示给用户的是的清晰的意思, ...

  6. SpringBoot+Vue+Mybatis-plus 博客(四):完成发布文章、编辑文章、删除文章及查询文章功能

    SpringBoot+Vue+Mybatis-plus 博客:个人博客介绍及效果展示 SpringBoot+Vue+Mybatis-plus 博客(一):完成博客后台前端登录页面.后端登录接口 Spr ...

  7. 基于SpringBoot + Vue的个人博客系统07——文章列表和文章详情

    简介 由于本人不是专业的前端,所以写出来的界面可能会稍微有些丑陋,甚至有些地方的写法不是很专业,还请大家见谅 主界面 JS 部分 首先是 js 逻辑部分 我们先在@/http/request.js中定 ...

  8. 前后端分离跨服务器文件上传,SpringBoot+Vue.js实现前后端分离的文件上传功能

    这篇文章需要一定vue和springboot的知识,分为两个项目,一个是前端vue项目,一个是后端springboot项目. 后端项目搭建 我使用的是springboot1.5.10+jdk8+ide ...

  9. springboot vue 小程序小区物业管理系统【物业手机版(小程序)+物业系统后端+物业系统前端+业主手机端(小程序)】(功能较丰富)

    springboot vue 小程序小区物业管理系统[物业手机版(小程序)+物业系统后端+物业系统前端+业主手机端(小程序)](功能较丰富) 高清视频演示: https://www.bilibili. ...

最新文章

  1. 《Adobe Fireworks CS6中文版经典教程》——1.5使用多个文档
  2. 【Grafana】函数
  3. java面试题十 java数组初始化
  4. python数据结构与算法分析_数据结构和算法分析
  5. ssh 配置:在 Linux 中 ssh 配置无密码登陆完整步骤以及易错点分析
  6. YGC 问题排查,又涨姿势了!
  7. java打包成jar_把Java程序打包成jar文件包并执行的方法
  8. citrix xendesktop edition
  9. 第十五章 第十五章 异步A3C(Asynchronous Advantage Actor-Critic,A3C)-强化学习理论学习与代码实现(强化学习导论第二版)
  10. excel如何从字符串中截取指定字符(LEFT、RIGHR、MID三大函数)
  11. 【STM8L】STM8L之按键中断
  12. 匿名者黑页html源码,HACK敲代码黑页源码
  13. UNI-APP_微信授权失败 微信授权第一次失败,需要授权两次才能成功
  14. 将多个html文件合成一个,【答疑】怎么用pr将多个项目工程文件合成一个? - 视频教程线上学...
  15. andriod自带模拟器使用代理
  16. CSDN博客新增「评论置顶」、「定时发布」功能,翘首期盼的PC版「每日一练」上线!【第14期*2021.9.22】
  17. 11月更新!一口气上线20+新功能,3D架构拓扑图更具趣味性~
  18. C语言+深度搜索的的方法解决全排列问题
  19. ASK、FSK调制解调
  20. a标签跳转新页面的各种方式

热门文章

  1. Java分布式跟踪系统Zipkin(六):Brave源码分析-Brave和SpringBoot整合
  2. 【GAT】如何理解Graph Attention Network(注意力机制)?
  3. 让孩子进阶中产的唯一路径是编程?
  4. b2b2c微信小程序商城源码
  5. 蓝牙控制esp32单片机(三)
  6. 关于options请求的一点理解
  7. 工程力学(10)—轴向拉伸与压缩二
  8. 汽车电子系统网络安全指南与汽车信息物理融合系统网络安全指南
  9. Transformer在3D点云中的应用综述(检测/跟踪/分割/降噪/补全)
  10. 最强辅助!IDA 辅助工具Karta——二进制文件中搜索开源代码