Instructions for use: the type of collectStartDate and setStartDate is Date, and the corresponding creation time is varchar type in mysql
1. Download and import datetimepicker style and js
<link th:href="@{/ajax/libs/datapicker/bootstrap-datetimepicker.min.css}" rel="stylesheet"/>
<script th:src="@{/ajax/libs/datapicker/bootstrap-datetimepicker.min.js}"></script>
2. Page code
<li>
<label class="font-noraml">采集时间:</label>
<div class="input-group date">
<input type="text" id="collectStartDate" placeholder="yyyy-MM-dd" name="collectStartDate"/>
<span>到</span>
<input type="text" id="collectEndDate" placeholder="yyyy-MM-dd" name="collectEndDate"/>
</div>
</li>
Three, js use
$("#collectStartDate").datetimepicker({
format: 'yyyy-mm-dd',
minView: "month",
todayBtn: true,
autoclose: true,
endDate : new Date(),
}).on('changeDate', function(event) {
event.preventDefault();
event.stopPropagation();
var startTime = event.date;
$('#collectEndDate').datetimepicker('setStartDate', startTime);
});
$("#collectEndDate").datetimepicker({
format: 'yyyy-mm-dd',
minView: "month",
todayBtn: true,
autoclose: true,
endDate : new Date(),
}).on('changeDate', function(event) {
event.preventDefault();
event.stopPropagation();
var endTime = event.date;
$("#collectStartDate").datetimepicker('setEndDate', endTime);
});
4. Fields corresponding to entities
private Date collectStartDate;
private Date collectEndDate;
5. Query sql in mybatis
<if test="collectStartDate!=null">
and STR_TO_DATE(a7, '%Y-%m-%d') >= STR_TO_DATE(#{
collectStartDate},'%Y-%m-%d')
</if>
<if test="collectEndDate!=null">
and STR_TO_DATE(a7, '%Y-%m-%d') <= STR_TO_DATE(#{
collectEndDate},'%Y-%m-%d')
</if>
Description: a7 is a field in the database