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:
- Vs2017 reported an error. Pthread. H header file cannot be opened and cannot be found
- The springboot integration CXF calls WebService and reports an error: cannot create a secure xmlinputfactory
- The vscode installation plug-in liveserver specified browser reported an error and could not be found
- When Maven hits the jar package, an error is reported when executing install, and the symbol cannot be found in a line
- Mac idea springboot project reported an error
- Springboot integration redis reports non null key required (solved)
- When C language refers to a user-defined type as a parameter, an error segmentation fault is reported
- The springboot test class reported an error NullPointerException
- When the mybatis field contains an expression, an error is reported when it is stored in the database
- Mybatis idea environment integration jar package
- An error is reported when springboot starts: error creating bean with name ‘XXXX’
- Kotlin reported an error jsonexception using fastjason: default constructor not found
- An error was reported when springboot connected to redis Servlet.service () for servlet [dispatcherServlet] in context with path [] threw e
- The main class could not be found or loaded when springboot started
- Springboot + mybatis plus transaction management
- Springboot integrated with mybatis
- After verifying parameters with validation, springboot reports an error: no constructor found in package name + class name
- An error of 500 is reported when an item is assigned to a role
- About the error querying database. Cause: java.lang.nullpointerexception reported in mybatis
- Springboot + mybatis + logback does not print SQL problems on the console