mybatis传递多个参数值(转)

Mybatis传递多个参数

ibatis3如何传递多个参数有两个方法:一种是使用Map,另一种是使用JavaBean。

  

<!-- 

  使用HashMap传递多个参数  

 parameterType 可以是别名或完全限定名 ,map->java.util.Map,这两个都是可以的 

 --> 

 <selectid="selectBlogByMap"parameterType="map"resultType="Blog"

     SELECT t.ID, t.title, t.content 

       FROM blog t 

      WHERE t.title = #{h_title} 

        AND t.content =#{h_content} 

 </select> 

 <!-- 使用JavaBean传递多个参数 --> 

 <selectid="selectBlogByBean"parameterType="Blog"resultType="Blog"

     SELECT t.ID, t.title, t.content 

       FROM blog t 

      WHERE t.title = #{title} 

        AND t.content =#{content} 

 </select>

/**

   * 通过Map传递多个参数

   */

  @Test

  public void testSelectByMap() { 

      SqlSession session = sqlSessionFactory.openSession(); 

      Map<String, Object> param=new HashMap<String, Object>(); 

      param.put("h_title", "oracle"); 

      param.put("h_content", "使用序列!"); 

      Blog blog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByMap",param); 

      session.close(); 

      System.out.println("blog title:"+blog.getTitle()); 

  

  /**

   * 通过JavaBean传递多个参数

   */

  @Test

  public void testSelectByBean() { 

      SqlSession session = sqlSessionFactory.openSession(); 

      Blog blog=new Blog(); 

      blog.setTitle("oracle"); 

      blog.setContent("使用序列!"); 

      Blog newBlog = (Blog)session.selectOne("cn.enjoylife.BlogMapper.selectBlogByBean",blog); 

      session.close(); 

      System.out.println("new Blog ID:"+newBlog.getId()); 

  }

时间: 2024-08-09 10:56:16

mybatis传递多个参数值(转)的相关文章

mybatis 传递参数的方法总结

有三种mybatis传递参数的方式: 第一种 mybatis传入参数是有序号的,可以直接用序号取得参数 User selectUser(String name,String area); 可以在xml配置文件中写 <select id="selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{0} and user_area=#{1} <

获取url网址传递的指定参数值

获取url网址传递的指定参数值:url传递参数是常识,这里无需多介绍,下面就介绍一下结合正则表达式如何获取url传递的参数值.代码如下: String.prototype.getQuery=function(name) { var reg=new RegExp('(^|\\?|&)'+name+'=([^&]*|$)'); var url=this.replace(/&/g,'&') var r=url.match(reg); return r===null?null:un

MyBatis传递参数

MyBatis传递参数 一.使用 map 接口传递参数 在 MyBatis 中允许 map 接口通过键值对传递多个参数,把接口方法定义为 : public List<Role> findRolesByMap(Map<String , Object> parameterMap); 此时,传递给映射器的是一个 map对象,使用它在 SQL 中设置对应的参数,如代码清单, 参数 roleName 和 note , 要求的是 map 的键 <select id=" find

mybatis传递参数到mapping.xml

第一种方案 ,通过序号传递 DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id="selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{0} and user_area=#{1} </select> 其中,#{0}

Mybatis传递多个参数

方法一: //DAO层的函数方法Public User selectUser(String name,String area); 对应的Mapper.xml <select id="selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{0} and user_area=#{1} </select> 其中,#{0}代表接收的是da

关于向Mybatis传递多个参数进行SQL查询的用法

当只向xxxMapper.xml文件中传递一个参数时,可以简单的用"_parameter"来接收xxxMapper.java传递进来的参数,并代入查询,比如说这样: (1)xxxMapper.java文件中这样定义: List<String> selectAllAirportCode(Boolean mapping); (2)这时在对应的xxxMapper.xml文件中可以使用"_parameter"来接收这个参数: <select id=&quo

Mybatis传递多个参数的解决办法 三种

第一种方案 DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id="selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{0} and user_area=#{1} </select> 其中,#{0}代表接收的是da

mybatis传递Map和List集合示例

1.List示例 java文件: dao: public List<ServicePort> selectByIps(List<String> ips); xml文件: <!-- 高级查询 --> <select id="selectByIps" resultType="ServicePort"> Select * from port_service_info where ip in <foreach item=

如何使用HTML传递和接收参数值

<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus?"> <meta name="Author" content=""> <meta name="