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注解则可以使用多个参数,在查询语句中使用时可以使用#{}或者${}。

  • 相关阅读:
    HDU 5091 Beam Cannon (扫描线思想)
    UVA12904 Load Balancing(中途相遇法)
    linux虚拟机时间同步
    linux shell
    项目bug
    定时发送邮件出现问题
    kafka里面的topic消费情况查看
    kafka常见命令
    HiJson简要说明
    zookeeper、hbase常见命令
  • 原文地址:https://www.cnblogs.com/Lilwhat/p/13220847.html
Copyright © 2011-2022 走看看