问一下编码的内容里的%是什么意思

try {
preparedStatement = connection.prepareStatement(sql);

		if (condition.getLineName() != null) {
preparedStatement.setString(1, "%" + condition.getLineName() + "%");
} else {
preparedStatement.setString(1, "%");
}
if (condition.getDirection() != null) {
if("2".equals(condition.getDirection())) {
preparedStatement.setString(2, "%");
}else {
preparedStatement.setString(2, "%" + condition.getDirection() + "%");

回答

SQL里的like关键字的语法

select * from t where t.name like '%张三%'
``
%表示模糊匹配
> 张三%    表示匹配所有name以“张三”开头的数据
> %张三    表示匹配所有name以“张三”结尾的数据
> %张三%    表示匹配所有name包含“张三”的数据
以上是问一下编码的内容里的%是什么意思的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>