我想创建一个表单,输入作为员工ID,来自日期,并根据EmployeeID和日期过滤器查询我的sql表。根据员工ID的输入和日期,我的sql表应该返回并显示数据。我正在使用node.js作为服务器端。我想知道如何将数据从html表单传递给控制器,从控制器传递到节点以查询sql表并获得所需的输出。这是我的attendance.html文件
<h2>Please select a file in .xlsx format to upload</h2>
<form action="ProcessAttendanceAPI" method="post" enctype="multipart/form-data">
<input name="attendanceFile" type="file" class="form-control">
<button type="submit" class="btn btn-block btn-primary">Upload File</button>
</form>
<br>
<h4>{{title}}</h4>
<button type="submit" class="btn btn-block btn-primary" ng-click="showAlert()">
Generate Report</button>
<div class="container" ng-show="myvalue">
<h3>SEARCH BY</h3>
<select class="form-control" ng-model='SearchTerm'>
<option value='$'>PLEASE CHOOSE ONE OPTION</option>
<option value='employeeId'>EMPLOYEE ID</option>
<option value='punch_date'>DATE</option>
</select>
<br>
<div class="container">
<h5>Search Key:
<h5>
<br>
<input type="text" class="form-control" ng-model="searchKeyword[SearchTerm]">
</div>
<br>
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>Employee ID</td>
<td>DATE</td>
<td>IN TIME</td>
<td>OUT TIME</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="blog in blogs | filter:searchKeyword">
<td>{{blog.employeeId}}</td>
<td>{{blog.punch_date}}</td>
<td>a {{blog.min}}</td>
<td>{{blog.max}}</td>
</tr>
</tbody>
</table>
</div>
我的SQL表结构是
CREATE TABLE `emp_attendance` (
`attendance_id` int(11) NOT NULL AUTO_INCREMENT,
`punch_date` date not null,
`punch_in_timestamp` datetime NOT NULL,
`punch_out_timestamp` datetime,
`employeeId` varchar(64) DEFAULT NULL,
`upload_id` int(11) DEFAULT NULL,
PRIMARY KEY (`attendance_id`),
-- KEY `FK_emp_attendance_1` (`employeeId`),
KEY `FK_emp_attendance_2` (`upload_id`),
-- CONSTRAINT `FK_emp_attendance_1` FOREIGN KEY (`employeeId`) REFERENCES `employee` (`employeeId`),
CONSTRAINT `FK_emp_attendance_2` FOREIGN KEY (`upload_id`) REFERENCES `emp_attendance_uploads` (`upload_id`)
) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=latin1;
截至目前,我从node.js中的以下代码获取存储在sql表中的整个数据
exports.Attendancedata = function(req, res) {
dbconfig.getConnection(function(err, con) {
con.query('SELECT employeeId as employeeId, punch_date as punch_date,min(punch_in_timestamp) as min ,max(punch_out_timestamp) as max FROM emp_attendance group by employeeId, punch_date',
function(err, results) {
if (err) {
handleError(err, res);
} else {
res.send(results);
}
});
con.release();
});
}