jdbc实现模糊查询
下面为dao层内容,视线模糊查询,
public List<paper> Select_paper(String theme,String author,String coming) {
String sql = "select * from paper where title like '%"+theme+"%' and author like '%"+author+"%'";
List<paper> query = template.query(sql, new BeanPropertyRowMapper<>(paper.class));
return query;
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String theme = request.getParameter("theme");
String author = request.getParameter("author");
String coming = request.getParameter("coming");
/* System.out.println(theme);
System.out.println(author);
System.out.println(coming);*/
paperdao dao=new paperdao();
List<paper> papers = dao.Select_paper(theme, author, coming);
// System.out.println(papers);
request.setAttribute("papers",papers);
request.getRequestDispatcher("index.jsp").forward(request,response);
}
浙公网安备 33010602011771号