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

  • 相关阅读:
    kubernetes安全机制
    Django 与 Vue交互跨域问题解决
    ELK收集Kubernetes平台日志
    minikube 安装
    k8s安装教程
    Go 语言Map(集合)
    Go 语言类型转换
    Go 语言递归函数
    今天学习:CSS中的类class和标识id选择符(.和#号) 第一季
    人工智能星际争霸2教程
  • 原文地址:https://www.cnblogs.com/Lilwhat/p/13220847.html
Copyright © 2011-2022 走看看