How can I make sure that only the phone and message are sent to my database because now I also have the ID of each request that was successfully saved. I want to make the phone a unique identifier by which the values for repeats will be compared in the database.
How to make phone as ID.
UserController
@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.";
}
}
User
@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;
}
}
Application
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
UserRepo
public interface UserRepo extends CrudRepository<User, Long> {
}