Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery DataTable,用于筛选SQL表的重复项_Javascript_Jquery_Mysql_Spring Boot - Fatal编程技术网

Javascript jQuery DataTable,用于筛选SQL表的重复项

Javascript jQuery DataTable,用于筛选SQL表的重复项,javascript,jquery,mysql,spring-boot,Javascript,Jquery,Mysql,Spring Boot,在我的应用程序的下一步中,我必须对特定类型的选项卡进行建模以显示 该应用程序是使用Spring Boot、JDBCTemplate、Bootstrap、Ajax和jQuery数据表开发的 当前任务是:在我们的数据库中,其中一个表是events,它存储关于我们网络pc事件的数据。在搜索所有事件(完成)之后,我们希望在我们的应用程序上有另一个页面:“今日事件”。此页面仅显示当天的事件 如何查询当前日期的数据库不是问题,我知道怎么做。 问题是:当我查询数据库时,我可能有一些行具有相同的主机但不同类型的

在我的应用程序的下一步中,我必须对特定类型的选项卡进行建模以显示

该应用程序是使用Spring Boot、JDBCTemplate、Bootstrap、Ajax和jQuery数据表开发的

当前任务是:在我们的数据库中,其中一个表是events,它存储关于我们网络pc事件的数据。在搜索所有事件(完成)之后,我们希望在我们的应用程序上有另一个页面:“今日事件”。此页面仅显示当天的事件

如何查询当前日期的数据库不是问题,我知道怎么做。 问题是:当我查询数据库时,我可能有一些行具有相同的主机但不同类型的事件(其中一个事件字段是“type”,它显示的事件类型就是所显示的类型)。这是我询问主机名、事件类型和主机操作系统时的结果示例:

正如tou所见,前两个主机有两种不同类型的事件:Achille有操作系统和应用程序、Aiace文件完整性和TCP服务

当我们使用jQuery DataTable在应用程序中显示数据时,我们不希望这样显示:结果表必须有以下标题:

我们想要的是:对于所有主机,只显示一次它们及其操作系统;然后,如果存在某种类型的事件,则必须出现一个元素(元素是另一个故事,现在假设一个简单的符号为“X”)。使用前面的结果表,输出可能是:

|主机|操作系统|操作系统|文件集成|服务|运行服务| TCPServices |应用程序|

|Achille | Linux | X | | | | X|

|Aiace | Linux | X | | X ||

Now, my DAO class has a method that perform the query to obtain all the events of the current days, that is:

public List<Events> getTodayEvents()
    {
        /**
         * This is the string that contain the query to obtain the data from join of
         * hosts and events with aggregator operations.
         */
        String SQL = "SELECT * FROM hosts JOIN events ON hosts.id = events.host_id WHERE DATE(events.date) = CURDATE()";

        /**
         * The list containing the results is obtained using the method query on jdcbtemplate, giving in in input to it the query string, the array of object 
         * containing the input variabile of the method and the rowmapper implemented.
         */
        List<Events> theEvents = jdbcTemplate.query(SQL, new HostAndEventsMapper());

        return theEvents;
    } 
|阿努比|赢| | | | X ||

Now, my DAO class has a method that perform the query to obtain all the events of the current days, that is:

public List<Events> getTodayEvents()
    {
        /**
         * This is the string that contain the query to obtain the data from join of
         * hosts and events with aggregator operations.
         */
        String SQL = "SELECT * FROM hosts JOIN events ON hosts.id = events.host_id WHERE DATE(events.date) = CURDATE()";

        /**
         * The list containing the results is obtained using the method query on jdcbtemplate, giving in in input to it the query string, the array of object 
         * containing the input variabile of the method and the rowmapper implemented.
         */
        List<Events> theEvents = jdbcTemplate.query(SQL, new HostAndEventsMapper());

        return theEvents;
    } 
但是,当然,使用这种结构,结果与我在开始时向您展示的结果表相同:

这不是我们想要的形式


所以,问题是:我必须修改什么才能得到我们想要的结果?刀?控制器?数据表?如何实现呢?

看来您需要一个组关联函数,这样类似的函数就可以工作了

select group_concat(type,','), name,os from <your table>  group by name,os;
从groupby name,os中选择group_concat(type,,),name,os;
您需要将sql更改为使用group CONCATION函数,以允许所有行显示在一行上


你可能会发现它非常有用,因为它看起来很有趣;现在,我必须只了解如何修改此查询的行映射器。非常感谢。如果你发布你的问题,我可以帮你。或者,如果这足够,请将其标记为答案
select group_concat(type,','), name,os from <your table>  group by name,os;