Springboot+Vue实现网页内容生成图片功能

Java引导者

共 6421字,需浏览 13分钟

 ·

2020-09-10 02:27

点击上方 web项目开发选择 设为星标

优质文章,及时送达

--

案例功能效果图

文章详情页面

把文章详情生成图片页面


环境介绍

前端:vue

后端:springboot
jdk:1.8及以上

数据库:mysql


完整源码获取方式



源码获取方式


码关注回复【分享图片】获取完整源码


如果你在运行这个代码的过程中有遇到问题,请加小编微信xxf960513,我拉你进对应微信学习群!!帮助你快速掌握这个功能代码!



核心代码介绍


AtricleCtrle.java

      @RestController@RequestMapping("/article")@CrossOriginpublic class ArticleCtrler {  @Autowired  private 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
loadPage = articleService.loadPage(vo); return Result.success(loadPage); } catch (Exception e) { e.printStackTrace(); } return Result.error(CodeMsg.SERVER_ERROR); }}

ArticleService.interface

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

ArticleDao.java

@Repositorypublic interface ArticleDao {  void save(Article vo);  List
findByCondit(Article_Condit vo);}

main.js

import Vue from 'vue'import App from './App'import router from './router'import axios from 'axios'import ElementUI from 'element-ui';import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);import $ from 'jquery'
axios.defaults.baseURL = 'http://127.0.0.1:8080';Vue.prototype.HOST='/email'
Vue.config.productionTip = falseVue.prototype.$axios = axios
/* eslint-disable no-new */new Vue({ el: '#app', router, components: { App }, template: ''})

index.vue

<template>  <div class="wrap">    <div class="top">      <h1>文章列表h1>      <el-button type="primary" @click="goToEdit">添加文章el-button>    div>
<div class="card-wrap"> <div v-for="(item, index) in art" :key="index" class="box-card" @click="goToDetail(item)"> <el-card> <div class="title">{{ item.title }}div> <div class="des">{{ item.description }}div> <div class="time">{{ item.createdatetime }}div> el-card> div> div> div>template>
<script>import axios from 'axios'export default { components: {}, props: {}, data() { return { art: [] } }, computed: {}, watch: {}, created() {}, mounted() { axios .post('http://139.159.147.237:8080/yxyz/article/loadPage') .then((res) => { console.log(res.data, 'res') if (res.data && res.data.data && res.data.data.list) { console.log(res.data.data.list, this, 'res') const list = res.data.data.list this.art = list } }) .catch(function(error) { console.log(error) }) }, methods: { goToEdit() { this.$router.push('/about') }, goToDetail(item) { console.log(123) this.$router.push({ name: 'detail', params: { item: item } }) } }}script>
<style scoped lang="scss">.wrap { margin-top: 50px;}.top { display: flex; justify-content: center; align-items: center; position: relative; button { position: absolute; right: 0; }}.card-wrap { display: flex; flex-wrap: wrap;}.box-card { margin-bottom: 20px; margin-right: 20px; width: 30%; .title { font-weight: bold; font-size: 16px; text-align: left; margin-bottom: 10px; } .des { font-size: 14px; text-align: left; margin-bottom: 10px; } .time { font-size: 14px; text-align: left; }}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 class="time">{{ detail.createdatetime }}div>    el-card>  div>template>
<script>export default { components: {}, props: {}, data() { return { detail: {} } }, computed: {}, watch: {}, created() { console.log(this.$route) const item = this.$route.params.item
this.detail = item }, mounted() {}, methods: {}}script>
<style scoped lang="scss">.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: 8080  servlet:    context-path: /yxyzspring:  datasource:    name: yxyz    url: jdbc:mysql://localhost/test?serverTimezone=GMT%2b8&characterEncoding=UTF8    username: root    password: 123 # 使用druid数据源    type: com.alibaba.druid.pool.DruidDataSource    driver-class-name: com.mysql.cj.jdbc.Driver    filters: stat    maxActive: 20    initialSize: 1    maxWait: 60000    minIdle: 1    timeBetweenEvictionRunsMillis: 60000    minEvictableIdleTimeMillis: 300000    validationQuery: select 'x'    testWhileIdle: true    testOnBorrow: false    testOnReturn: false    poolPreparedStatements: true    maxOpenPreparedStatements: 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

t_article.sql

SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for t_article-- ----------------------------DROP TABLE IF EXISTS `t_article`;CREATE TABLE `t_article` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `title` varchar(255) NOT NULL,  `description` varchar(512) NOT NULL,  `content` text NOT NULL,  `articletype` varchar(16) DEFAULT NULL,  `createdatetime` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,  `createuserid` varchar(32) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8;


--完--

推荐案例


温暖提示

为了方便大家更好的学习,本公众号经常分享一些完整的单个功能案例代码给大家去练习,如果本公众号没有你要学习的功能案例,你可以联系小编(微信:xxf960513)提供你的小需求给我,我安排我们这边的开发团队免费帮你完成你的案例。
注意:只能提单个功能的需求不能要求功能太多,比如要求用什么技术,有几个页面,页面要求怎么样?


请长按识别二维码

想学习更多的java功能案例请关注

Java项目开发

如果你觉得这个案例以及我们的分享思路不错,对你有帮助,请分享给身边更多需要学习的朋友。别忘了《留言+点在看》给作者一个鼓励哦!

浏览 82
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报