1

如何使用服务构建器 liferay 保存自定义实体?我创建新实体(名称=BasicProfile)并由服务构建器liferay构建,但保存时发生异常。我的代码:

    BasicProfile basicProfile = new BasicProfileImpl();
    basicProfile.setUserId(11701L);

    basicProfile.setBirthCertificateSerial(birthCertificate);
    basicProfile.setCreateDate(new Date());
    basicProfile.setFatherName(fatherName);
    basicProfile.setExtCustId(acceptorNumber);
    basicProfile.setMobileNumber(telNumber);
    basicProfile.setNationalCode(nationalCode);
   basicProfile = BasicProfileLocalServiceUtil.addBasicProfile(basicProfile);  
4

1 回答 1

1
  1. 在您的 BasicProfileLocalServiceImpl.java 中创建以下方法:

    public BasicProfile create(long userId, String birthCertificate, String fatherName, String acceptorNumber, String telNumber, String nationalCode) throws Exception {
        long id = counterLocalService.increment();
        BasicProfile obj = createBasicProfile(id);
        obj.setUserId(userId);
        obj.setBirthCertificateSerial(birthCertificate);
        obj.setCreateDate(new Date());
        obj.setFatherName(fatherName);
        obj.setExtCustId(acceptorNumber);
        obj.setMobileNumber(telNumber);
        obj.setNationalCode(nationalCode);
        obj = updateProduct(obj);
        return obj;
    }
    
  2. 然后在您的代码中调用该方法来创建一个新对象:

    BasicProfile basicProfile = BasicProfileLocalServiceUtil.create(userId, birthCertificate, fatherName, acceptorNumber, telNumber, nationalCode);
    
于 2015-01-05T09:35:04.380 回答