ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**1. DAO层接口** ```java public interface StudentDao { /** * 注解 @Param 可用可不用 */ Student queryById(@Param("id") Integer id); } ``` **2. XML映射文件** ```xml <select id="queryById" parameterType="int" resultType="Student"> select id, `name`, born, gender from student where id = #{id} </select> ``` **3. 测试** ```java @Test public void queryById() { try { sqlSession = MybatisUtils.createConnetion(); Student student = sqlSession.getMapper(StudentDao.class).queryById(1); //Student(id=1, name=张无忌, born=Mon Apr 04 21:22:30 CST 2022, gender=男) System.out.println(student); } catch (Exception e) { e.printStackTrace(); } finally { MybatisUtils.close(sqlSession); } } ```