vue+springboot+springcloud

2. 项目搭建

2.1 技术选型

前端技术:

  • 基础的 HTML、CSS、JavaScript(基于 ES6 标准)
  • JQuery
  • Vue.js 2.0 以及基于 Vue 的框架:Vuetify(UI框架)
  • 前端构建工具:WebPack
  • 前端安装包工具:NPM
  • Vue 脚手架:Vue-cli
  • Vue 路由:vue-router
  • Ajax 框架:axios
  • 基于 Vue 的富文本框架:quill-editor

后端技术:

  • 基础的 SpringMVC、Spring 5.x 和 MyBatis3
  • Spring Boot 2.2.4 版本
  • Spring Cloud Hoxton.SR1
  • Redis-4.0
  • RabbitMQ-3.4
  • Elasticsearch-6.3
  • nginx-1.14.2
  • FastDFS - 5.0.8
  • MyCat
  • Thymeleaf
  • mysql 5.6

2.3 域名

我们在开发的过程中,为了保证以后的生产、测试环境统一,尽量都采用域名来访问项目。

一级域名:leyou.com

二级域名:www.leyou.com , api.leyou.com

我们可以通过 switchhost 工具来修改自己的 host 对应的地址,只要把这些域名指向 127.0.0.1,那么跟你用 localhost 的效果是完全一样的。

2.4 创建父工程

1.添加依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.leyou.parent</groupId>
    <artifactId>leyou</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <name>leyou</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR1</spring-cloud.version>
        <mybatis.starter.version>1.3.2</mybatis.starter.version>
        <mapper.starter.version>2.0.2</mapper.starter.version>
        <druid.starter.version>1.1.9</druid.starter.version>
        <mysql.version>5.1.32</mysql.version>
        <pageHelper.starter.version>1.2.3</pageHelper.starter.version>
        <leyou.latest.version>1.0.0-SNAPSHOT</leyou.latest.version>
        <fastDFS.client.version>1.26.1-RELEASE</fastDFS.client.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- springCloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- mybatis启动器 -->
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>${mybatis.starter.version}</version>
            </dependency>
            <!-- 通用Mapper启动器 -->
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper-spring-boot-starter</artifactId>
                <version>${mapper.starter.version}</version>
            </dependency>
            <!-- 分页助手启动器 -->
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper-spring-boot-starter</artifactId>
                <version>${pageHelper.starter.version}</version>
            </dependency>
            <!-- mysql驱动 -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>
            <!--FastDFS客户端-->
            <dependency>
                <groupId>com.github.tobato</groupId>
                <artifactId>fastdfs-client</artifactId>
                <version>${fastDFS.client.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    
</project>

2.5 创建 Eureka Server

添加依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>leyou</artifactId>
        <groupId>com.leyou.parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.leyou.registry</groupId>
    <artifactId>leyou-registry</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>


</project>

编写启动类

@SpringBootApplication
@EnableEurekaServer
public class LeyouRegistryApplication {
    public static void main(String[] args) {
        SpringApplication.run(LeyouRegistryApplication.class,args);
    }
}

编写配置文件 application.yaml

server:
  port: 10086
spring:
  application:
    name: leyou-registry
eureka:
  client:
    service-url:
      defaultZone: http://localhost:${server.port}/eureka
    fetch-registry: false
    register-with-eureka: false
  server:
    enable-self-preservation: false
    eviction-interval-timer-in-ms: 5000

2.6 创建 Zuul

添加依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>leyou</artifactId>
        <groupId>com.leyou.parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.leyou.gateway</groupId>
    <artifactId>leyou-gateway</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>


</project>

编写启动类

@SpringBootApplication
@EnableZuulProxy
public class LeyouGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(LeyouGatewayApplication.class, args);
    }
}

编写配置

server:
  port: 10010
spring:
  application:
    name: leyou-gateway
eureka:
  client:
    service-url:
      defaultZone: http://localhost:10086/eureka
    registry-fetch-interval-seconds: 5
zuul:
  prefix: /api

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue.jsSpringBoot 结合可以构建一个强大的后端服务和前端用户界面,用于实现图片上传功能。这里是一个简要的步骤概述: 1. **前端Vue)**: - 使用 Vue CLI 创建一个新的项目,并安装必要的依赖,如 `axios` (用于发送 HTTP 请求) 和 `vue-file-upload` 或者 `iview` 这样的 UI 组件库中的文件上传组件。 - 在 HTML 元素上创建一个表单,包含一个文件输入元素 `<input type="file">`,这将让用户选择要上传的图片。 - 使用 JavaScript 视图层代码监听文件输入事件,当用户选择文件后,发送 AJAX 请求到 SpringBoot 后台。 ```javascript <template> <div> <button @click="uploadFile">上传图片</button> <img :src="imageUrl" v-if="imageUrl"> </div> </template> <script> export default { data() { return { imageUrl: '', }; }, methods: { uploadFile() { const file = this.$refs.fileInput.files; // 发送请求到SpringBoot接口 axios.post('/api/upload', { file }, { headers: {'Content-Type': 'multipart/form-data'} }) .then(response => { this.imageUrl = response.data.url; // 存储上传后的图片 URL }); }, }, }; </script> ``` 2. **后端(SpringBoot)**: - 在 SpringBoot 应用中,创建一个 RESTful API 接口,例如 `/api/upload`,用于处理图片上传。使用 Spring MVC 或 Spring WebFlux 来处理HTTP请求。 - 实现图片存储逻辑,通常会使用文件系统、云存储服务或第三方库如 Amazon S3、Google Cloud Storage。 ```java @PostMapping("/upload") public ResponseEntity<String> handleImageUpload(@RequestParam("file") MultipartFile file) throws IOException { try { // 将文件保存到服务器或云存储 String filePath = saveUploadedFile(file); return ResponseEntity.ok("http://your-server/" + filePath); // 返回存储后的图片URL } catch (Exception e) { log.error("Error uploading file", e); throw new RestResponseEntity(HttpStatus.BAD_REQUEST, "图片上传失败"); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LI JS@你猜啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值