gpt4 book ai didi

java - 如何将大量值传递到 GET 请求参数中

转载 作者:行者123 更新时间:2023-12-01 22:17:09 26 4
gpt4 key购买 nike

我在我的项目中使用了 spring boot 和 post man。在 Controller 中,我使用了方法获取所有类别,如下所示:

@GetMapping(value = "/category")
@ResponseStatus(HttpStatus.OK)
public List<ReadableCategory> findAllCategories(@RequestParam(value = "filter", required = false) List<String> filter, MerchantStore store, Language language) {
return categoryService.findCategories(store, 0, language, filter);
}

商品商店:

public class MerchantStore implements Auditable {

private final static String DEFAULT_STORE = "DEFAULT";

@Id
@Column(name = "MERCHANT_ID", unique = true, nullable = false)
@TableGenerator(name = "TABLE_GEN", table = "SM_SEQUENCER", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "STORE_SEQ_NEXT_VAL")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_GEN")
@JsonProperty(

"merchant_id")
private Integer id;

@Column(name = "STORE_NAME", nullable = true, length = 100)
@JsonProperty(value = "store_name")
private String storeName;

@Pattern(regexp = "^[a-zA-Z0-9_]*$")
@Column(name = "STORE_CODE", nullable = true, unique = true, length = 100)
@JsonProperty(value = "merchant_id")
private String code;

@Column(name = "STORE_PHONE", length = 50)
private String storePhone;

@Column(name = "STORE_ADDRESS")
private String storeAddress;

@Column(name = "STORE_CITY", length = 100)
private String storeCity;

@Column(name = "STORE_POSTAL_CODE", length = 15)
private String storePostcode;

@ManyToOne(fetch = FetchType.LAZY, targetEntity = Country.class)
@JoinColumn(name = "COUNTRY_ID", nullable = true)
private Country country;

@ManyToOne(fetch = FetchType.LAZY, targetEntity = Zone.class)
@JoinColumn(name = "ZONE_ID", nullable = true)
private Zone zone;

@Column(name = "STORE_STATE_PROV", length = 100)
private String storeStateProvince;

@Column(name = "WEIGHTUNITCODE", length = 5)
private String wightUnitCode = MeasureUnit.LB.name();

@Column(name = "SEIZEUNITCODE", length = 5)
private String seizeUnitCode = MeasureUnit.IN.name();

@Column(name = "IN_BUSINESS_SINCE")
private LocalDate inBusinessSince = LocalDate.now();

@Transient
private String dateBusinessSince;

@ManyToOne(fetch = FetchType.LAZY, targetEntity = Language.class)
@JoinColumn(name = "LANGUAGE_ID", nullable = false)
private Language defaultLanguage;

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "MERCHANT_LANGUAGE")
private List<Language> languages = new ArrayList<>();

//some thing fields and get/set methods

语言.class

@Id
@Column(name = "LANGUAGE_ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

@Embedded
private AuditSection auditSection = new AuditSection();

@Column(name = "CODE", nullable = false)
private String code;

@Column(name = "SORT_ORDER")
private Integer sortOrder;

@OneToMany(mappedBy = "defaultLanguage",targetEntity = MerchantStore.class)
@ToString.Exclude
@JsonIgnoreProperties
private List<MerchantStore> storesDefaultLanguage;

@ManyToMany(mappedBy = "languages",targetEntity = MerchantStore.class,fetch = FetchType.EAGER)
@ToString.Exclude
@JsonIgnoreProperties
private List<MerchantStore> stores = new ArrayList<>();

public String getCode() {
return code;
}

当我向 postman 请求时,如下所示: http://localhost:8585/api/v1/id=1&storeName=2&code=3&languages=1,2,3

它可以工作,但是因为当我请求所有字段时,我的 MerchanStore 类有很多字段。示例:10 个字段,我的 url 非常长且复杂。我有两个问题:

  • 有没有更好的方法来发布参数而不把它放在上面 使用 GET 请求(不是 Post 请求)的 url。

  • 当我输入 id=1 时,因为 MerchanStore 类包含 id 和语言也包含id,它放相同的值1.如何具体值
    带 ID 的 MerchanStore 和带 ID 的语言。

最佳答案

Is there a better way to post the param without putting it on the url using GET request(not Post Request).

没有。使用带有请求参数的 GET 表示您的 URL 可以添加书签。特别是对于搜索或过滤目的,非常方便和有用。

When i put id=1, because class MerchanStore contain id and language also contain id, it put same value 1. How to specific value MerchanStore with Id and Language with Id.

我对此一无所知,也许你可以将其作为一个新问题发布。

关于java - 如何将大量值传递到 GET 请求参数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58618246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com