//hibernate查询部分字段转换成实体bean

    /*** 查询线路信息*/@Overridepublic List<Line> getSimpleLineListByTj(Map<String,Object>paramMap){

Criteria cr
=this.getSession().createCriteria(Line.class,"Line");//cr.setFetchMode("chuTuanInfo", FetchMode.JOIN);//Criteria teamche=cr.createAlias("chuTuanInfo","chuTuanInfo", JoinType.LEFT_OUTER_JOIN);//Criteria teamPlanCR=cr.createAlias("teamplan","teamplan", JoinType.LEFT_OUTER_JOIN); ProjectionList pList=Projections.projectionList();//pList.add(Projections.property("id"));//pList.add(Projections.property("linename")); pList.add(Projections.alias(Projections.property("id"), "id"));//使用别名才能aliasToBean到Line pList.add(Projections.alias(Projections.property("linename"), "linename"));//pList.add(Projections.property("teamplan.renshu")); cr.setProjection(pList);//FaTuanState.getMap();//List<String> propertyNameList = new ArrayList();//propertyNameList.add("id");//propertyNameList.add("linename");//List list = getListWithPartProperty(cr, propertyNameList);//Map<String,Object> paramMap = new HashMap<String,Object>();//paramMap.put(key, value); cr.add(Restrictions.ne("state", FaTuanState.TINGFA));//《》停发和暂停的 cr.add(Restrictions.ne("state", FaTuanState.ZANTING));if(paramMap.get("areaid")!=null && !StringUtils.isBlank(paramMap.get("areaid").toString())){
cr.add(Restrictions.eq(
"jingqu.id", Integer.parseInt(paramMap.get("areaid").toString())));
}


cr.addOrder(Order.asc(
"linename"));
cr.setResultTransformer(Transformers.aliasToBean(Line.
class));returncr.list();
}

 

通过java反射得到javabean的属性名称和值

Field fields[]
=cHis.getClass().getDeclaredFields();//cHis 是实体类名称 String[] name=newString[fields.length];
Object[] value
=newObject[fields.length];try{
Field.setAccessible(fields,
true);for (int i = 0; i < name.length; i++) {
name[i]
=fields[i].getName();
System.out.println(name[i]
+ "-> ");
value[i]
= fields[i].get(cHis);//cHis 是实体类名称 System.out.println(value[i]);
}
}
catch(Exception e) {
e.printStackTrace();
}


通过反射获取类属性字段 以及 调用类方法 以下方法未测试应该可以
public classModelClassHelper {public static HashMap<String,Class>init(String classPath)
{
try{//"com.geocompass.model.STSTBPRPModel" HashMap<String,Class> fieldHashMap=new HashMap<String,Class>();
Class cls
= Class.forName(classPath); //com.geocompass.model.STSTBPRPModel Field[] fieldlist =cls.getDeclaredFields();for (int i = 0; i < fieldlist.length; i++) {
Field fld
=fieldlist[i];
fieldHashMap.put(fld.getName(), fld.getType());
//System.out.println("name = " + fld.getName());//System.out.println("decl class = " + fld.getDeclaringClass());//System.out.println("type = " + fld.getType());//System.out.println("-----"); }returnfieldHashMap;
}
catch(ClassNotFoundException e) {//TODO Auto-generated catch block e.printStackTrace();
}
return null;
}
public staticString getTableName(String classPath)
{
try{
Class cls
=Class.forName(classPath);
Method test
=cls.getDeclaredMethod("getTableName");
Object invoke
=test.invoke(cls.newInstance());returninvoke.toString();//cls.asSubclass(TabModel.class); } catch(ClassNotFoundException e) {//TODO Auto-generated catch block e.printStackTrace();
}
catch(SecurityException e) {//TODO Auto-generated catch block e.printStackTrace();
}
catch(NoSuchMethodException e) {//TODO Auto-generated catch block e.printStackTrace();
}
catch(IllegalArgumentException e) {//TODO Auto-generated catch block e.printStackTrace();
}
catch(IllegalAccessException e) {//TODO Auto-generated catch block e.printStackTrace();
}
catch(InvocationTargetException e) {//TODO Auto-generated catch block e.printStackTrace();
}
catch(InstantiationException e) {//TODO Auto-generated catch block e.printStackTrace();
}
return "";
}}

利用反射技术动态获取任意Java类实例的属性值
packageorg.apache.easframework.core.entity.impl;importjava.lang.reflect.Field;public classTestEntity {privateString code;privateString name;public voidsetCode(String code)
{
this.code =code;
}
publicString getCode()
{
return this.code;
}
public voidsetName(String name)
{
this.name =name;
}
publicString getName()
{
return this.name;
}
public static void main(String[] args) throwsSecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException
{
TestEntity obj
= newTestEntity();
obj.setName(
"name value");
obj.setCode(
"code value");
Field[] fds
=Class.forName
(
"org.apache.easframework.core.entity.impl.TestEntity").getDeclaredFields();

System.out.println(fds.length);
for(int i=0;i<fds.length;i++)
{
System.out.println(fds[i].get(obj));

}
}

}

 

表格行计算 总金额:functionjisuanTrJinE(obj){var curTab = $(obj).closest("table");var curTr = $(obj).closest("tr");var curTabId = curTab.attr("id");var zongJinE = 0;//alert(curTabId);


             var danjia =  curTr.find("input[class='danjia']").val();var shuliang =  curTr.find("input[class='shuliang']").val();if(danjia==""){ danjia=0;}if(shuliang==""){ shuliang=0;} 
zongJinE
= danjia*shuliang;




curTr.find(
"input[class='jinE']").val(zongJinE); }

 

计算class 求和:
(function($) {
	var plugName = "mathutil";
	var mathutil = {
		addUp : function($obj) {
			var result=0;
			$obj.each(function (i,n){
				 var $n=$(n);
				 var num=Number($n.val());
				 if(!isNaN(num)){
					 result+=num;
				 }
			});
			return result;
		}
	};
	window.mathutil=mathutil;
})(jQuery);

调用:	var yifu=mathutil.addUp($(".yifu"));
	$("#yifu").val(yifu);

  

免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。