myibatis传多个参数

方法一:直接给每个参数指定参数名

Mapper:

public List<TaskDic> listNewTask(@Param("userId")String userId,@Param("taskType") Integer type);

xml: 不要加 parameterType 因为这里有String 和 Integer两个类型,这里指定不了

<select id="listNewTask"  resultMap="TaskDicResultMap">

select

tk.id,tk.task_name,tk.task_type,tk.task_exp,utk.task_status

from

b_uc_task tk left join b_uc_user_task utk

on tk.id = utk.task_id

and utk.user_id = #{userId}

where

tk.task_type = #{taskType}

</select>

test:

@Test

public void listNewTask(){

System.out.println(userTaskMapper.listNewTask("22341",2).size());

}

方法二:将多个参数丢到一个Map中,传递Map

Mapper:

public List<TaskDic> listNewTask(Map<String, Object> map);

xml:parameterType="map"

<select id="listNewTask" parameterType="map"
resultMap="TaskDicResultMap">

select

tk.id,tk.task_name,tk.task_type,tk.task_exp,utk.task_status

from

b_uc_task tk left join b_uc_user_task utk

on tk.id = utk.task_id

and utk.user_id = #{userId}

where

tk.task_type = #{taskType}

</select>

test:

public void listNewTask(){

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

map.put("userId", "22341");

map.put("taskType", 2);

System.out.println(userTaskMapper.listNewTask(map).size());

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-02 02:33:28

myibatis传多个参数的相关文章

MyBatis学习总结_19_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} </sele

js上传文件带参数,并且,返回给前台文件路径,解析上传的xml文件,存储到数据库中

ajaxfileupload.js jQuery.extend({ createUploadIframe: function(id, uri) { //create frame var frameId = 'jUploadFrame' + id; if(window.ActiveXObject) { var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '&qu

button点击传多个参数

// --------------------button点击传多个参数------------------------ UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(100, 100, 200, 50); btn.backgroundColor = [UIColor blueColor]; [btn setTitle:@"click me" forState:U

Mybatis传多个参数(三种解决方案)

据我目前接触到的传多个参数的方案有三种. 第一种方案 DAO层的函数方法 ? 1 PublicUserselectUser(Stringname,String area); 对应的Mapper.xml ? 1 2 3 <selectid="selectUser"resultMap="BaseResultMap"> select * fromuser_user_t  whereuser_name = #{0}anduser_area=#{1} </s

mybatis 嵌套查询子查询column传多个参数描述

mybatis 嵌套查询子查询column传多个参数如下: 1.图解 2.代码示例 备注:注意,相同颜色的单词都是有关联的. <resultMap id="blogResult" type="Blog"> <association property="author" column="{id=author_id,likename=author_name}" javaType="Author"

httpclient 4.3 psot方法上传文件与参数 中文乱码解决

废话不多说,直接上有码的! 1 package httpclient; 2 3 import java.io.File; 4 import java.nio.charset.Charset; 5 6 import org.apache.http.Consts; 7 import org.apache.http.Header; 8 import org.apache.http.HttpEntity; 9 import org.apache.http.client.methods.Closeable

C# params object[] args 可以传多个参数,可以不限制类型(转)

C# params object[] args 可以传多个参数,可以不限制类型 using System;using System.Collections.Generic;using System.Text; namespace ConsoleApplication2{    class Program    {        static void Main(string[] args)        {            print("Information", new Fie

【转】Mybatis传多个参数(三种解决方案)

转自: http://www.2cto.com/database/201409/338155.html 据我目前接触到的传多个参数的方案有三种. 第一种方案: DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id="selectUser" resultMap="BaseResultMap"> select  *  from user_user

mapper 传多个参数

Mybatis的Mapper接口的参数,一般是一个对象,但如果不是对象,并且有多个参数的时候呢?我们第一个的想法是把参数封装成一个java.util.Map类型,然后在方法的注释上面写上map的key是什么,但是,这样的做法明显不够直观,不能够一眼看出这个方法的参数是什么,并且,影响到了java方法的多态性(方法名相同,参数数量或类型不同).下面的方法一和方法二能够解决问题! 一 DAO层的函数方法 1 Public User selectUser(String name,String area