欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mybatis 如何返回list<String>類型數(shù)據(jù)

 更新時間:2021年10月09日 14:46:21   作者:長腿CX媛  
這篇文章主要介紹了mybatis 如何返回list<String>類型數(shù)據(jù)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

mybatis返回list<String>類型數(shù)據(jù)

studends表里一條teacher_id 數(shù)據(jù)對應多條 student_id數(shù)據(jù),所以通過teacher_id 查詢出來的student_id 是一個List。

mybatis代碼如下:

//返回類型是String類型的student_id
<resultMap id="studentIdResult" type="java.lang.String" >
    <result column="student_id" property="studentId" jdbcType="VARCHAR" />
</resultMap>
//入?yún)㈩愋停╬arameterType)是String類型 teacherId
<select id="getStudentsByTeacherId" resultMap="studentIdResult" parameterType="java.lang.String" >
    select student_id
    from student
    where teacher_id = #{id,jdbcType=VARCHAR}
</select>

mybatis返回list<String>時resultType寫String

查詢出的結果可能有好多條記錄,返回類型即是list。但resultType還是寫成resultType="user"(user為集合list中的實體類),而不是寫成resultType="java.util.List"

mybatis返回list<String>時resultType寫java.lang.String而不是java.util.List

如果寫成java.util.List時會報錯

error querying database.the error occurred while handling results.

resultType也不能寫成java.util.HashMap否則會返回[{"abcde"},{"fghilmn"},{"opqrst"}]

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論