JDBC实现模糊查询
下面为dao层内容,视线模糊查询,
1
2
3
4
5
|
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; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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); } |