mybatis basic type passing parameters

 

Mybatis query sql passes in a string, int and other basic data types as parameters,

It needs to be written as follows, no matter what the parameter name is, it must be changed to "_parameter"

as follows:

1 <select id="findByName" parameterType="string" resultType="com.domain.entity.FactoryEntity">
2     SELECT * FROM T_FACTORY WHERE F_NAME LIKE "%${_parameter}%"
3     </select>

At the same time, the distinction between # and $ should be distinguished

#{}: resolves to a parameter marker for a JDBC prepared statement, and a #{ } resolves to a parameter placeholder.

${}: is just a pure string replacement, variable replacement will be done during dynamic SQL parsing.

  name-->cy

 eg:  select id,name,age from student where name=#{name}   -- name='cy'

       select id,name,age from student where name=${name}    -- name=cy

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326245995&siteId=291194637
Recommended