1.vue界面
<el-form-item label="Time:" size="small" style="float:right; ">
<el-date-picker
v-model="query.param.dateParam"
type="daterange"
range-separator="to"
start-placeholder="start"
end-placeholder="end"
value-format="yyyy-MM-dd"
style="width:350px">
</el-date-picker>
</el-form-item>
daterange 类型,后台接受的startTime endTime定义成String类型
js:
if(this.query.param.dateParam!=null && this.query.param.dateParam.length>0
){
this.query.param.startTime = this.query.param.dateParam[0]
this.query.param.endTime = this.query.param.dateParam[1]
}
或者
var faultTime = this.query.param.dateParam ? this.query.param.dateParam : '';
this.query.param.startTime = this.getDatePickerFirstTimeStamp(faultTime);
this.query.param.endTime = this.getDatePickerSecondTimeStamp(faultTime);
//封装类
getDatePickerFirstTimeStamp(timeStampArray) {
if(timeStampArray == "") {
return "";
}
return timeStampArray[0];
},
getDatePickerSecondTimeStamp(timeStampArray) {
if(timeStampArray == "") {
return "";
}
return timeStampArray[1];
}
2.java 实体类
private String startTime;
private String endTime;
3.mybatis
<if test="startTime != null and endTime!=null">
AND DATE_FORMAT(create_time,'%Y-%m-%d') between
#{startTime} and #{endTime}
</if>
数据库的createTime是DateTime类型
网友评论