🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
**1. DAO层接口** ```java public interface StudentDao { /** * 注解 @Param 可用可不用 */ Student queryById(@Param("id") Integer id); } ``` **2. XML映射文件** ```xml <!-- parameterType: queryById方法参数类型,不区分大小写,该属性可选,mybatis 会自动识别的。 resultType: queryById方法的返回类型,如果在mybatis-config.xml设置了别名,也可以写成student #{id}: 这就是传递过来的参数,使用#{参数名}来接收。当使用注解@Param("id")时,id就是@Param中的id; 不使用注解@Param时,id就是方法queryById中的参数名id --> <select id="queryById" parameterType="int" resultType="Student"> select id, `name`, born, gender from student where id = #{id} </select> ``` **** 参考文档:https://mybatis.org/mybatis-3/zh/sqlmap-xml.html#Parameters