public List<User> selectUserLikeByName(String name) {
//'%'空格:userName空格'%' 一定要有空格,不然会报错
String sql = "SELECT id,username,sex,password,address FROM user WHERE username LIKE '%' :userName '%'";
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("userName", name);
RowMapper<User> rm = BeanPropertyRowMapper.newInstance(User.class);
List<User> users = namedParameterJdbcTemplate.query(sql, paramMap, rm);
return users;
}
在网上有人说这种模糊查询是可以的,但是实际中我用的postgresql数据库,这种写法 '%' :userName '%' 会报错syntax error at or near $1
哪位大神帮忙看看?