The springboot integration mybatis reported an error. The parameter cannot be found

Today, I stepped on a pit when I implemented a login page in springboot and mybatis

It always shows that the parameter cannot be found, and many blogs on the Internet have not found the reason

  Finally, it was pointed out by the leaders in the group that the @ param annotation was missing in the usermapper parameter

 

This SQL statement is used in usermapper, resulting in an error

 

  So I sorted out the usage of a wave of @ param annotations from the Internet

1. Use @ param annotation

When writing SQL statements in the following way:

    @ Select(“select column from table where userid = #{userid} “)
    public int selectColumn(int userid);

When you use the @ param annotation to declare parameters, you can use either #{} or ${}.

    @ Select(“select column from table where userid = ${userid} “)
    public int selectColumn(@Param(“userid”) int userid);

When you do not use the @ param annotation to declare parameters, you must use the use #{} method. If you use ${}, an error will be reported.

    @ Select(“select column from table where userid = ${userid} “)
    public int selectColumn(@Param(“userid”) int userid);

2. Do not use @ param annotation

··When the @ param annotation is not used, there can only be one parameter and it is a java bean. JavaBean properties can be referenced in SQL statements, and only JavaBean properties can be referenced.

    // Here ID is the attribute of user

    @ Select(“SELECT * from Table where id = ${id}”)
    Enchashment selectUserById(User user);
1

Read More: