若依前后端分离-时间日期年月日时分秒格式查询
这个是简单的问题,整理一下。
·
这个是简单的问题,整理一下。
vue添加表单
<el-form-item label="开始时间" prop="startTime">
<el-date-picker clearable
v-model="form.startTime"
type="datetime"
value-format="yyyy-MM-dd HH:mm:ss"
placeholder="请选择开始时间">
</el-date-picker>
</el-form-item>
vue回显后端数据
格式如下:
{y}年{m}月{d}日 {h}:{i}:{s} 周{a}
<el-table-column label="开始时间" align="center" prop="startTime" width="180">
<template slot-scope="scope">
<p>{{ parseTime(scope.row.startTime, '{h}:{i}:{s}') }}</p>
<span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
后端实体类
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
若依项目已配置默认时区,timezone = “GMT+8” 东八区可不设置
/**
* 程序注解配置
*
* @author ruoyi
*/
@Configuration
// 表示通过aop框架暴露该代理对象,AopContext能够访问
@EnableAspectJAutoProxy(exposeProxy = true)
// 指定要扫描的Mapper类的包的路径
@MapperScan("com.ruoyi.**.mapper")
public class ApplicationConfig {
/**
* 时区配置
*/
@Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
}
}
数据库查询
格式如下
%y-%m-%d %h:%i:%s
<if test="startTime != null ">and date_format(start_time,'%y%m%d%h%i') >=
date_format(#{startTime},'%y%m%d%h%i')
</if>
<if test="endTime != null ">and date_format(end_time,'%y%m%d%h%i') <=
date_format(#{endTime},'%y%m%d%h%i')
</if>
更多推荐
已为社区贡献22条内容
所有评论(0)