10 前后端分离

本贴最后更新于 296 天前,其中的信息可能已经事过景迁

前后端结合的话有以下问题:​

image

前后端分离开发

介绍

​​image​​

开发流程

​​image​​

mock 数据是模拟数据。

技术栈

image

yapi

介绍

image

使用

image

​​​image

导出接口:

image

image

swagger

介绍

image

使用方式

image

image

        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
            <version>3.0.2</version>
        </dependency>

image

WebMvcConfig​类加上注解:

@EnableSwagger2
@EnableKnife4j

再加上这两个方法:

    @Bean
    public Docket createRestApi() {
        // 文档类型
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.itheima.reggie.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("瑞吉外卖")
                .version("1.0")
                .description("瑞吉外卖接口文档")
                .build();
    }

image

        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

image

                "/doc.html",
                "/webjars/**",
                "/swagger-resources",
                "/v2/api-docs"

进入 http://localhost:8080/doc.html​网站就可以看到生成的接口。

image

常用注解

image

项目部署

部署架构

image

部署环境说明

image

192.168.100.128​:

  • 主库
  • nginx

192.168.100.100​:

  • 从库

部署前端项目

image

dist 是前端 webpack 打包好的。

image

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/dist;
            index  index.html index.htm;
        }

        location ^~ /api/ {
                rewrite ^/api/(.*)$ /$1 break;
                proxy_pass http://192.168.100.100:8080;
        }

image前端发送请求会多加一个 api 的前缀。

反向代理对这个 url 进行处理,保证后端能接收到正确的请求:

image

部署后端项目

image

image

image

遇到一个小问题,记录一下:Git 的使用-一个分支完全替换另一个分支

  • Java

    Java 是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由 Sun Microsystems 公司于 1995 年 5 月推出的。Java 技术具有卓越的通用性、高效性、平台移植性和安全性。

    3169 引用 • 8207 回帖 • 1 关注

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...