泛型参数传递

  1. 请求URL:http://localhost:8081/basic_project/user/mapCode

  1. 入参出餐
{
    "requestId": "1101",
    "tenantId": "1102",
    "pin": "1104",
    "data": {
        "id": "5010",
        "name": "靳露露"
    }
}

  1. Controller
@PostMapping("/mapCode")
public Object mapCode(@RequestBody BaseRequest<Student> baseRequest) {
	System.out.println(JSON.toJSON(baseRequest));
	return JSON.toJSON(baseRequest);
}
  1. 泛型
package com.hxh.basic.project.controller.pojo;

import lombok.Data;

import java.io.Serializable;

/**
 * @program wdb-gateway
 * @author: jy
 * @create: 2021/02/26 13:45
 */
@Data
public class BaseRequest<T> implements Serializable {
    private static final long serialVersionUID = -8380835582974221590L;
    private String requestId;
    private Long tenantId;
    private String pin;
    private T data;
}
  1. 实体类
package com.hxh.basic.project.controller.pojo;

import lombok.Data;

import java.io.Serializable;

@Data
public class Student implements Serializable {
    private static final long serialVersionUID = -2674800810779287798L;

    private Integer id;
    private String name;
}
上一篇:git报remote HTTP Basic Access denied错误的解决方法


下一篇:蓝桥杯:BASIC-8——回文数