簡體   English   中英

MyBatis:在MySQL數據庫上查詢DATE類型的java.util.Date

[英]MyBatis : query java.util.Date with DATE type on MYSQL database

在我的Mapping 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;

 <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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM