zoukankan      html  css  js  c++  java
  • Mybatis传参方式

    • 传递多个参数的四种方式:
    • 顺序传参:public User selectUser(String name,int deptId); <select id="selectUser" resultType="user">select * from user where user_name=#{0} and dept_id = #{1}</select> #{}里面的数字代表你穿如参数的顺序.不建议使用.sql层表达不直观
    • @Param 注解传参:public User selectUser(@Param("userName")String name,@Param("deptId")int deptId); <select id="selectUser" resultType="user">select * from user where user_name=#{userName} and dept_id = #{deptId}</select> #{}里面的名称对应的是注解@Param 括号中修饰的名称,这种情况在参数不多的情况下比较直观,推荐之用
    • Map传参法:public User selectUser(Map<String,Object> params); <select id="selectUser" resultType="user" parameterType="map">select * from user where user_name=#{userName} and dept_id = #{deptId}</select> #{}里面的名称对应的是Map里面的key名称,这种方法适合多个参数,且参数易变能灵活传递的情况
    • Java Bean传参数::public User selectUser(User user); <select id="selectUser" resultType="user" parameterType="user">select * from user where user_name=#{userName} and dept_id = #{deptId}</select> #{}里面的名称对应的是 User类里面的成员属性。 这种方法很直观,但需要建一个实体类,扩展不容易,需要加属性,看情况使用
    • 转载(Hollis)
  • 相关阅读:
    link和@import的区别
    行内元素、块状元素和行内块元素
    content-box与border-box区别
    实现浏览器内多个标签页之间的通信
    cookie、 sessionStorage 、localStorage之间的区别和使用
    让浏览器识别HTML5规范中的新标签
    HTML5新增及移除的元素
    摇一摇
    WebViewJavascriptBridge
    使用TFHpple解析html
  • 原文地址:https://www.cnblogs.com/wadmwz/p/8971928.html
Copyright © 2011-2022 走看看