gpt4 book ai didi

java - spring-boot如何将手机设为ID

转载 作者:行者123 更新时间:2023-11-29 07:17:06 25 4
gpt4 key购买 nike

我怎样才能确保只有电话和消息被发送到我的数据库,因为现在我也有成功保存的每个请求的 ID。我想让手机成为唯一标识符,通过它可以在数据库中比较重复值。

如何将手机作为身份证。

用户 Controller

@RestController
@RequestMapping("/users")
public class UserController {
@Autowired
private UserRepo userRepo;
@PostMapping(consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
public String createUser(@Valid @RequestBody User requestUserDetails) {
userRepo.save(requestUserDetails);

return "The message delivered.";
}
}

用户

    @Entity
@Table(name = "ApiTable", schema = "TestApi")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

private String phone;

private String message;


public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getMessage() {
return message;
}

public void setLastName(String message) {
this.message = message;
}
}

申请

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

用户库

public interface UserRepo extends CrudRepository<User, Long> {

最佳答案

以下是根据您的示例将 phone 字段设为 Id 的方法:

@Entity
@Table(name = "ApiTable", schema = "TestApi")
public class User {

@Id
private String phone;

private String message;

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getMessage() {
return message;
}

public void setLastName(String message) {
this.message = message;
}
}

您的存储库将如下所示:

public interface UserRepo extends CrudRepository<User, String> {
}

关于java - spring-boot如何将手机设为ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58639827/

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