1. 程式人生 > >MyBatis查詢單表返回List

MyBatis查詢單表返回List

本來以為把List<Bean> 封裝在一個javabean裡,然後在對映檔案裡配置一個<resultMap>然後利用<collection>進行封裝就好了,確實可以,但是也比較麻煩,查了一下百度發現也沒什麼例子可以直接返回List

後來才知道只需要配置一個resultMap就好了

<resultMap type="Model.stu" id="studentList">
				<result property="id" column="id"/>
				<result property="student_name" column="student_name"/>
				<result property="student_age" column="student_age"/>
		</resultMap>
	
		<select id="selectSomeStudent" resultMap="studentList">
			select * from student limit #{f},#{r}
		</select>


List<stu> selectSomeStudent(@Param("f")int firstResult,@Param("r")int maxResult);