1、List<实体>数据:

public List<Device> queryOSDevice(String cpu,String ip,String name){
String sql = null;
if(cpu.equals("os_xp")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsXP') ";
}else if(cpu.equals("os_7")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows7') ";
}else if(cpu.equals("Os_Win8")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows81') ";
}else if(cpu.equals("Os_Win10")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows10InsiderPreview') ";
}else if(cpu.equals("os_vista")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsVista') ";
}else if(cpu.equals("os_2003")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsServer2003') ";
}else if(cpu.equals("os_98")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows98') ";
}else if(cpu.equals("os_95")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows95') ";
}else if(cpu.equals("os_me")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsMe') ";
}else if(cpu.equals("os_nt")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsNt') ";
}else if(cpu.equals("os_2000")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows2000') ";
}
if(!"".equals(ip) && !"".equals(name)){
sql += "and this.ip =:ip and this.name = :name ";
return getSession().createQuery(sql)
.setParameter("ip", ip)
.setParameter("name", name)
.list();
}
if(!"".equals(ip) && "".equals(name)){
sql += "and this.ip =:ip ";
return getSession().createQuery(sql)
.setParameter("ip", ip)
.list();
}
if("".equals(ip) && !"".equals(name)){
sql += "and this.name = :name ";
return getSession().createQuery(sql)
.setParameter("name", name)
.list();
}
return getSession().createQuery(sql).list();
}

2、List<String>数据:

public List<String> queryOSDevice(String cpu,String ip,String name){
String sql = null;
List<String> osDevice = new ArrayList<String>();
if(cpu.equals("os_xp")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsXP') ";
}else if(cpu.equals("os_7")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows7') ";
}else if(cpu.equals("Os_Win8")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows81') ";
}else if(cpu.equals("Os_Win10")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows10InsiderPreview') ";
}else if(cpu.equals("os_vista")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsVista') ";
}else if(cpu.equals("os_2003")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsServer2003') ";
}else if(cpu.equals("os_98")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows98') ";
}else if(cpu.equals("os_95")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows95') ";
}else if(cpu.equals("os_me")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsMe') ";
}else if(cpu.equals("os_nt")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsNt') ";
}else if(cpu.equals("os_2000")){
sql = "select this.ip,this.mac,this.ipNumber,this.name,this.devOnlyId,this.cpuType,this.memorySize,this.diskSize from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows2000') ";
}
if(!"".equals(ip)){
sql += "and this.ip = '" + ip +"'";
}
if(!"".equals(name)){
sql += "and this.name = '" + name + "'";
}
osDevice = getSession().createQuery(sql).list();
return osDevice;
}

  注意:List<String>里面标红处需要注意的项,看下面这篇博客:常见Hibernate报错处理:出现“org.hibernate.QueryException: could not resolve property”和 is not mapped和could not locate named parameter错误的解决

List<Object>:

public List<Object> queryCountByOsAndOrgname(String cpu,String orgName) {
List<Object> list = new ArrayList<Object>();
String sql = null;
if(cpu.equals("os_xp")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsXP') ";
}else if(cpu.equals("os_7")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows7') ";
}else if(cpu.equals("os_win8")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows81') ";
}else if(cpu.equals("os_win10")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows10InsiderPreview') ";
}else if(cpu.equals("os_vista")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsVista') ";
}else if(cpu.equals("os_2003")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsServer2003') ";
}else if(cpu.equals("os_98")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows98') ";
}else if(cpu.equals("os_95")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows95') ";
}else if(cpu.equals("os_me")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsMe') ";
}else if(cpu.equals("os_nt")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsNt') ";
}else if(cpu.equals("os_2000")){
sql = "select count(*) from " + this.clazz.getName() + " this where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows2000') ";
}
if(!"".equals(orgName)){
sql += "and this.organization.name = '" + orgName + "'";
}
Number number = (Number)getSession().createQuery(sql).uniqueResult();
if(number==null){
number = ;
}
JSONObject jsonObject = new JSONObject();
jsonObject.put(orgName, number);
list.add(jsonObject);
return list;
}

List<Object>数据需要改一下:就是根据os查出来所有的数据,然后再根据orgName去分组,需要各orgName分组的数目;需要传递过去的接口数据类型如下:
[{"classid":"姚佳豪","value":1}, {"classid":"测试一部","value":1}, {"classid":"王明明","value":3}, {"classid":"陈锋","value":2}, {"classid":"黄睿","value":1}]

根据数据库查出来的数据如下:

@SuppressWarnings("unchecked")
public List<Object> queryCountByOsAndOrgname(String cpu,Integer orgName) {
List<Object> list = new ArrayList<Object>();
String sql = null;
if(cpu.equals("os_xp")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsXP') ";
}else if(cpu.equals("os_7")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where d.osId = (select id from cems_dict_os o where o.name = 'com.vrv.common.system.os.Windows7') ";
}else if(cpu.equals("os_win8")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows81') ";
}else if(cpu.equals("os_win10")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows10InsiderPreview') ";
}else if(cpu.equals("os_vista")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsVista') ";
}else if(cpu.equals("os_2003")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsServer2003') ";
}else if(cpu.equals("os_98")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows98') ";
}else if(cpu.equals("os_95")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows95') ";
}else if(cpu.equals("os_me")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsMe') ";
}else if(cpu.equals("os_nt")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsNt') ";
}else if(cpu.equals("os_2000")){
sql = "select count(*),c.name from cems_device d,cems_organization c "
+ "where this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows2000') ";
}
if(- == orgName){
sql += "and d.organizationId = c.id group by d.organizationId ";
}
List<Object[]> listobj = getSession().createSQLQuery(sql).list();
//注意List里面是Object[]对象数组的类型,这样下面listobj.get(i)[1],才可以获取到
for(int i = ; i < listobj.size(); i++){
JSONObject jsonObject = new JSONObject();
jsonObject.put("classid", listobj.get(i)[]);
jsonObject.put("value", listobj.get(i)[]);
list.add(jsonObject);
}
return list;
}

3、List<Device>实体数据:

public List<Device> queryOSDevice(String cpu,String ip,String name,String orgname){
String sql = null;
List<Device> osDevice = new ArrayList<Device>();
if(cpu.equals("os_xp")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsXP') ";
}else if(cpu.equals("os_7")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows7') ";
}else if(cpu.equals("Os_Win8")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows81') ";
}else if(cpu.equals("Os_Win10")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows10InsiderPreview') ";
}else if(cpu.equals("os_vista")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsVista') ";
}else if(cpu.equals("os_2003")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsServer2003') ";
}else if(cpu.equals("os_98")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows98') ";
}else if(cpu.equals("os_95")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows95') ";
}else if(cpu.equals("os_me")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsMe') ";
}else if(cpu.equals("os_nt")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsNt') ";
}else if(cpu.equals("os_2000")){
sql = " from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows2000') ";
}
if(!"".equals(ip)){
sql += "and this.ip = '" + ip +"'";
}
if(!"".equals(name)){
sql += "and this.name = '" + name + "'";
}
if(!"".equals(orgname)){
sql += "and this.organization.name = '" + orgname + "'";
}
osDevice = getSession().createQuery(sql).list();
return osDevice;
}

  表里关联的是:

  映射XML文件:

<!-- 所属组织机构 -->
<many-to-one name="organization" class="com.vrv.cems.mgr.domain.Organization" not-null="true" column="organizationId" not-found="ignore"/>

  这种写法:this.organization.name,能取到organization表里的name。

List<实体>与List<String>数据互转的更多相关文章

  1. 基于MVC4+EasyUI的Web开发框架经验总结(3)- 使用Json实体类构建菜单数据

    最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采用EasyUI的前端界面处理技术,走MVC的技术路线,在重 ...

  2. 自动匹配HTTP请求中对应实体参数名的数据(性能不是最优)

    /// <summary> /// 获取请求参数字段 /// </summary> /// <typeparam name="T"></t ...

  3. 使用Json实体类构建菜单数据

    基于MVC4+EasyUI的Web开发框架经验总结(3)- 使用Json实体类构建菜单数据 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框 ...

  4. Json、JavaBean、String等互转

    Json.JavaBean.String等互转 本文介绍简单的Json.JavaBean.String互换(下文JavaBean简称Object对象,这里不是很严谨) 转换关系如下: 其中String ...

  5. ASP.NET实现二维码 ASP.Net上传文件 SQL基础语法 C# 动态创建数据库三(MySQL) Net Core 实现谷歌翻译ApI 免费版 C#发布和调试WebService ajax调用WebService实现数据库操作 C# 实体类转json数据过滤掉字段为null的字段

    ASP.NET实现二维码 using System;using System.Collections.Generic;using System.Drawing;using System.Linq;us ...

  6. 匿名类型 使用泛型T linq返回dynamic类型的匿名实体 如何把匿名类型.GetType()返回的对象传进泛型里面 EF实体查询出的数据List<T>转DataTable出现【DataSet 不支持 System.Nullable<>】的问题

    [100分]紧急求助:LinQ下使用IQueryable<T>如何将返回类型<T>使用匿名类型 问题描述如下:我有一个方法如下:public IQueryable Dissen ...

  7. Mybatis中实体类属性和数据列之间映射的四种办法

    http://blog.csdn.net/lmy86263/article/details/53150091 Mybatis不像hibernate中那么自动化,通过@Column注解或者直接使用实体类 ...

  8. (转)基于MVC4+EasyUI的Web开发框架经验总结(3)- 使用Json实体类构建菜单数据

    http://www.cnblogs.com/wuhuacong/p/3669708.html 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开 ...

  9. C# 实体类转json数据过滤掉字段为null的字段

    C# 实体类转json数据过滤掉字段为null的字段 语法如下: var jsonSetting = new JsonSerializerSettings {NullValueHandling = N ...

随机推荐

  1. EffectiveJava读书笔记

    less, but is more. 创建和销毁对象 避免创建不必要对象 消除过期的对象引用 使可变性最小 泛型 用标记接口定义类型 检查参数有效性 返回零长度的数组或集合,而不是null 需要精确答 ...

  2. 内置函数补充,__str__方法、__del__方法 和 __call__方法和元祖

    一 .内置函数补充 1.isinstance函数: isinstance(obj,cls)检查obj是否是类 cls 的对象 使用该函数来判断一个函数的类型 2. issubclass(sub, su ...

  3. nginx1.11.9 apt即源码编译各平台测试

    测试系统:ubuntu16.04 server,debian8.7 netinstall,centos7 mini. 系统配置:使用virtualbox安装,内存1G,cpu单核,物理CPU  i5- ...

  4. 1.docker镜像

    1.docker的安装 安装 wget -qO- https://get.docker.com/ | sh 启动docker后台服务 sudo service docker start 测试运行hel ...

  5. 【 Keepalived 】Nginx or Http 主-备模式

    一.主-备模式: 操作系统:centos 6.4 x64 ka1: 192.168.2.10 ka2: 192.168.2.11 vip: 192.168.2.200 ka1-master服务器配置 ...

  6. html中的定位与层级设置

    #转载请先留言联系 定位 HTML中的position属性可以对元素进行定位,通过position的不同的值,可以配合方位属性,让元素显示页面中的任何一个位置. position有四个值: stati ...

  7. JVM CMS 常用参数配置(修订)

    搜集到的一些参数内容,比较有用,大部分转载自并发编程网ifeve.com. -XX:+UseConcMarkSweepGC该标志首先是激活CMS收集器.默认HotSpot JVM使用的是并行收集器. ...

  8. crontab自动备份MySQL数据库并删除5天前备份

    1.创建备份文件夹 //备份数据库文件夹 mkdir /data/backmysql //crontab日志 mkdir /data/logs   2.创建脚本文件 db_user="xxx ...

  9. Spark部署及应用

    在飞速发展的云计算大数据时代,Spark是继Hadoop之后,成为替代Hadoop的下一代云计算大数据核心技术,目前Spark已经构建了自己的整个大数据处理生态系统,如流处理.图技术.机器学习.NoS ...

  10. linux查看cpu内存信息

    # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...