mybatis 进行日期信息比较

我的项目中 数据库mysql 里面存放日期类型是varchar

 如果前台进行查询,传递的日期类型也是 yyyy-mm-dd 类型 2022-01-01 的格式。

那么此时在mybatis xml 中 可以直接进行字符串日期大小比较

   SELECT
        bookkeeping.*,
        dictProduct.dict_name AS productDictName,
        dictConfirmed.dict_name AS confirmedDictName
        FROM
        (
        SELECT
        id,
        `confirmed_month` as confirmedMonth,
        `confirmed_date` as confirmedDate,
        `contract_code` as contractCode,
        `company_name`,
        `accountId`,
        `project_id`,
        `project_name`,
        `product_id`,
        `product_num`,
        `product_name`,
        `usage_start_at` as usageStartAt,
        `income_product_id`,
        `income_prodcut_name`,
        `goods_name`,
        `bookkeeping_receivables`,
        `amount_no_tax`,
        `tax_amount`,
        `maint_amount_to_amortized`,
        `tax_rate`,
        `maint_amount_to_amortized_no_tax`,
        `tax_amount2`,
        `actual_amount_received`,
        `tax_rate2`,
        `actual_amount_received_no_tax`,
        `tax_amount3`,
        `confirmed_receipt_type`,
        `send_info`,
        `adjustment_comment`,
        `product_attribute`,
        `insert_time`,
        `sync_history_id`
        FROM
        financial_revenue_bookkeeping
        ) bookkeeping
        LEFT JOIN common_dict dictProduct ON dictProduct.dict_value = bookkeeping.product_attribute
        AND dictProduct.dict_type = 'productAttributeType'
        LEFT JOIN common_dict dictConfirmed ON dictConfirmed.dict_value = bookkeeping.confirmed_receipt_type
        AND dictConfirmed.dict_type = 'confirmed_receipt_type'
        where
             confirmedDate  >= '2022-01' and  
             confirmedMonth <= '2022-06'
           
 
                and confirmed_month = ]]> #{confirmStartMonth}
            
            
                and confirmed_month  #{confirmEndMonth}
            

也可以参考网址字符串类型的日期时间在mybatis中比较大小,不需要转换格式 - YangBinChina - 博客园

你可能感兴趣的:(mybatis,mysql,数据库)