MyBatis @Param Annotation Explained
In MyBatis, the @Param annotation is used to give aliases to parameters in SQL statements, making it easier to reference these parameters in the SQL. When there are multiple parameters in a method in the Mapper interface, MyBatis cannot recognize the order of the parameters. Therefore, the @Param annotation is needed to give aliases to the parameters, allowing specific parameter values to be referenced in the SQL statements using the aliases. For example:
public User getUserById(@Param("id") int id, @Param("name") String name);
In the example above, the @Param annotation assigns aliases to the id and name parameters, allowing them to be referenced in the Mapper.xml file using these aliases, such as #{id} and #{name}.