【问题标题】:User information is not persistenting to Oracle Database用户信息未保存到 Oracle 数据库
【发布时间】:2017-03-02 22:02:28
【问题描述】:

我已经用 mySQL 做到了,但我需要使用 Oracle:

这是一个非常简单的注册用户:

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

用户信息模型

@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 回购

public interface UserLoginRepo extends JpaRepository<UserInformation, Long> {}

控制器方法

@RequestMapping(value = "/register", method = RequestMethod.POST)
    public UserInformation registerUser(@RequestBody UserInformation user){

        return userService.save(user);
    }

当我运行 SELECT * FROM USERINFORMATION; 时,什么都没有显示。

据我了解,我不需要设置 JPA 配置,因为我在 applications.properties 中进行设置。

【问题讨论】:

  • 您在哪里运行select,如果您使用的是 JPA,为什么?为什么省略了相关部分?如果什么都没有显示,是没有什么可显示的还是你只是在吞咽异常?
  • @Kayaman 我更喜欢使用 JPA,我 public interface UserLoginRepo extends JpaRepository&lt;UserInformation, Long&gt; {} 有 CRUD,所以不需要编写 select 语句。
  • 啊,我看错了你的问题。您正在程序外部运行 select 以检查是否保存了某些内容。无论如何,请检查您的日志并通过调试器运行它。

标签: java spring oracle spring-data spring-data-jpa


【解决方案1】:

您是否检查了 UserInformation 对象是否来自请求正文?我知道你不应该使用 "@RequestBody",只需将 "UserInformation user" 放在参数中即可。

【讨论】:

  • 这应该是评论,它没有回答问题。
猜你喜欢
  • 1970-01-01
  • 2011-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-06
  • 2020-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多