zoukankan      html  css  js  c++  java
  • 关于mybaits的注解@Param

    一、含义

      @param作为dao层的注解,为了解决多个参数时,参数类型不一致的问题。

     <select id="findEmpById" resultType="com.tsinkai.ettp.model.Emp" 
                                             parameterType="java.lang.Integer" >
            select 
                *
            from 
                emp
            where 
                id = #{id,jdbcType=INTEGER}
        </select>

    当只有一个参数时,parameterType可以确定类型,但当有两个不同类型的参数时,就无法满足条件。

    public Emp find(@Param("userName")String name,@Param("userAge")int age);
    <select id="find" resultMap="BaseResultMap" >
            select 
                *
            from 
                emp
            where 
                name=#{userName}
                and
                age=#{userAge}
        </select>

    使用@param后,就不需要指定parameterType了。

    同时,可以使用@Param同时指定两个Pojo类。

    public Emp find(@Param("s")Student student,@Param("t")Teacher teacher);
    <select id="find" resultMap="BaseResultMap" >
            select 
                *
            from 
                emp
            where 
                name=#{t.name}
                and
                age=#{s.age}
        </select>
    就算这个世道烂成一堆粪坑,那也不是你吃屎的理由
  • 相关阅读:

    入门动态规划问题
    AC自动机
    KMP算法
    [OpenGL]用鼠标拖拽图形移动
    HDU-2222 Keywords Search
    Trie
    Manacher算法
    linux环境搭建
    Android Studio使用JNI和NDK进行开发
  • 原文地址:https://www.cnblogs.com/whalesea/p/10931645.html
Copyright © 2011-2022 走看看