问题遇到的现象和发生背景
mysql的版本:5.7.24
mybatis的版本:3.5.5
Mybatis操作mysql数据库使用$没问题而使用#却报错
问题相关代码,请勿粘贴截图
Mapper对应的接口
public interface ListDataMapper {
ArrayList<ListData> selectThirteen(@Param("table")String table, @Param("page")int page);
}
mapper对应的sql
<mapper namespace="com.supercount.mapper.ListDataMapper">
<select id="selectThirteen" resultType="ListData">
select name,REPLACE(score,'.','') as score,num from #{table} order by LPAD(score,7,0) asc limit #{(page-1)*13},13;
</select>
</mapper>
mybatis配置信息
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<package name="com.supercount.pojo"/>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql:///db1?useSSL=false&useServerPrepStmts=true&cachePrepStmts=true&useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="1948"/>
</dataSource>
</environment>
</environments>
<mappers>
<package name="com.supercount.mapper"/>
</mappers>
</configuration>
运行结果及报错内容
运行结果
我的解答思路和尝试过的方法
我使用了$可以解决但是不能防止sql注入
我想要达到的结果
使用#进行预编译可以防止注入漏洞