美文网首页
controller层接收时间

controller层接收时间

作者: 李霖神谷 | 来源:发表于2019-12-26 16:48 被阅读0次

前端发送过来的是string类型的时间戳,使用 @DateTimeFormat将string类型转换为指定类型的date类型。

/*  public ApiResult countBySiteId(Integer siteId,HttpSession session){*/
    public ApiResult countBySiteId(Integer siteId,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime,
                                   HttpSession session) throws ParseException {

        // 定义一个map来封装参数。然后直接传递给map做参数
        Map<String ,Object> hashMap = new HashMap();
        hashMap.put("siteId",siteId);
        hashMap.put("startTime",startTime);
        hashMap.put("endTime",endTime);

mapper中mysql比较的时候:

<if test="startTime != null and startTime !=''">
                <![CDATA[   and publish_time >= DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%T:%s')   ]]>
            </if>
            <if test="endTime != null and endTime!=''">
                <![CDATA[   and publish_time <=  DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%T:%s')   ]]>
            </if>

当前端传过来的是string类型的时间戳,这时的sql:

<if test="null!=startTime and ''!=startTime">
                <![CDATA[   and  unix_timestamp(apply_time)> unix_timestamp(#{startTime,jdbcType=VARCHAR})]]>
            </if>
            <if test="null!=endTime and ''!=endTime">
                <![CDATA[  and  unix_timestamp(apply_time)<unix_timestamp(#{endTime,jdbcType=VARCHAR})]]>
            </if>

相关文章

网友评论

      本文标题:controller层接收时间

      本文链接:https://www.haomeiwen.com/subject/crlloctx.html