idea新建springboot后端到前端_码云开源项目:利用SpringBoot+Vue 实现留言版
一.新建Vue项目和SpringBoot项目
新建Vue项目
新建文件夹SpringBoot-Vue-MessageBoard创建Vue项目使用vue ui命令(需要vue 3.0选择刚才的目录 名字为Vue创建后V还是小写 创建后可以改为大写 取消git初始化 手动配置 取消 打开 创建项目,不保存预设
新建SpringBoot项目
用IDEA打开SpringBoot-Vue-MessageBoard这个目录 创建SpringBoot项目右键 选择Spring Initializr 选择这四个 名字改为SpringBoot
二. 后端
配置application.properties
#Mysqlspring.datasource.url=jdbc:mysql://localhost:3306/enaium?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghaispring.datasource.username=rootspring.datasource.password=rootspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverspring.jpa.show-sql= truespring.jpa.properties.hibernate.format_sql = true#Serverserver.port=8181
写实体类
package cn.enaium.message.entity;import lombok.AllArgsConstructor;import lombok.Data;import lombok.NoArgsConstructor;import javax.persistence.Entity;import javax.persistence.Id;/** * Project: message * ----------------------------------------------------------- * Copyright © 2020 | Enaium | All rights reserved. */@Data@Entity@NoArgsConstructor@AllArgsConstructorpublic class Message { @Id private Long id; private String author; private String message; private String time;}
实体类Jpa
package cn.enaium.message.repository;import cn.enaium.message.entity.Message;import org.springframework.data.jpa.repository.JpaRepository;/** * Project: message * ----------------------------------------------------------- * Copyright © 2020 | Enaium | All rights reserved. */public interface MessageRepository extends JpaRepository {}
Controller
package cn.enaium.message.controller;import cn.enaium.message.entity.Message;import cn.enaium.message.repository.MessageRepository;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import java.text.SimpleDateFormat;import java.util.Date;import java.util.List;/** * Project: message * ----------------------------------------------------------- * Copyright © 2020 | Enaium | All rights reserved. */@RestControllerpublic class Controller { @Autowired private MessageRepository messageRepository; @RequestMapping("/getMessages") private List getMessages() { return messageRepository.findAll();//遍历所有留言 } @GetMapping("/postMessage") private String postMessage(@RequestParam String author, @RequestParam String message) { if(author.replaceAll(" ","").equals("") || message.replaceAll(" ","").equals("")) { return "filed"; }//判断名字和留言是否为空 messageRepository.save(new Message((long) (messageRepository.findAll().size() + 1),author,message,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));//保存留言到数据库 return "success"; }}
解决跨源请求问题
package cn.enaium.message.config;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.CorsRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;/** * Project: message * ----------------------------------------------------------- * Copyright © 2020 | Enaium | All rights reserved. */@Configurationpublic class CorsConfig implements WebMvcConfigurer { @Override//重写这个方法 public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("*") .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") .allowCredentials(true) .maxAge(3600) .allowedHeaders("*"); }}
三. 前端
安装插件axios和Element UI
写Home页面
留言版
留言By Enaium
路由页面
import Vue from 'vue'import VueRouter from 'vue-router'import Home from '../views/Home.vue'Vue.use(VueRouter)const routes = [ { path: '/', name: 'Home', component: Home }]const router = new VueRouter({ mode: 'history', routes})export default router
四. 运行
运行SpringBootcd 到Vue使用npm run serve运行
idea新建springboot后端到前端_码云开源项目:利用SpringBoot+Vue 实现留言版相关推荐
- 关于码云开源项目SpringBootAdmin多数据源配置
SpringBootAdmin是码云上一个以springboot为核心的开源的后台管理系统. 这里是链接地址:点击打开链接 由于是后台系统,应该采用数据库分离,权限,用户,角色和业务模块分开. app ...
- idea新建springboot后端到前端_基于SpringBoot+AntDesign的快速开发平台
项目介绍 Jeecg-Boot是一款基于SpringBoot+代码生成器的快速开发平台!前后端分离架构.技术采用SpringBoot.AntDesignVue.Mybatis.Shiro.JWT.强大 ...
- 2017 年度码云新增项目排行榜 TOP 50,为它们打“call”
2017 年度码云新增项目排行榜 TOP 50 正式出炉 !2017 结束了,我们来关注一下这一年里码云上新增的最热门的开源项目吧.此榜单根据 2017 年在码云上新增开源项目的 Watch.Star ...
- 2016 年度码云热门项目排行榜 TOP 50
原文地址:http://www.oschina.net/news/80909/2016-oschina-git-top-50?from=timeline&isappinstalled=0 阿里 ...
- 白嫖项目基于ssm房屋租赁系统源码【开源项目】
ssm房屋租赁系统 运行工具:idea或eclipse均测试,可以运行. 开发技术: 后端ssm(spring springmvc mybatis) 前端:jsp jquery 数据库:mysq ...
- 为什么将表格的method改为post后就无法工作_不用再等后端的接口啦!这个开源项目花 2 分钟就能模拟出后端接口...
本文作者:HelloGitHub-嘉文 这里是 HelloGitHub 推出的<讲解开源项目>系列,今天给大家带来一款开源免费的模拟后端 API 的工具:moco 没学过后端开发的也能快速 ...
- 支付宝当面付扫码支付支付后不回调_码云上不错的几个支付相关的项目
阅读文本大概需要15分钟. 网上支付相关的额业务场景无处不在,如果能掌握支付相关的核心技术,对于升职涨薪有莫大的好处.目前国内支付以支付宝和微信这两种支付为首,其他支付则可以忽略不计.有些网友以这两种 ...
- git小乌龟连接码云_码云(Gitee.com)帮助文档_V1.2
码云Pages #### 码云 `Pages` 是一个免费的静态网页托管服务,您可以使用 码云 `Pages` 托管博客.项目官网等静态网页.如果您使用过 `Github Pages` 那么您会很快上 ...
- 码云上传文件夹_码云上传本地文件夹,码云只能上传20个文件的突破方法
码云官方地址:https://gitee.com/ 很多人不知道码云上传本地文件夹怎么操作,或者如何突破码云只能上传20个文件限制的问题,今天就来说说这事的方法吧. 简介: 码云是媲美GitHub的代 ...
最新文章
- Redis学习(4)-数据类型set和zset
- 11.typescript-元组
- 一个简单判等例子的深度分析
- [BJDCTF2020]EasySearch
- 通过女票的淘宝历程,大白话讲解大数据各个方向的分工
- 配置HDFS HttpFS和WebHDFS
- OSGi将Maven与Equinox结合使用
- MCMC 和 Gibbs采样
- python资源管理器选择文件_Python:在资源管理器中获取选定文件的列表(windows7)...
- PHP常见缓存技术分析,让重复的调用缓存以加快速度
- C# int byte数组互转 int byte[]互转
- ubuntu14.04 下 mysql 存储目录迁移
- pxhere - 世界知名的免费摄影图库,可以免费商用
- 计算机网络ip地址分类6,c类ip地址划分6个子网
- Python 爬取“微博树洞”详细教程
- 虚拟小镇意识保存~认识脑电波
- 前端开发的就业前景和收入怎么样啊
- 阿龙的学习笔记---转载及精炼总结github仓库:cpp-backend-reference
- 超市管理系统的html页面,基于WEB的超市管理系统_站内搜索_Web开发网
- Lieges of Legendre CodeForces - 603C (博弈论,SG找规律)