java实体与gxt BeanModel?的转换
?
第一种方法:
java实体bean实现BeanModelTag标识接口
?
第二种方法:
? ? ? ?新建一个新的接口继承于BeanModelMarker,并且用@BEAN(实体.class)指定java实体
?
第二种方法:
利用BeanModelFactory方法转换
?
示例:
第一种java bean:
?
public class Entity implements Serializable,BeanModelTag{ }?
第二种java bean不变,新建一个接口:
?
@BEAN(Bank.class) public interface BeankBean extends BeanModelMarker { }
?
?
gxt测试代码:
?
final RpcProxy<ListLoadResult<BeanModel>> rpcProxy = new RpcProxy<ListLoadResult<BeanModel>>() { @Override protected void load(Object loadConfig, AsyncCallback<ListLoadResult<BeanModel>> callback) { BankActionAsync bankActionAsync = Registry.get("bankAction"); bankActionAsync.getAll(callback); } };
rpcProxy.load(new BeanModelReader(), new Object(), new AsyncCallback<ListLoadResult<BeanModel>>(){ @Override public void onFailure(Throwable caught) { // TODO Auto-generated method stub System.out.println("失败"); } @Override public void onSuccess(ListLoadResult<BeanModel> result) { for(BeanModel m : result.getData()){ System.out.println(m.get("id")); System.out.println(m.get("name")); System.out.println(m.get("serviceNo")); System.out.println("---------------------"); } } });
?
第三种方法:
/** * 把bean转换成beanModel * @param o * @return */ public static BeanModel convertBeanToBeanModel(Object o){ BeanModelFactory factory = BeanModelLookup.get().getFactory(o.getClass()); return factory.createModel(o); }?
?