• SSM横向拓展一个功能--->搜索


    首先编写对应的SQL,要完成的功能

    1、在Mapper接口里对应返回值类型

    Books queryBookByName(String bookName);

    2、对应Mapper里编写SQL

       <select id="queryBookByName" resultType="Books">
            select * from ssmbuild.books where bookName like CONCAT('%',#{bookName},'%')
        </select>

    3、编写Service层接口(和dao里的接口一样的)

    Books queryBookByName(String bookName);

    4、接口实现类

    public Books queryBookByName(String bookName) {
            return bookMapper.queryBookByName(bookName);
        }

    5、对应页面添加表单

    <div class="col-md-4 column">
    <form class="form-inline" action="${pageContext.request.contextPath}/query" method="post">
    <span style="color: red; font-weight: bold" >${error}</span>
    <input type="text" name="queryBookName" placeholder="请输入要查询的书籍名称" required>
    <input type="submit" value="查询">
    </form>
    </div>

    6、对应Controller    /query

    @RequestMapping("/query")
    public String query(String queryBookName,Model model){
    Books book=bookService.queryBookByName(queryBookName);
    if (book==null){
    model.addAttribute("error","未找到");
    List<Books> books=bookService.queryAllBook();
    model.addAttribute("list",books);
    return "allBook";
    }
    List<Books> books=new ArrayList<Books>();
    books.add(book);
    model.addAttribute("list",books);
    return "allBook";
    }
  • 相关阅读:
    What's New in Chrome DevTools All In One
    User Timing API All In One
    Tailwind CSS All In One
    CSS 3D rotate with mouse move All In One
    Event Timing API All In One
    Long Tasks API All In One
    js get window custom global variables All In One
    Web 前端广告落地页性能监控系统 All In One
    Element Timing API All In One
    base64编码
  • 原文地址:https://www.cnblogs.com/springxian/p/13750776.html
Copyright © 2020-2023  润新知