File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -94,4 +94,20 @@ SELECT * from fruits_20241204 where id=? [1]
9494```
9595可以看见${date}被替换成"20241204",而#{id}替换成了'?',同时param_list中只有一个参数值为1。
9696
97- 基于安全性的考虑,为了防止SQL注入,建议只要能使用#{}就不要使用${},除非你有足够的把握。
97+ 基于安全性的考虑,为了防止SQL注入,建议只要能使用#{}就不要使用${},除非你有足够的把握。
98+
99+ ## Cache
100+ mybatis-py为每条连接维护一个缓存池,淘汰策略是LRU,你可以定义池最大的字节容量,如果你不想使用cache,可以设置参数配置,代码如下:
101+ ``` python
102+ def main ():
103+ # 连接到 MySQL 数据库
104+ # conn = mysql.connector.connect(
105+ # host="localhost", # MySQL 主机地址
106+ # user="mybatis", # MySQL 用户名
107+ # password="mybatis", # MySQL 密码
108+ # database="mybatis" # 需要连接的数据库
109+ # )
110+
111+ mb = Mybatis(conn, " mapper" , cache_memory_limit = 50 * 1024 * 1024 ) # 容量上限为50MB
112+ mb2 = Mybatis(conn, " mapper" , cache_memory_limit = None ) # 不开启缓存
113+ ```
You can’t perform that action at this time.
0 commit comments