gpt4 book ai didi

java - 从post请求java中获取变量

转载 作者:行者123 更新时间:2023-12-01 19:20:48 25 4
gpt4 key购买 nike

我想创建一个通过 API 的其余部分发送消息的微服务。如果数据是通过 POST 请求传输的,我想立即使用该数据来发送消息。电话号码和其他数据目前是硬编码的。如何直接在 POST 请求中使用数据?


@PostMapping("/contacts")
public ResponseEntity<Object> createContact (@RequestBody Contact contact)
{

String phone_number="xxxxxxxxxxx";
String customer_phone_number="xxxxxxxxxx";

open(phone_number,customer_phone_number,custom_uid);
Contact savedContact = contactRepository.save(contact);

URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{userName}").buildAndExpand(savedContact.getUserName()).toUri();
return ResponseEntity.created(location).build();

}

有人可以帮我吗?

最佳答案



@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int contact_id;

private String userName;
private String phone_number;
private String customer_phone_number;
private String template;

public int getContact_id() {
return contact_id;
}
public void setContact_id(int contact_id) {
this.contact_id = contact_id;
}
public String getPhone_number() {
return phone_number;
}
public void setPhone_number(String phone_number) {
this.phone_number = phone_number;
}
public String getCustomer_phone_number() {
return customer_phone_number;
}
public void setCustomer_phone_number(String customer_phone_number) {
this.customer_phone_number = customer_phone_number;
}

public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}

public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Contact()
{

}
public Contact(int contact_id,String userName, String phone_number, String customer_phone_number, String template) {
super();

this.contact_id = contact_id;
this.userName=userName;
this.phone_number = phone_number;
this.customer_phone_number = customer_phone_number;

this.template = template;
}


这是我与 setter/getter 的接触类

关于java - 从post请求java中获取变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59355583/

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