Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.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
Sql server 如何在Spring Boot中将输入文本与数据库值进行比较?_Sql Server_Spring Boot_Spring Data Jpa_Chart.js_Thymeleaf - Fatal编程技术网

Sql server 如何在Spring Boot中将输入文本与数据库值进行比较?

Sql server 如何在Spring Boot中将输入文本与数据库值进行比较?,sql-server,spring-boot,spring-data-jpa,chart.js,thymeleaf,Sql Server,Spring Boot,Spring Data Jpa,Chart.js,Thymeleaf,我想做的是:在html中输入文本,例如:11:00:00。然后将该输入值与数据库中的列时间进行比较,并显示与11:00:00相关的数据。我想我必须将输入文本从Html传输到控制器,保存到一个变量中,然后在存储库文件中,我使用语法选择。。。从…起时间=XXX,但我不知道怎么做 SQL server中的我的表是product,有4列:id、TAG00我的温度数据、日期、时间 谢谢你的帮助 AppController.java html我使用Graph ChartJS显示数据库中的数据和时间 <

我想做的是:在html中输入文本,例如:11:00:00。然后将该输入值与数据库中的列时间进行比较,并显示与11:00:00相关的数据。我想我必须将输入文本从Html传输到控制器,保存到一个变量中,然后在存储库文件中,我使用语法选择。。。从…起时间=XXX,但我不知道怎么做

SQL server中的我的表是product,有4列:id、TAG00我的温度数据、日期、时间

谢谢你的帮助

AppController.java

html我使用Graph ChartJS显示数据库中的数据和时间

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:th="http://www.thymeleaf.org">
<div  style="position:relative;left:50px;top:5px;"  > <!-- Position: 
relative(tuong quan theo left,right,bottom,top), absolute,fixed -->
  <a href="/">Home</a>       
</div> 
<script 
src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"> 
</script>
<link rel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@0.5.0"> 
</script> <!-- thu vien dung de hien thi gia tri tren bieu do -->
<div class="container">
<canvas id="ChartBar"></canvas>
</div>
<div class="container">
<canvas id="myChart1" width ="350" height="350"></canvas>
</div>
<script th:inline="javascript">
let myChart1 = document.getElementById('myChart1').getContext('2d');
// Global Options
Chart.defaults.global.defaultFontFamily = 'Lato';
Chart.defaults.global.defaultFontSize = 18;
Chart.defaults.global.defaultFontColor = '#777';
let massPopChart = new Chart(myChart1, {
  type:'bar', // bar, horizontalBar, pie, line, doughnut, radar, polarArea
  data:{
    //labels: [1,3,5,7];
    labels:/*[[${listTime}]]*/,<!--my Time data-->
    datasets:[{
      label:'Temperature',      
      //data: [2,4,6,8];
      data:/*[[${listData}]]*/, <!--my Temperature data-->         
      backgroundColor:'rgba(255, 99, 132, 0.6)',              
      fill: false,
      borderWidth:1,
      borderColor:'rgba(255, 0, 0, 0.6)', //thay doi mau cho Line
      hoverBorderWidth:1,
      hoverBorderColor:'#111',
      pointRadius: 3
    }]
  },
  options: {      
      legend : {
          display: false,
      },
      responsive :  true ,
      maintainAspectRatio: false,         
      plugins: { //plugin dung de hien thi gia tri len bieu do
          datalabels: {
                display: function(context) {
                    return context.dataIndex % 1; 
                },
                backgroundColor: function(context) {
                    return context.dataset.backgroundColor;
                },
                backgroundColor: 'rgba(255, 255, 255,0)',
                borderRadius: 2,
                anchor : 'end',
                align : 'top',
                color: 'black',
                font: {
                    weight: 'bold'
                },
                formatter: Math.round
            }
        },
      scales: {//scales dung de cai dat option cho cot X,Y
          yAxes: [{
              ticks: {
                  beginAtZero: true,
                  stepSize: 0.1,
                  min: 24,
                  max: 25,
                  fontColor : 'blue'
              },
          }],
          xAxes: [{
              ticks: {
                  fontColor: 'blue'
              },
          }]
      }
  }
});    
试试看

ProductRepository.java

公共接口ProductRepository扩展了JpaRepository{ 公开名单findByTag00Is@Paramtag00floattag00; 公开名单findByTimeIs@Paramtimefloat时间2; } findByTimeIsfloat time2这与选择相同。。。从…起其中时间=时间2

AppController.java

公共类AppController{ @自动连线 私人产品服务; @自动连线 私人产品储存库prorepo; @请求映射/图表线 公共字符串viewLineModel模型,@RequestParamname=time,required=false浮点时间{ //随时间做任何事 //示例:propero.findbytime; }
那ChartLine.html呢?我需要一个文本框来输入时间,然后比较html中的时间和数据库中的时间。。。
public interface ProductRepository extends JpaRepository<Product, Long> {

@Query(value="SELECT tag00 FROM Product",nativeQuery =true)
public List<Object[]> findByTag00(@Param("tag00")float tag00);

@Query(value="SELECT time FROM Product",nativeQuery =true)
public List<Object[]> findByTime(@Param("time")String time);}
@Entity
public class Product {
public int id;
public float tag00;
public String date;
public String time;
protected Product() {
}
protected Product(int id, float tag00, String date, String time) {
    super();
    this.id = id;
    this.tag00 = tag00;
    this.date = date;
    this.time = time;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public float getTAG00() {
    return tag00;
}
public void setTAG00(float tag00) {
    this.tag00 = tag00;
}
public String getDate() {
    return date;
}
public void setDate(String date) {
    this.date = date;
}   
public String getTime() {
    return time;
}
public void setTime(String time) {
    this.time = time;
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:th="http://www.thymeleaf.org">
<div  style="position:relative;left:50px;top:5px;"  > <!-- Position: 
relative(tuong quan theo left,right,bottom,top), absolute,fixed -->
  <a href="/">Home</a>       
</div> 
<script 
src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"> 
</script>
<link rel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@0.5.0"> 
</script> <!-- thu vien dung de hien thi gia tri tren bieu do -->
<div class="container">
<canvas id="ChartBar"></canvas>
</div>
<div class="container">
<canvas id="myChart1" width ="350" height="350"></canvas>
</div>
<script th:inline="javascript">
let myChart1 = document.getElementById('myChart1').getContext('2d');
// Global Options
Chart.defaults.global.defaultFontFamily = 'Lato';
Chart.defaults.global.defaultFontSize = 18;
Chart.defaults.global.defaultFontColor = '#777';
let massPopChart = new Chart(myChart1, {
  type:'bar', // bar, horizontalBar, pie, line, doughnut, radar, polarArea
  data:{
    //labels: [1,3,5,7];
    labels:/*[[${listTime}]]*/,<!--my Time data-->
    datasets:[{
      label:'Temperature',      
      //data: [2,4,6,8];
      data:/*[[${listData}]]*/, <!--my Temperature data-->         
      backgroundColor:'rgba(255, 99, 132, 0.6)',              
      fill: false,
      borderWidth:1,
      borderColor:'rgba(255, 0, 0, 0.6)', //thay doi mau cho Line
      hoverBorderWidth:1,
      hoverBorderColor:'#111',
      pointRadius: 3
    }]
  },
  options: {      
      legend : {
          display: false,
      },
      responsive :  true ,
      maintainAspectRatio: false,         
      plugins: { //plugin dung de hien thi gia tri len bieu do
          datalabels: {
                display: function(context) {
                    return context.dataIndex % 1; 
                },
                backgroundColor: function(context) {
                    return context.dataset.backgroundColor;
                },
                backgroundColor: 'rgba(255, 255, 255,0)',
                borderRadius: 2,
                anchor : 'end',
                align : 'top',
                color: 'black',
                font: {
                    weight: 'bold'
                },
                formatter: Math.round
            }
        },
      scales: {//scales dung de cai dat option cho cot X,Y
          yAxes: [{
              ticks: {
                  beginAtZero: true,
                  stepSize: 0.1,
                  min: 24,
                  max: 25,
                  fontColor : 'blue'
              },
          }],
          xAxes: [{
              ticks: {
                  fontColor: 'blue'
              },
          }]
      }
  }
});