简体   繁体   English

java.lang.NoSuchMethodException:com…员工。 <init> ()

[英]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.

相关问题 java.lang.NoSuchMethodException:userAuth.User。<init> ()</init> - java.lang.NoSuchMethodException: userAuth.User.<init>() java.lang.NoSuchMethodException:未知属性“ activePackage” - java.lang.NoSuchMethodException: Unknown property ' activePackage' 启动服务器时出现异常:java.lang.NoSuchMethodException:org.springframework.security.authentication.ProviderManager。<init>() - Exception while starting up the server : java.lang.NoSuchMethodException: org.springframework.security.authentication.ProviderManager.<init>() java.lang.NoSuchMethodException: org.springframework.boot.autoconfigure.web.HttpMessageConverters$$EnhancerBySpringCGLIB$$3ba87c15。<init> () - java.lang.NoSuchMethodException: org.springframework.boot.autoconfigure.web.HttpMessageConverters$$EnhancerBySpringCGLIB$$3ba87c15.<init>() 找不到默认的构造函数; 嵌套的异常是java.lang.NoSuchMethodException - No default constructor found; nested exception is java.lang.NoSuchMethodException Spring 请求处理失败; 嵌套异常是 java.lang.NoSuchMethodException: - Spring Request processing failed; nested exception is java.lang.NoSuchMethodException: 错误:java.lang.NoSuchMethodException: java.lang.Long.() in spring MVC - Error: java.lang.NoSuchMethodException: java.lang.Long.() in spring MVC java.lang.NoSuchMethodException:java.lang.String.substring(java.lang.Long,java.lang.Long) - java.lang.NoSuchMethodException: java.lang.String.substring(java.lang.Long, java.lang.Long) 未找到默认构造函数; 嵌套异常是 java.lang.NoSuchMethodException 与 Spring MVC? - No default constructor found; nested exception is java.lang.NoSuchMethodException with Spring MVC? SpringMVC Apache Tomcat 7.0 java.lang.NoSuchMethodException:org.apache.catalina.deploy.WebXml addFilter - SpringMVC apache tomcat 7.0 java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addFilter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM