2017-08-25 70 views
0

我有麻烦我的春节,控制器和一个html:有没有做绑定点击这里提交按钮。春天控制器不作形式结合

这是以下形式:

<form class="form-horizontal" role = "form" id="searchtodayeventsform"> 


        <div class = "form-group"> 
         <label for = "note" class = "col-sm-3 control-label">Date</label> 
          <div class = "col-sm-8"> 
           <input type = "date" class = "form-control" id = "todaydatevalue" placeholder = "MM/DD/AAAA"> 
          </div> 
        </div> 


        <div class = "form-group"> 
         <label for = "type" class = "col-sm-3 control-label">OS</label> 
          <div class = "col-sm-8"> 
           <select class = "form-control" id = "osnamevalue" name="todayostypeoptions"> 
           <option value="Linux">Linux</option> 
           <option value="Windows">Windows</option> 
           </select> 
          </div> 
        </div> 


        <div class = "form-group"> 
         <div class = "col-sm-offset-2 col-sm-10" id="submit"> 
          <button type = "submit" class = "btn btn-default">Cerca</button> 
         </div> 
        </div> 

此,用于控制日期参数和发送所有到控制器内的功能:

DTevents = $('#eventsosdatedata').DataTable( 
      { 
       "serverSide": true, 
       "ajax":{ 
          url: "../geteventsosdate.json", 
          type: "post", 
          "data": function (d) 
          { 
           var param = {osnamevalue : $('#osnamevalue').val()}; 

           if(moment($('#todaydatevalue').val()).isValid()) 
           param = $.extend(param, {datevalue : moment($('#todaydatevalue').val()).toDate().getTime()}); 
           console.log(param); 
           return $.extend(d, param); 
          } 

         }, 

这是控制器:

/** 
    * This method is used when a list of events of speficic day and os are requested 
    * 
    * @param model the model data 
    * @param request the http request 
    * @param os the os choosed 
    * @param date the date desired 
    * @return the updated model 
    * @throws IOException 
    */ 
    @PostMapping(value="/geteventsosdate.json") 
    @ResponseBody 
    public ModelAndView showEventsOsDate(ModelAndView model, HttpServletRequest request, 
      @RequestParam(name="osnamevalue", required=false) String os, 
      @RequestParam(name="todaydatevalue", required=false) Long date) throws IOException 
    { 
     Timestamp date_value; 
     Date effective_date = null; 

     if(date != null) 
     { 
      date_value = new Timestamp(date); 
      effective_date = new Date(date_value.getTime()); 
     } 

     //First, we must populate the list of Events 
     List<Events> listEvents = networks.getEventsWithDateAndOs(os, effective_date); 

     //Second, we put this list in the model and set properties for jquery datatables 
       model.addObject("recordsTotal", listEvents.size()); 
       model.addObject("recordsFiltered", listEvents.size()); 
       model.addObject("data", listEvents); 

     //Finally, we return the model 
     return model; 
    } 

在控制器内执行的查询在此DAO类方法中完成:

使用
/** 
    * Return the events with same format of the current day table, 
    * where users can choose day and os. 
    * 
    * @return a list with join query results 
    */ 
    public List<Events> getEventsWithDateAndOs(String os, Date date) 
    { 
     /** 
     * This is the string that contain the query to obtain the data from join of 
     * hosts and events with aggregator operations. 
     */ 
     String SQL = "SELECT hosts.name, hosts.os," 
       + " MAX(case when events.type = 'Applications' then events.status end) as Applications," 
       + " MAX(case when events.type = 'OS' then events.status end) as OS_Type," 
       + " MAX(case when events.type = 'Running Services' then events.status end) as Running_Services," 
       + " MAX(case when events.type = 'TCP Services' then events.status end) as TCP_Services," 
       + " MAX(case when events.type = 'File Integrity' then events.status end) as File_Integrity," 
       + " MAX(case when events.type = 'Services' then events.status end) as Services" 
       + " FROM hosts JOIN events ON hosts.id = events.host_id" 
       + " WHERE events.date = ? AND (? is null or hosts.os = ?)" 
       + " GROUP BY hosts.name"; 

     /** 
     * 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 Object[]{os, os, date}, new EventTypeCountMapper()); 

     return theEvents; 
    } 

此的RowMapper:

import java.sql.ResultSet; 
import java.sql.SQLException; 

import org.consorziotriveneto.networks.entity.Events; 
import org.springframework.jdbc.core.RowMapper; 

public class EventTypeCountMapper implements RowMapper<Events> 
{ 
     //This method must be implemented when we use a row mapper 
     public Events mapRow(ResultSet rs, int rowNum) throws SQLException 
     { 
      Events events = new Events(); 


      //mapping of hosts attributes 
      events.setName(rs.getString("hosts.name")); 
      events.setOs(rs.getString("hosts.os")); 
      //mapping od count query 
      events.setApplications(rs.getString("Applications")); 
      events.setOs_type(rs.getString("OS_Type")); 
      events.setServices(rs.getString("Services")); 
      events.setRunning_services(rs.getString("Running_Services")); 
      events.setTcp_services(rs.getString("TCP_Services")); 
      events.setFile_integrity(rs.getString("File_Integrity")); 

      return events; 

     } 
} 

执行的应用程序,在控制台我:

Object { osnamevalue: undefined, datevalue: 1503646503530 } 

随着操作系统名称中选定一个没有设置好的和当天的时间戳,而不是。

这不是第一种形式在我的应用结合;我遵循与他人相同的模式,没有问题。我的印象是,我忘了一些东西,某些特定的步骤,或者我做了一些错误的设置,但我不明白是什么。

+0

您的数据功能,但根据https://api.jquery.com/jquery.post/字符串或普通物体的预期。尝试简化它以发送'{osnamevalue:“test”,datevalue:111}'并查看控制器是否正确地获取结果。 JJust要了解它是服务器还是客户端问题 – StanislavL

回答

0

因为没有指定name参数,它不会使绑定。

请尝试这样的:在阿贾克斯发送

<input type = "date" class = "form-control" id = "todaydatevalue" name"todaydatevalue" placeholder = "MM/DD/AAAA">