@param注解用法解析

@Param注解单一属性

 

    @Select({"select * from country where countryname=#{countryname} and countrycode=#{countrycode}"})
    Country selectByNameAndCode(@Param("countryname") String countryname,@Param("countrycode") String countrycode);


    @Select({"select * from country where countryname=#{param1} and countrycode=#{param2}"})
    Country selectByNameAndCode(@Param("countryname") String countryname,@Param("countrycode") String countrycode);

//不使用注解
    @Select({"select * from country where countryname=#{arg0} and countrycode=#{arg1}"})
    Country selectByNameAndCode( String countryname, String countrycode);

    @Select({"select * from country where countryname=#{param1} and countrycode=#{param2}"})
    Country selectByNameAndCode( String countryname, String countrycode);

配置该注解后,Mybatis会自动将参数封装成Map类型,@param注解值会作为Map的key

在xml文件中或注解方式里都可以使用#{param1},#{param2},#{countryname},#{countrycode}方法。当接口函数中只有一个参数(基本数据类型)时会直接使用该参数,不管这个参数叫什么。

例如

    @Delete({"delete from country where id=#{abc} "})
    int deleteById(int id);

abc与id不一样一样可以正常使用 。

@Param注解javaBean对象

    @Insert({"insert into country(countryname,countrycode) values(#{country.countryName},#{country.countryCode})"})
    int insertOne(@Param("country") Country country);

 


版权声明:本文为qq_39401280原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。