public List<DUserVo> search(int start, Integer limit, String userName) {
QueryRunner queryRunner = new QueryRunner(DruidUtil.getDataSource());
String sql="select id,user_name userName,d_name dName,d_people dPeople,d_intro dIntro from d_user where 1=1";
ArrayList<Object> param = new ArrayList<Object>();
if(!userName.equals("")){
sql+=" and user_name like ? ";
param.add("%"+userName+"%");
}
sql+=" limit ?,?";
param.add(start);
param.add(limit);
System.out.println("sql = " + sql);
System.out.println(param);
try {
List<DUserVo> userVos = queryRunner.query(sql, new BeanListHandler<DUserVo>(DUserVo.class), param.toArray());
return userVos;
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return null;
}
模糊查询实现sql语句的搜索
最新推荐文章于 2023-10-25 17:58:10 发布