I have done this is the past with mySQL but I need to use Oracle:
This is a very simple register user:
application.properties
#Oracle database setup
spring.datasource.url=jdbc:oracle:thin:@999.999.999.11:1521:d3SID
spring.datasource.username=userName
spring.datasource.password=password
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
server.port = 4000
UserInformation model
@Entity
public class UserInformation {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
@Column(name = "firstName")
@Min(2) @Max(15)
@NotNull
private String firstName;
@Column(name = "lastName")
private String lastName;
@Column(name = "userName")
private String userName;
@Column(name = "password")
private String password;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof UserInformation)) {
return false;
}
UserInformation that = (UserInformation) o;
return id.equals(that.id);
}
@Override
public int hashCode() {
return id.hashCode();
}
@Override
public String toString() {
return "Applicant{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + ", userName='" + userName + '\'' + ", password='" +
password + '\'' + '}';
}
}
JPA repo
public interface UserLoginRepo extends JpaRepository<UserInformation, Long> {}
Controller method
@RequestMapping(value = "/register", method = RequestMethod.POST)
public UserInformation registerUser(@RequestBody UserInformation user){
return userService.save(user);
}
When I run SELECT * FROM USERINFORMATION;
nothing displays.
From my understanding I should not need to set up JPA config since I am doing it in applications.properties
.
答案 0 :(得分:-1)
您是否检查过UserInformation对象是否来自请求正文?据我所知,您不应该使用“@ RequestBody”,只需将“UserInformation用户”放在参数中。