【不靠谱程序员】mybatis如何查询某一天的数据

249 阅读1分钟

我们就看mybatis的实现代码。

public interface PayPabReceiptDownloadMapper extends BaseMapper<PayPabReceiptDownload> {

    /**
     * 根据日期查询下载记录
     * @param createDate
     * @return
     */
    List<PayPabReceiptDownload> queryByCreateDate(String createDate);

}

再看xml文件对应里的sql:

<select id="queryByCreateDate" resultType="com.emax.channel.provider.modules.receipt.entity.PayPabReceiptDownload">
    select * from pay_pab_receipt_download where file_status = 2 
    and DATE_FORMAT(create_date,'%Y-%m-%d') = #{createDate}
</select>

不靠谱!

不靠谱说明:

  1. 方法queryByCreateDate的参数createDate,如果不看到里面的sql语句,你能知道应该传什么值? 如何靠谱?你猜!
  2. 再说sql,因为在字段上用了函数,导致sql执行变慢,即使create_date字段有索引,这样加了函数的sql也无法命中索引。