美文网首页
Mybatis的小知识

Mybatis的小知识

作者: 文萃北 | 来源:发表于2019-01-17 16:15 被阅读0次

实现多参数查询

单参数查询过于简单就不列了,下面只列出多参数查询的几种方式:

  • 使用Map传递参数 可以使用Mybatis 提供的Map接口作为参数来实现
  <insert id="add" parameterType="map"  >
        insert into t_student values(null,#{name},#{age})
  </insert>
  • 使用注解的方式传递参数 @Param。如果参数过多,调用函数就比较麻烦了。
  • 使用JavaBean传递参数
  <insert id="add" parameterType="Student"  >
        insert into t_student values(null,#{name},#{age})
  </insert>

主键回填

方法:使用useGenerateKeys属性设置为true,并且设置keyProperty。

相关文章

网友评论

      本文标题:Mybatis的小知识

      本文链接:https://www.haomeiwen.com/subject/favidqtx.html