MyBaits传递多个参数
来源:互联网 发布:mac 加速器 编辑:程序博客网 时间:2024/05/01 20:34
1.传递一个参数的情况比较容易
比如在mapping.xml中有:
<select id="Find" resultType="ray.bean.User" parameterType="string">select * from user where USERNAME=#{username} </select>那么dao层就需要这么调用:(主要是名称和参数类型要正确)
public User Find(String username);2. 传递多个参数的情况:
(1)、使用map来传递多个参数:
mapping.xml中有:
<!-- 使用map传递多个参数 --> <select id="loginUser" resultType="ray.bean.User"> select * from user where loginName=#{loginName, jdbcType=VARCHAR} and password=#{password, jdbcType=VARCHAR} and isAdmin = 1; </select>那么dao中需要这么写:(弊端是在dao接口层不知道参数具体表示什么意思)
public User loginUser(Map<String, String> paramas);在service层需要这么调:
public User loginUser(String loginName, String uPwd) {Map<String, String> param = new HashMap<String, String>();param.put("loginName", loginName);param.put("password", uPwd);return userDao.loginUser(param);}(2)、通过顺序来调用
<!-- 使用map传递多个参数 --> <select id="loginUser" resultType="ray.bean.User"> select * from user where loginName=#{0} and password=#{1} and isAdmin = 1; </select>dao层需要这么写:
public User <span style="font-family: Arial, Helvetica, sans-serif;">loginUser </span><span style="font-family: Arial, Helvetica, sans-serif;">(String userName, String passWord);</span>
(3)、通过封装为bean来调(万能的,但是对于较少的参数个数比较麻烦)
<update id="Update" parameterType="ray.bean.User">update user set PASSWORD=#{password} where userId=#{userId};</update>dao层需要这么写:
public int Update(User user);(4)、使用注解@param表示参数,是对第一种方法的改进
mapping.xml中:
<!-- 使用@param传递多个参数 --> <select id="loginUser" resultType="ray.bean.User"> select * from user where loginName=#{loginName, jdbcType=VARCHAR} and password=#{password, jdbcType=VARCHAR} and isAdmin = 1; </select>在dao层这么写:
public User loginUser(@Param("userName")String userName, @Param("passWord")String passWord);service层也不需要封装map
0 0
- MyBaits传递多个参数
- MyBaits参数传递注意事项
- showModalDialog传递多个参数
- 多个参数的传递
- HyperLink传递多个参数
- setTimeout传递多个参数
- LinkButton 传递多个参数
- javascript传递多个参数
- ibatis 传递多个参数
- Extjs 多个参数传递
- ibatis 传递多个参数
- smartclient 传递多个参数
- Mybatis传递多个参数
- javascript传递多个参数
- LinkButton 传递多个参数
- Mybatis传递多个参数
- Mybatis传递多个参数
- ajax传递多个参数
- JAVA IO(三)
- 专题二:搜索总结报告
- BZOJ4524: [Cqoi2016]伪光滑数
- 通过NSURLSessionDownloadTask代理实现下载大文件
- 多线程编程之三个面试题
- MyBaits传递多个参数
- c++检测JAVA环境
- 约瑟夫环and同余方程组模板(exgcd求解同余方程组)
- echo写vbs下载者木马
- Python中的序列结构数据类型
- BZOJ 3998 TJOI 2015 弦论 后缀自动机
- Android Volley和Android-async-http两个网络框架比较
- 【DFS+多次剪枝】HDU1455Sticks【POJ少林神棍】
- 跟我学REDIS-REDIS(二)----常用数据类型之Lists