这个是简单的问题,整理一下。

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') &gt;=
                date_format(#{startTime},'%y%m%d%h%i')
            </if>
            <if test="endTime != null ">and date_format(end_time,'%y%m%d%h%i') &lt;=
                date_format(#{endTime},'%y%m%d%h%i')
            </if>
Logo

快速构建 Web 应用程序

更多推荐