[英]java.lang.NoSuchMethodException: com…Employee.<init>()
I have this class for which I have a constructor: 我有一个我有一个构造函数的类:
@Entity
data class Employee(
@field: Id
@field:GeneratedValue var id : Long = 0,
var username : String = "",
var password : String ="",
var name : String ="",
var lastName: String ="",
var phone : String="",
var email : String ="",
var sex : String ="",
var active : Boolean = false,
@field: ManyToOne(targetEntity = District::class)
var district : District?,
@field: ManyToOne(targetEntity = Company::class)
var company : Company?,
var picture:String="",
var resetPasswordCode:String="",
// código que se le envía al usuario en el momento que crea
// la cuenta, deberá abrir en enlace del correo para activarla
// de ahí que "active" sea false.
var activationCode : String="",
var enabled : Boolean = true,
var accountNonExpired: Boolean = true,
var credentialsNonExpired: Boolean = true,
var accountNonLocked : Boolean = true,
@field: OneToMany(targetEntity = Roles::class) var roles :MutableSet<Roles> = mutableSetOf())
{
fun toUser() : User
{
val authorities = mutableSetOf<GrantedAuthority>()
roles.forEach{authorities.add(SimpleGrantedAuthority(it.role))}
return User(username,password,enabled,accountNonExpired,credentialsNonExpired,accountNonLocked, authorities)
}
}
I have a controller method and for testing, I just print the "saving" text (as I'm having this issue, it doesn't make sense (to me) to go any further): 我有一个控制器方法,为了进行测试,我只打印“保存”文本(因为我遇到了这个问题,(对我来说)继续进行是没有意义的):
@RequestMapping(method = arrayOf(RequestMethod.POST))
fun doPost(employee: Employee) : String {
println("saving!!!")
// employeeService.save(employee)
return "redirect:/display"
}
When sending the form, I get this error: 发送表单时,出现此错误:
java.lang.NoSuchMethodException: com.almasoft.facturapp.entities.Employee.<init>()
The form is this: 形式是这样的:
<form th:action="@{/register}" method="post" role="form"
th:object="${employee}">
<legend>Register a User</legend>
<div class="form-group">
<label for="username">User Name</label>
<input type="text" class="form-control" name="username" id="username" th:field="*{username}"></input>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" id="password" th:field="*{password}"></input>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
I'm following this post and adapting the code for my needs, but I can't get this to work :( 我正在关注这篇文章并根据我的需要调整代码,但我无法使它起作用:(
So, why would it complain about a default constructor if there is already one? 那么,为什么要抱怨默认的构造函数呢?
And: how can I solve this? 并且:我该如何解决?
@field: ManyToOne(targetEntity = District::class)
var district : District?,
@field: ManyToOne(targetEntity = Company::class)
var company : Company?,
These don't have default values so empty constructor is not generated. 这些没有默认值,因此不会生成空的构造函数。
Add = null
to each. 向每个添加
= null
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.