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)
  • 相关阅读:
    ant design pro梳理
    JSON.stringify()
    数组小细节
    js this细节
    策略模式解决if-else过多
    使用useState的赋值函数异步更新问题
    Hook
    React Api
    Intent
    树的非递归遍历
  • 原文地址:https://www.cnblogs.com/wadmwz/p/8971928.html
Copyright © 2011-2022 走看看