This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14807|Reply: 0

[Source] Usage and Role of @Param in mybatis

[Copy link]
Posted on 9/10/2018 10:34:00 AM | | |
When using annotations to simplify XML configuration, the role of @Param annotation is to name the parameters, and after naming the parameters, you can get the parameter value according to the name, and correctly pass the parameters into the SQL statement

Let's first look at the @Select method in the Mapper interface

Here's an explanation

1.@Select(....) The function of the annotation is to tell the mybatis framework to execute the SQL statement in parentheses

2.s_id id, s_name name, class_id classid format is field name + attribute name, for example s_id is the field name in the database, id is the attribute name in the class

    The function of this code is to realize the one-to-one mapping of database field names and entity class attributes, otherwise the database will not know how to match



3.where s_name= #{aaaa} and class_id = #{bbbb} means that the sql statement should accept 2 parameters, one parameter name is aaaa, one parameter name is bbbb, if you want to pass the correct parameters, then you need to name the parameters, because you don't need to use the xml configuration file, then we have to use other ways to name the parameters, this way is @Param annotations



4. Write @Param ("parameter name") in front of the method parameter to indicate the name of the parameter, and the name is the content in parentheses

public Student select(@Param("aaaa") String name,@Param("bbbb")int class_id);
Give the parameter String name to aaaa, and then sql statement.... where s_name= #{aaaa} to get the parameter value based on aaaa





Previous:Intellij IDEA SpringBoot Hot Boot is an ineffective solution using Spring-boot-devTools
Next:JPEXS Free Flash Decompiler
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com