执行如下命令:

mvn -Dmybatis.generator.overwrite=true mybatis-generator:generate

可以使用mybatis generator

mybatis 使用多个参数

自定义方法需要根据多个查询条件去查询:

SELECT * FROM `db_demo`.`hot_topic` WHERE lang='english' AND category='' AND  topic_type='video' ORDER BY score DESC;

推荐使用注解的方式:

需要自定义方法:

mapper文件中

  //  使用注解
JSONArray selectByLangAndCategoryAndTopicType(@Param("lang") String lang, @Param("category") String category, @Param("topicType") String topicType);

mapper.xml文件中:

<select id="selectByLangAndCategoryAndTopicType" resultMap="ResultMapWithBLOBs" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Thu Oct 12 14:51:34 CST 2017.
-->
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from hot_topic
where lang= #{lang,jdbcType=VARCHAR} AND category = #{category,jdbcType=VARCHAR} AND topic_type=#{topicType,jdbcType=VARCHAR}
</select>

其他方法

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}代表接收的是dao层中的第一个参数,#{1}代表dao层中第二参数,更多参数一致往后加即可。


其他方法

此方法采用Map传多参数.

Dao层的函数方法

Public User selectUser(Map paramMap);

对应的Mapper.xml

<select id=" selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>

Service层调用

Private User xxxSelectUser(){
Map paramMap=new hashMap();
paramMap.put(“userName”,”对应具体的参数值”);
paramMap.put(“userArea”,”对应具体的参数值”);
User user=xxx. selectUser(paramMap);}

此方法不够直观,见到接口方法不能直接的知道要传的参数是什么。

mybatis 使用tips - 使用多个参数的更多相关文章

  1. MyBatis传入集合 list 数组 map参数的写法

    foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合.foreach元素的属性主要有item,index,collection,open,separator,close.ite ...

  2. Mybatis 实用篇(三)参数处理

    Mybatis 实用篇(三)参数处理 sql 语句中的参数 parameterType 可以省略不写. 一.参数封装 1.1 单个参数处理 public interface UserMapper { ...

  3. mybatis按datetime条件查询,参数为时间戳时

    mybatis按datetime条件查询,参数为时间戳时,如果数据库为2018-1-1 20:22:10, 你的时间戳也为2018-1-1 20:22:10,但却没找到数据.可能是时差导致的.百度修正 ...

  4. MyBatis映射文件中用#和$传递参数的特点

    在MyBatis映射文件中用#和$传递参数的特点, #是以占位符的形式来传递对应变量的参数值的,框架会对传入的参数做预编译的动作, 用$时会将传入的变量的参数值原样的传递过去,并且用$传递传递参数的时 ...

  5. MyBatis中抽象方法中多个参数的问题

    在使用MyBatis时,接口中的抽象方法只允许有1个参数,如果有多个参数,例如:      Integer updatePassword(             Integer id, String ...

  6. Mybatis接口中传递多个参数

    1.接口 public interface MemberMapper { public boolean insertMember(Members member); public Members sel ...

  7. Mybatis的mapper接口接受的参数类型

    最近项目用到了Mybatis,学一下记下来. Mybatis的Mapper文件中的select.insert.update.delete元素中有一个parameterType属性,用于对应的mappe ...

  8. 8.mybatis动态SQL模糊查询 (多参数查询,使用parameterType)

    多参数查询,使用parameterType.实例: 用户User[id, name, age] 1.mysql建表并插入数据 2.Java实体类 public class User { public ...

  9. Mybatis的parameterType传入多个参数

    如果查询的条件有多个的时候,mybatis有三种传入方式: 1.通过注解传入 例如: public interface Mapper(){ public User login(@Param(" ...

随机推荐

  1. Centos命令行窗口显示一大串前缀,777;notify;Command completed;的解决方法

    How to remove the return code from the terminal prompt In addition to the PS1 environment variable, ...

  2. vs2017运行时修改代码Changes are not allowed while code is running.

    vs2017代码运行时不允许进行更改 工具->选项->调试->常规->启用编辑并继续不选择“启用编辑并继续”,这样就可以在调试时修改cs代码了.

  3. Django ORM-01

    What is ORM Django ? ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. ...

  4. springcloud(四) ribbon和feign

    Ribbon使用 order-service工程: application.yml: server: port: 9010 #order 服务都是用90 开头的端口 spring: applicati ...

  5. Go语言环境安装详细介绍

    工具链介绍 go有两套编译工具链,分别是从plant9移植过来的gc和依赖gcc的gccgo. 官方为gc工具链提供了二进制安装包和源码, 可以根据需要选择一种安装方式.gc工具链对操作系统和CPU类 ...

  6. MVC中@Html.Action的用法

    MVC项目中如果有公共部分的代码就可以单独拿出来作为控件来用(比如头部和底部代码).跟ASP.NET中的ASCX实现的效果一样,但MVC比它方便的多. 想要实现该效果,需要知道@Html.Action ...

  7. 将com口2号引脚、3号引脚引出来,两个引脚对接会出发中断

    思路:让程序一直不停的发数据,再设一个及接收事件,接通(短路)后触发. 灵感文章: 方案一:  去AQ解决话务台问题,下了车就牛不停蹄的去买了串口挡板,db9 female接口,根据2-3.3-2.5 ...

  8. AOP术语

    1.连接点(Joinpoint) 程序执行的某个特定位置:如类开始初始化前,类初始化后,类某个方法调用前,调用后,方法跑出异常后.一个类或一段程序代码拥有一些具有边界性质的特定点.这些代码中的特定点就 ...

  9. chrome36可以使用自定义元素的回调了

    <!DOCTYPE html> <html> <head> <title>ms-attr-*</title> <meta charse ...

  10. shell脚本学习指南-grep文本搜索命令-学习(3)

    1.作用 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全 ...