使用龙目岛与格雷尔和弹簧靴
2022-09-01 13:54:53
我正在尝试用龙目岛构建一个项目,这就是我作为依赖项所拥有的。
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.social:spring-social-facebook")
compile("org.springframework.social:spring-social-twitter")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("junit:junit")
compile("org.springframework.boot:spring-boot-devtools")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("mysql:mysql-connector-java")
compileOnly("org.projectlombok:lombok:1.16.10")
}
我能够包括注释,并且我已经在编辑器中包括了龙目岛。我甚至能够使用龙目岛编译代码,并对龙目岛生成的方法进行cal。
这是我的实体:
@Data
@Entity
@Table(name = "TEA_USER", uniqueConstraints = {
@UniqueConstraint(columnNames = { "USR_EMAIL" }),
@UniqueConstraint(columnNames = { "USR_NAME" })
})
public class User {
@NotNull
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="USR_ID")
private long id;
@NotNull
@Column(name="USR_FNAME")
private String firstName;
@NotNull
@Column(name="USR_LNAME")
private String lastName;
@NotNull
@Min(5)
@Max(30)
@Column(name="USR_NAME")
private String username;
@Column(name="USR_EMAIL")
private String email;
@Min(8)
@NotNull
@Column(name="USR_PASSWORD")
private String password;
}
这是一个编译良好的函数:
@PostMapping("/registration/register")
public String doRegister (@ModelAttribute @Valid User user, BindingResult result){
user.getEmail();
System.out.println(user.getFirstName());
if (result.hasErrors()) {
return "register/customRegister";
}
this.userRepository.save(user);
return "register/customRegistered";
}
但是当我运行bootRun并且我尝试访问功能时,这是我得到的异常:
org.springframework.beans.NotReadablePropertyException: Invalid property 'firstName' of bean class [com.lucasfrossard.entities.User]: Bean property 'firstName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
但是,如果我手动包括 setter 和 getters,这工作正常。我不明白发生了什么以及如何解决它。有什么想法吗?