如果所传bookTypeName为空则执行select * from t_bookType(搜索框里未输入信息)

否则追加 and bookTypeName like  '%"+bookType.getBookTypeName()+"%'

如果是追加的第一个and则替换为where:

sb.toString().replaceFirst("and", "where")

方法代码示例如下:

public ResultSet bookTypeList(Connection con,BookType bookType) throws SQLException{
StringBuffer sb=new StringBuffer("select * from t_bookType") ;
if(StringUtil.isNotEmpty(bookType.getBookTypeName())){
sb.append(" and bookTypeName like '%"+bookType.getBookTypeName()+"%'");
}
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}

 

相关文章:

  • 2021-12-11
  • 2022-02-08
  • 2022-12-23
  • 2022-01-16
  • 2022-02-08
  • 2021-05-28
  • 2021-08-14
猜你喜欢
  • 2022-12-23
  • 2021-08-06
  • 2021-11-23
  • 2021-10-16
  • 2021-11-09
  • 2021-08-26
相关资源
相似解决方案