【问题标题】:MyBatis : query java.util.Date with DATE type on MYSQL databaseMyBatis : 在 MYSQL 数据库上使用 DATE 类型查询 java.util.Date
【发布时间】:2012-08-09 09:27:13
【问题描述】:

在我的映射 XML 中我有:

<select id="getPatientsByBirthday"  parameterType="date" resultType="com.axiohelix.nozoki.entity.Patient">
            SELECT id AS id,
               pharumo_id AS pharumoId,
               code AS code,
               family_name AS familyName,
               first_name AS firstName,
               family_name_kana AS familyNameKana,
               first_name_kana AS firstNameKana,
               gender AS gender,               
               address AS address,
               tel AS tel
        FROM tbl_patient
        WHERE birthday = #{id}
    </select>

其中生日是 MYSQL 数据库中的 DATE 类型。

我的 Mapper 界面是这样的:

public interface PatientMapper {

    void insertPatient(Patient patient);
    Patient getPatientById(Integer id);
    Integer getPatientCount();
    List<Patient> getPatientsByBirthday(Date  bday);
}

我尝试查询具有特定生日的患者:

Calendar cal1 = new GregorianCalendar(1980, 8, 15);
Date bday=cal1.getTime();

List<Patient> plist=mapper.getPatientsByBirthday(bday);

即使有给定日期的记录,这也会返回空列表。

任何提示?

【问题讨论】:

  • 在 XML 文件中分享您的 Mapper 接口实现以及结果映射。

标签: java mysql date ibatis mybatis


【解决方案1】:

像这样改变你的映射 xml;

 <select id="getPatientsByBirthday"  parameterType="java.util.Date" resultType="com.axiohelix.nozoki.entity.Patient">
        SELECT id AS id,
           pharumo_id AS pharumoId,
           code AS code,
           family_name AS familyName,
           first_name AS firstName,
           family_name_kana AS familyNameKana,
           first_name_kana AS firstNameKana,
           gender AS gender,               
           address AS address,
           tel AS tel
        FROM tbl_patient
        WHERE birthday = #{date}
</select>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-02
    • 2018-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    相关资源
    最近更新 更多