zoukankan      html  css  js  c++  java
  • @Param注解

    实际的应用场景

    /**
     * ArticleTypeMapper 数据访问类
     */
    public interface ArticleTypeMapper {
    
        @Select("select * from ec_article_type where code = #{xxxx}")
        ArticleType getTypeByCode(String typeCode);
    
        @Select("select * from ec_article_type")
        List<ArticleType> getArticleTypes();
    
        @Select("select * from ec_article_type where length(code) = 4")
        List<ArticleType> getFirstArticleTypes();
    
        @Select("select * from ec_article_type where code like #{typeCode} and length(code) = #{len} ")
        List<ArticleType> loadSecondTypes(@Param("typeCode") String typeCode, @Param("len") int i);
    }
    

    在SSM框架中,@Param主要是用来注解dao类中方法的参数,便于在对应的dao.xml文件中引用,如:在userDAO类中有这么一个函数:

    public User selectByNameAndPwd(@Param("userName") String name,@Param("Password") String )

    在其对应的dao.xml文件中的查询语句则为:

    select username,password from user where username=({userName} and password=){Password}

    注:在不使用@Param注解的时候,函数的参数只能为一个,并且在查询语句取值时只能用#{},且其所属的类必须为Javabean,而使用@Param注解则可以使用多个参数,在查询语句中使用时可以使用#{}或者${}。

  • 相关阅读:
    [HNOI2006] 公路修建问题
    [8.16模拟赛] 玩具 (dp/字符串)
    [NOI2014] 动物园
    [CF816E] Karen and Supermarket1 [树形dp]
    [POI2006] OKR-period of words
    [BZOJ4260] Codechef REBXOR
    [POJ3630] Phone List
    正确答案 [Hash/枚举]
    The xor-longest Path [Trie]
    [NOI1999] 生日蛋糕
  • 原文地址:https://www.cnblogs.com/Lilwhat/p/13220847.html
Copyright © 2011-2022 走看看