grails找不到匹配的构造函数:somiti.JointMember(java.lang.String)

时间:2017-02-12 11:41:48

标签: java grails grails-2.0 grails-domain-class

我正在使用grails 2.4.2。我有一个域名作为JointMemberInvestment,其中一个hava是JointMember类的实例。但是当我想保存数据时,它会给我以下错误: Could not find matching constructor for: somiti.JointMember(java.lang.String)

任何人都可以帮助我吗?以下是我的尝试:

我的域名类:

    class JointMemberInvestment {

    JointMember jointMember
    int investAmount
    Date investDate

    static mapping = {
        table('joint_member_investment')
        version defaultValue: 0
    }

    static constraints = {
        investAmount(nullable: false, blank: false)
        investDate(nullable: false, blank: false)
    }
}

我的控制器保存方法:

@Transactional
def save(JointMemberInvestment jointMemberInvestmentInstance) {
    if (jointMemberInvestmentInstance == null) {
        notFound()
        return
    }

    String investDate = params.investDate;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(investDate);
    java.sql.Date sqlInvestDate = new java.sql.Date(date.getTime());

    jointMemberInvestmentInstance.investDate = sqlInvestDate
    jointMemberInvestmentInstance.jointMember = JointMember.get(Long.parseLong(params.jointMemberId))        

    if (jointMemberInvestmentInstance.hasErrors()) {
        respond jointMemberInvestmentInstance.errors, view: 'create'
        return
    }

    jointMemberInvestmentInstance.save flush: true

    request.withFormat {
        form multipartForm {
            flash.message = message(code: 'default.created.message', args: [message(code: 'jointMemberInvestment.label', default: 'JointMemberInvestment'), jointMemberInvestmentInstance.id])
            redirect jointMemberInvestmentInstance
        }
        '*' { respond jointMemberInvestmentInstance, [status: CREATED] }
    }
}

1 个答案:

答案 0 :(得分:0)

jointMemberInvestmentInstance.investDate = sqlInvestDate
    jointMemberInvestmentInstance.jointMember = JointMember.get(Long.parseLong(params.jointMemberId))        

bindData(jointMemberInvestmentInstance, params, [exclude:['JointMember']])

    if (jointMemberInvestmentInstance.hasErrors()) {
        respond jointMemberInvestmentInstance.errors, view: 'create'
        return
    }

可能会对你有帮助。