예제 #1
0
  @Test
  public void testCopy() {
    MyName myName = new MyName();
    myName.setName("wanghognfei");

    YourName yourName = new YourName();
    BeanCopier bc = BeanCopier.create(MyName.class, YourName.class, false);

    bc.copy(myName, yourName, null);
    Assert.assertEquals(myName.getName(), yourName.getName());

    System.out.println("LV0".compareTo("VIP1"));
  }
 public String editAction() { // get data
   String result = null;
   clearErrorMessages();
   IAuthorityRoleService<AuthorityRole, String> objService =
       (IAuthorityRoleService<AuthorityRole, String>)
           SpringFacesUtil.getSpringBean(
               PlatformSpringBeanConstants.AUTHORITY_ROLE_SERVICE_BEAN_NAME);
   objService.setEntityClass(AuthorityRole.class);
   objService.setPKClass(String.class);
   String objId = (String) SpringFacesUtil.getRequestParameter("objId");
   AuthorityRole obj = objService.findById(objId);
   AuthorityRoleVo objVo = new AuthorityRoleVo();
   BeanCopier copyHere = BeanCopier.create(AuthorityRole.class, AuthorityRoleVo.class, false);
   copyHere.copy(obj, objVo, null);
   this.setAction(PlatformConstants.ACTION_EDIT_TYPE);
   this.setEdit(objVo);
   return result;
 }
 public String saveAction() { // create new
   String result = null;
   clearErrorMessages();
   validator(this.getErrorMessages(), this.getEdit());
   if (!(this.getErrorMessages().isEmpty())) {
     return null;
   }
   IAuthorityRoleService<AuthorityRole, String> objService =
       (IAuthorityRoleService<AuthorityRole, String>)
           SpringFacesUtil.getSpringBean(
               PlatformSpringBeanConstants.AUTHORITY_ROLE_SERVICE_BEAN_NAME);
   objService.setEntityClass(AuthorityRole.class);
   objService.setPKClass(String.class);
   if (null != this.getEdit() && !("".equals(this.getEdit().getName()))) {
     AuthorityRole theObj = objService.findUniqueBy("name", this.getEdit().getName()); //
     if (null != theObj) {
       String hasExistErrorN18 =
           MessageFactory.getMessage(
                   PlatformConstants.USER_BUNDLE_NAME,
                   "role.has.exist.error.message",
                   FacesMessage.SEVERITY_ERROR)
               .getDetail();
       this.getErrorMessages().add(hasExistErrorN18);
     }
   }
   if (!(this.getErrorMessages().isEmpty())) {
     return null;
   }
   AuthorityRole newObj = new AuthorityRole();
   BeanCopier copyHere = BeanCopier.create(AuthorityRoleVo.class, AuthorityRole.class, false);
   copyHere.copy(this.getEdit(), newObj, null);
   // 设置通用的修改数据属性 修改时间和修改人
   try {
     EntityDataUtil<AuthorityRole, String> currUtil = new EntityDataUtil<AuthorityRole, String>();
     currUtil.setCreatePropertyValue(newObj);
   } catch (Exception e) {
     return result;
   } finally {
     // do nothing;//关闭session的时候还会报,并且在session那里抓取了所有的Exception。
   }
   // end
   objService.save(newObj);
   return result;
 }