vue3配置代理实现axios请求本地接口返回PG库数据【前后端实操】

前端编写

安装 axios

如果当前未安装axios,可以执行如下指令安装

bash 复制代码
npm install axios

配置代理

当前为基于Vite构建的项目,在 vite.config.ts 中配置代理,在defineConfig中新增server配置,主要关注两个点:

一、需要代理的url开头,此处为/asset

二、代理的目标IP以及端口号,此处为http://localhost:8888

typescript 复制代码
// vite.config.ts
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
  plugins: [vue()],
  server: {
    proxy: {
      '/asset': { // 以 '/asset' 开头的请求会被代理
        target: 'http://localhost:8888', // 后端服务器地址
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace(/^\/asset/, '') // 重写路径,去掉 '/asset'
      }
    }
  }
});

如果你的项目基于Vue CLI构建,可在vue.config.js添加

javascript 复制代码
// vue.config.js
const { defineConfig } = require('@vue/cli-service');

module.exports = defineConfig({
  devServer: {
    proxy: {
      '/asset': {  // 以 '/asset' 开头的请求会被代理
        target: 'http://localhost:8888',  // 后端服务器地址
        changeOrigin: true,  // 允许跨域
        pathRewrite: {
          '^/asset': ''  // 重写路径,去掉 '/asset'
        }
      }
    }
  }
});

前端代码编写

此处使用ts&vue3写法,由于使用原生axios写法,没有封装通用的请求js(后续博客完善),导致此处解析响应会比较绕

const assetInfoList = result?.data?.data?.assetInfoList

html 复制代码
<script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios'

const isUseLocalFlag = ref(true)
const setTabData = async function () {
  if (isUseLocalFlag.value) {
    const bizId = '0777c40218114c35a29b0d4d84355668'
    await axios.post(`/asset/assetInfo/${bizId}/byBizId`).then(result => {
      if (result.status === 200) {
        const assetInfoList = result?.data?.data?.assetInfoList
        console.log('assetInfoList', assetInfoList)
      }
    })
  } else {
    // 请求mock数据
  }
}
</script>

<template>
  <div>
    数据源选择:
  </div>
  <el-switch
      v-model="isUseLocalFlag"
      active-text="使用本地服务数据"
      inactive-text="使用mock数据"
  />
  <el-button @click="setTabData" style="margin-left: 10px;">给tab赋值</el-button>
</template>

<style scoped>

</style>

后端编写

pgsql建表&测试数据填充

sql 复制代码
-- 资产信息表创建
CREATE TABLE IF NOT EXISTS t_asset_info (
  asset_number varchar(100) COLLATE pg_catalog.default NOT NULL,
  asset_status varchar(10) COLLATE pg_catalog.default,
  use_dept_code varchar(100) COLLATE pg_catalog.default,
  create_time timestamp(0),
  create_by_uuid varchar(32) COLLATE pg_catalog.default,
  create_by_account varchar(32) COLLATE pg_catalog.default,
  create_by_name varchar(100) COLLATE pg_catalog.default,
  last_update_time timestamp(0),
  last_update_uuid varchar(32) COLLATE pg_catalog.default,
  last_update_account varchar(32) COLLATE pg_catalog.default,
  last_update_name varchar(100) COLLATE pg_catalog.default,
  ext_attribute1 varchar(255) COLLATE pg_catalog.default,
  ext_attribute2 varchar(255) COLLATE pg_catalog.default,
  ext_attribute3 varchar(255) COLLATE pg_catalog.default,
  ext_attribute4 varchar(255) COLLATE pg_catalog.default,
  ext_attribute5 varchar(255) COLLATE pg_catalog.default,
  ext_attribute6 varchar(255) COLLATE pg_catalog.default,
  ext_attribute7 varchar(255) COLLATE pg_catalog.default,
  ext_attribute8 varchar(255) COLLATE pg_catalog.default,
  ext_attribute9 varchar(255) COLLATE pg_catalog.default,
  ext_attribute10 varchar(255) COLLATE pg_catalog.default,
  ext_attribute11 varchar(255) COLLATE pg_catalog.default,
  ext_attribute12 varchar(255) COLLATE pg_catalog.default,
  ext_attribute13 varchar(255) COLLATE pg_catalog.default,
  ext_attribute14 varchar(255) COLLATE pg_catalog.default,
  ext_attribute15 varchar(255) COLLATE pg_catalog.default,
  ext_attribute16 varchar(255) COLLATE pg_catalog.default,
  ext_attribute17 varchar(255) COLLATE pg_catalog.default,
  ext_attribute18 varchar(255) COLLATE pg_catalog.default,
  ext_attribute19 varchar(255) COLLATE pg_catalog.default,
  ext_attribute20 varchar(255) COLLATE pg_catalog.default,
  biz_id varchar(32) COLLATE pg_catalog.default DEFAULT ''::character varying,
  CONSTRAINT asset_info_pkey PRIMARY KEY (asset_number)
)
;

ALTER TABLE t_asset_info 
  OWNER TO postgres;

COMMENT ON COLUMN t_asset_info.asset_number IS '资产编号';

COMMENT ON COLUMN t_asset_info.asset_status IS '资产状态
10:正常
20:使用
30:闲置
40:报废
50:封存
60:盘点中
70:在途';

COMMENT ON COLUMN t_asset_info.use_dept_code IS '使用部门名称';

COMMENT ON COLUMN t_asset_info.create_time IS '创建时间';

COMMENT ON COLUMN t_asset_info.create_by_uuid IS '创建人uuid';

COMMENT ON COLUMN t_asset_info.create_by_account IS '创建人账号';

COMMENT ON COLUMN t_asset_info.create_by_name IS '创建人名称';

COMMENT ON COLUMN t_asset_info.last_update_time IS '最后更新时间';

COMMENT ON COLUMN t_asset_info.last_update_uuid IS '最后跟新人uuid';

COMMENT ON COLUMN t_asset_info.last_update_account IS '最后更新人账号';

COMMENT ON COLUMN t_asset_info.last_update_name IS '最后更新人名称';

COMMENT ON COLUMN t_asset_info.ext_attribute1 IS '拓展属性1';

COMMENT ON COLUMN t_asset_info.ext_attribute2 IS '拓展属性2';

COMMENT ON COLUMN t_asset_info.ext_attribute3 IS '拓展属性3';

COMMENT ON COLUMN t_asset_info.ext_attribute4 IS '拓展属性4';

COMMENT ON COLUMN t_asset_info.ext_attribute5 IS '拓展属性5';

COMMENT ON COLUMN t_asset_info.ext_attribute6 IS '拓展属性6';

COMMENT ON COLUMN t_asset_info.ext_attribute7 IS '拓展属性7';

COMMENT ON COLUMN t_asset_info.ext_attribute8 IS '拓展属性8';

COMMENT ON COLUMN t_asset_info.ext_attribute9 IS '拓展属性9';

COMMENT ON COLUMN t_asset_info.ext_attribute10 IS '拓展属性10';

COMMENT ON COLUMN t_asset_info.ext_attribute11 IS '拓展属性11';

COMMENT ON COLUMN t_asset_info.ext_attribute12 IS '拓展属性12';

COMMENT ON COLUMN t_asset_info.ext_attribute13 IS '拓展属性13';

COMMENT ON COLUMN t_asset_info.ext_attribute14 IS '拓展属性14';

COMMENT ON COLUMN t_asset_info.ext_attribute15 IS '拓展属性15';

COMMENT ON COLUMN t_asset_info.ext_attribute16 IS '拓展属性16';

COMMENT ON COLUMN t_asset_info.ext_attribute17 IS '拓展属性17';

COMMENT ON COLUMN t_asset_info.ext_attribute18 IS '拓展属性18';

COMMENT ON COLUMN t_asset_info.ext_attribute19 IS '拓展属性19';

COMMENT ON COLUMN t_asset_info.ext_attribute20 IS '拓展属性20';

COMMENT ON COLUMN t_asset_info.biz_id IS '业务ID';

COMMENT ON TABLE t_asset_info IS '资产信息表';
-- 资产信息表插入测试数据
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('03f7744cb08fbf23c5e3a49038b741d9', '60', '00-dept-34', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('0777c40218114c35a29b0d4d8435520e', '10', '00-dept-36', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('2d72bf99ebcad018297aed761b5dee8d', '10', '00-dept-29', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('3d4c487a1679c70f61b0aa3dd5a1733a', '60', '00-dept-27', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('4f22a0a4fe1a8ccc5916718cd1049241', '70', '00-dept-28', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('6ac629baf0e5af838433f7d48751cbbc', '50', '00-dept-33', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('7396d84b53bc253123ce149aae367227', '30', '00-dept-31', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('74fd3149eb6b63b4a05974644b12b9f7', '20', '00-dept-30', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('a33fa6930899ca9b30ff93a95dedd11e', '70', '00-dept-35', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');
INSERT INTO t_asset_info (asset_number, asset_status, use_dept_code, create_time, create_by_uuid, create_by_account, create_by_name, last_update_time, last_update_uuid, last_update_account, last_update_name, ext_attribute1, ext_attribute2, ext_attribute3, ext_attribute4, ext_attribute5, ext_attribute6, ext_attribute7, ext_attribute8, ext_attribute9, ext_attribute10, ext_attribute11, ext_attribute12, ext_attribute13, ext_attribute14, ext_attribute15, ext_attribute16, ext_attribute17, ext_attribute18, ext_attribute19, ext_attribute20, biz_id) VALUES ('db06878e60b8db82c4412d11ff793d18', '40', '00-dept-32', '2025-02-16 21:55:22', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', '2025-02-17 22:29:29', 'pine_tree_uuid', 'pine_tree_account', 'pine_tree_name', 'ext_attribute1', 'ext_attribute2', 'ext_attribute3', 'ext_attribute4', 'ext_attribute5', 'ext_attribute6', 'ext_attribute7', 'ext_attribute8', 'ext_attribute9', 'ext_attribute10', 'ext_attribute11', 'ext_attribute12', 'ext_attribute13', 'ext_attribute14', 'ext_attribute15', 'ext_attribute16', 'ext_attribute17', 'ext_attribute18', 'ext_attribute19', 'ext_attribute20', '0777c40218114c35a29b0d4d84355668');

实体类新增

java 复制代码
/**
 * <p>
 * 资产信息表
 * </p>
 *
 * @author PineTree
 * @since 2025-02-16
 */
@TableName("t_asset_info")
@ApiModel(value = "AssetInfo对象", description = "资产信息表")
@Data
public class AssetInfoDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("资产编号")
    @TableId(value = "asset_number", type = IdType.ASSIGN_UUID)
    private String assetNumber;

    @ApiModelProperty("资产状态	10:正常	20:使用	30:闲置	40:报废	50:封存	60:盘点中	70:在途")
    private String assetStatus;

    @ApiModelProperty("使用部门名称")
    private String useDeptCode;

    @ApiModelProperty("创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty("创建人uuid")
    private String createByUuid;

    @ApiModelProperty("创建人账号")
    private String createByAccount;

    @ApiModelProperty("创建人名称")
    private String createByName;

    @ApiModelProperty("最后更新时间")
    private LocalDateTime lastUpdateTime;

    @ApiModelProperty("最后跟新人uuid")
    private String lastUpdateUuid;

    @ApiModelProperty("最后更新人账号")
    private String lastUpdateAccount;

    @ApiModelProperty("最后更新人名称")
    private String lastUpdateName;

    @ApiModelProperty("拓展属性1")
    private String extAttribute1;

    @ApiModelProperty("拓展属性2")
    private String extAttribute2;

    @ApiModelProperty("拓展属性3")
    private String extAttribute3;

    @ApiModelProperty("拓展属性4")
    private String extAttribute4;

    @ApiModelProperty("拓展属性5")
    private String extAttribute5;

    @ApiModelProperty("拓展属性6")
    private String extAttribute6;

    @ApiModelProperty("拓展属性7")
    private String extAttribute7;

    @ApiModelProperty("拓展属性8")
    private String extAttribute8;

    @ApiModelProperty("拓展属性9")
    private String extAttribute9;

    @ApiModelProperty("拓展属性10")
    private String extAttribute10;

    @ApiModelProperty("拓展属性11")
    private String extAttribute11;

    @ApiModelProperty("拓展属性12")
    private String extAttribute12;

    @ApiModelProperty("拓展属性13")
    private String extAttribute13;

    @ApiModelProperty("拓展属性14")
    private String extAttribute14;

    @ApiModelProperty("拓展属性15")
    private String extAttribute15;

    @ApiModelProperty("拓展属性16")
    private String extAttribute16;

    @ApiModelProperty("拓展属性17")
    private String extAttribute17;

    @ApiModelProperty("拓展属性18")
    private String extAttribute18;

    @ApiModelProperty("拓展属性19")
    private String extAttribute19;

    @ApiModelProperty("拓展属性20")
    private String extAttribute20;

    @ApiModelProperty("业务ID")
    private String bizId;

}

controller层代码编写

由于使用了mybatis-plus,调用了通用service查询逻辑,只需编写controller即可

java 复制代码
/**
 * <p>
 * 资产信息表 前端控制器
 * </p>
 *
 * @author PineTree
 * @since 2025-02-16
 */
@RestController
@RequestMapping("/assetInfo")
public class AssetInfoController {

    @Resource
    private IAssetInfoService assetInfoService;
    @PostMapping("{bizId}/byBizId")
    public Result getAssetInfoByBizId(@PathVariable("bizId") String bizId) {
        if (StringUtils.isEmpty(bizId)) {
            return Result.ok();
        }
        QueryWrapper<AssetInfoDTO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("biz_id", bizId);
        List<AssetInfoDTO> assetInfoList = assetInfoService.list(queryWrapper);
        return Result.ok().data("assetInfoList", assetInfoList);
    }
}

postMan接口测试

启动本地后端,base_url为api collection维度的全局环境变量,此处设置为本地8888端口,可方便后续切换

联调

点击tab按钮,可以观察到成功从前端5173端口代理到8888并获取到了响应数据

代码仓

前端代码

https://gitee.com/pinetree-cpu/hello_vue3
master分支

后端代码

https://gitee.com/pinetree-cpu/parent-demon
pine_tree_dev分支

欢迎评论区留言&讨论

相关推荐
茶本无香4 分钟前
Java Collection API增强功能系列之二 List.of、Set.of、Map.of
java·开发语言·list
幽络源小助理5 分钟前
SpringBoot古典舞在线交流平台设计与实现
java·开发语言·spring boot
遥不可及~~斌10 分钟前
深入理解Spring框架:核心概念与组成剖析
java·后端·spring
落霞与孤鹭齐飞。。11 分钟前
SSM社区生活超市管理
java·服务器·开发语言·数据库·生活·课程设计
哪吒编程31 分钟前
新项目终于用上了jdk24
java·后端
一只_程序媛32 分钟前
【leetcode hot 100 20】有效的括号
java·linux·leetcode
从文处安1 小时前
Vue3 + Vite 项目部署后刷新白屏问题解决方案
vue.js
LanceJiang1 小时前
Element-Plus 二次封装 el-table LeTable组件
前端·vue.js
曳渔1 小时前
多线程(续—解决线程不安全问题)(超详细)
java·开发语言·java-ee
一个爱挣扎的旺崽1 小时前
【步骤条轮子】迎合业务的步骤条
前端·vue.js