1.The difference between “#” and “$” in mybatis

# mybatis treats this as a string by default

(1) The variable must be passed using #. Using #{} is equivalent to using the placeholder form of PrepareStatement to improve efficiency. You can prevent SQL injection and so on. The # method is generally used to pass in added, modified values or query, delete where condition ID values

select * from t_user where name = #{param}

$mybatis does not do any processing on the incoming data, there is SQL injection risk

$is just a simple string concatenation, corresponding to the invariant part, can only be used $. The $method is used to pass in database objects, such as group by fields,order by fields, table names, etc.

select count(*), from t_user group by ${param}

2. Difference between String, StringBuffer, and StringBuilder

The Java platform provides two types of String: a String and StringBuffer/StringBuilder, they can store and manipulate strings. String is read-only, which means that the contents of the String referenced by String cannot be changed. The StringBuffer/StringBuilder class says string objects can be modified directly. StringBuilder, introduced in Java 5, is exactly the same method as StringBuffer, except that it is used in a single-threaded environment and is more efficient than StringBuffer because none of its aspects are modified by synchronized.