php editor Baicao is here to answer a common question: "Do I need @Bind?" For beginners, @Bind is a common annotation, used in some frameworks and libraries. However, in PHP, there is no need to use the @Bind annotation. PHP is a dynamic language and does not require explicit binding of function or method parameters. The parameters of functions and methods are bound according to the actual parameters passed in when called. Therefore, in PHP, there is no need to use the @Bind annotation for parameter binding. I hope to be helpful!
I accidentally discovered that in a spring boot project, I don't have to bind parameters in a query like the one below.
@sqlquery(""" select id, name from organisations where id = :id """) @registerrowmapper(organisationmapper.class) organisation getorgansation(@bind("id") string id);
This works:
@SqlQuery(""" select id, name from organisations where id = :id """) @RegisterRowMapper(OrganisationMapper.class) Organisation getOrgansation(String id);
However, when I upgrade another project (not the spring boot project) to use 3.43.0, I cannot remove the binding.
Does anyone have a good explanation as to why I can get the query to work without bindings in a spring boot project, but not in a normal java project? (Besides the obvious explanation, magic). Is there any trick I can use to skip binding?
This comment can only be omitted when compiling the code with the javac flag -parameters
. It's possible that the first project is compiling with that flag and the other one isn't.
The -parameters
flag was introduced in Java 8. If this flag is used, the method's variable names will be available to reflection at runtime. When JDBI can infer the variable name id
through reflection, there is no need for the @Bind
annotation to make it clear that it is for the query parameter id
.
Please also check the corresponding section of the reference document: https://www.php.cn/link/8012c0dd4aa84ef92dfa2de0c7163b5a
The above is the detailed content of Need @Bind?. For more information, please follow other related articles on the PHP Chinese website!