练习

dao

void addBook(Book book);

List<Book> selectBook();

void deleteAll(String bid);

//redis查询分类有没有值
List<Book> selectByFlie();

User loginUser(User user);

void addUser(User user);

List<User> selectAll();

User selectById(int uid);
void updateUser(User user);

sericeImpl
@Override
public List<Book> selectByFlie() {
    String zhi=JedisUtil.get("zhi");
    if(zhi==null){
        List<Book> bookList=bookDao.selectByFlie();
        String bl=JSON.toJSONString(bookList);
        JedisUtil.set("zhi",bl,50000);
        return bookList;
    }else {
        String zhi2=JedisUtil.get("zhi");
        List<Book> bookList2=JSON.parseArray(zhi2,Book.class);
        return bookList2;
    }



xmlsql
<delete id="deleteAll" parameterType="String">
    delete from th_book where bid in (${value})
</delete>

<insert id="addBook" parameterType="book">
    insert into th_book (bname,bintroduce,bfile,bflei) VALUES
    (#{bname},#{bintroduce},#{bfile},#{bflei})
</insert>

<select id="selectBook" resultType="book">
    select * from th_book
</select>

<select id="selectByFlie" resultType="book">
    select bflei from th_book
</select>


<select id="selectById" resultType="user">
    select * from th_user where uid=#{uid}
</select>

<update id="updateUser" parameterType="user">
    update th_user set unmae=#{uname},upwd={upwd}  where uid=#{uid}
</update>

<select id="loginUser" parameterType="user" resultType="user">
   select * from th_user where uname=#{uname} and upwd=#{upwd}
</select>

<insert id="addUser" parameterType="user">
   insert into th_user(uname,upwd) VALUES
    (#{uname},#{upwd})
</insert>

<select id="selectAll" resultType="user">
    select * from th_user
</select>


controller
    @RequestMapping(value = "/loginUser")
    public String loginUser(User user, Model model){
        User user1=userService.loginUser(user);
        model.addAttribute("user1",user1);
        return "redirect:/zt/selectBook.action";
    }

@RequestMapping(value = "toadd",method = RequestMethod.GET)
public String toadd(){
        return "addUser";
}
    @RequestMapping(value = "/addUser",method = RequestMethod.POST)
    public String addUser(User user){
        userService.addUser(user);
        return "senUser";
    }

    @RequestMapping(value = "/selectBook")
    public String selectBook(Model model,@RequestParam(value = "PageNum",defaultValue = "1")
            Integer PageNum, @RequestParam(value = "PageSize",defaultValue = "3") Integer PageSize){
        PageHelper.startPage(PageNum,PageSize);
        List<Book> bookList=bookService.selectBook();
        PageInfo pageInfo=new PageInfo(bookList);
        model.addAttribute("pageInfo",pageInfo);
        return "selAll";
    }

    @RequestMapping(value = "toaddB")
    public String toaddB(){
        return "addBook";
    }
    @RequestMapping(value = "/addBook", method = RequestMethod.POST)
    public String addBook(@RequestParam(value = "file", required = false)MultipartFile file,Book book, HttpServletRequest request) throws Exception {
        if (!file.isEmpty()) {
            String bfile = FileUtil.uploadFile(file, request);
            book.setBfile(bfile);
        } else {
            book.setBfile("");
        }
        bookService.addBook(book);

        return "redirect:/zt/selectBook.action";
    }

//    @RequestMapping(value = "/getredis")
//    public String getredis(Model model){
//        List<String > list=new ArrayList<>();
//
//        list.add("时间");
//        list.add("搞笑");
//
//        JedisUtil.set("ll",list,5000);
//        String  stredis=JedisUtil.get("ll");
//
//        List<String> list1=(List<String>) JSON.parse(stredis);
//        model.addAttribute("list",list);
//        return "addBook";
//    }

    @RequestMapping(value = "/deleteAll")
    @ResponseBody
    public String deleteAll(String bid){
        bookService.deleteAll(bid);
        return "0";
    }



jsp
添加图书
<form action="/zt/addBook.action" method="post" enctype="multipart/form-data">
    书名:<input type="text" name="bname">
    书介绍:<input type="text" name="bintroduce">
    书面:<input type="file" name="file">
    书分类:
    <%--<select name="bflei">--%>
        <%--<option>请选择</option>--%>
        <%--<c:forEach items="${list}" var="bflei">--%>
            <%--<option value="${bflei}">${bflei}</option>--%>
        <%--</c:forEach>--%>
    <%--</select>--%>

    <select name="bflei">
        <option value="小说">小说</option>
        <option value="搞笑">搞笑</option>
    </select>
    <input type="submit" value="添加图书">

</form>



查询所有
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<html>
<head>

     <script src="/resources/bootstrap/js/jquery-1.8.3.js"></script>
      <script>
          $(function () {
              $("#qx").click(function () {
                  $("input[name='bid']").prop("checked",this.checked);
              });
          });
          function delBook() {
             var bid=[];
             $("input[name='bid']:checked").each(function () {
                 id.push($(this).val());
             });
             if(bid==0){
                 alert("请选择您要删除的数据")
             }
             if(bid>0){
                 if(confirm("是否确定删除")){
                     $.post(
                         "${pageContext.request.contextPath}/zt/deleteAll.action",
                             {"bid":bid.join(",")},
                           function () {
                             alert("删除成功!")
                             window.location.reload(true)
                           } );
                 }
             }
          }
      </script>
</head>
<body>

   <table>
       <tr>
           <td><input type="checkbox" id="qx"></td>
           <td>ID</td>
           <td>书名</td>
           <td>书介绍</td>
           <td>书面</td>
           <td>书分类</td>
       </tr>

       <c:forEach items="${pageInfo.list}" var="bl">
           <tr>
               <td><input type="checkbox" name="bid" value="${bl.bid}"></td>
               <td>${bl.bid}</td>
               <td>${bl.bname}</td>
               <td>${bl.bintroduce}</td>
               <td><img src="${bl.bfile}" style="width: 100px" height="100px"></td>
               <td>${bl.bflei}</td>
           </tr>
       </c:forEach>
       <tr>
           <td colspan="5">
               <button οnclick="delBook()">删除</button>
           </td>
       </tr>
   </table>


   <div class="row">
       <div style="font-weight: bold;font-size: 16px;font-family:'微软雅体';" class="col-md-7"><i class="blue">${pageInfo.total}</i>条记录,
           当前显示第&nbsp;<i class="blue">${pageInfo.pageNum}/${pageInfo.pages}</i>&nbsp;</div>

       <nav aria-label="Page navigation">
           <ul class="pagination">
               <c:if test="${!pageInfo.isFirstPage}">
                   <li><a href="<%=basePath%>/zt/selectBook.action?PageNum=1">首页</a></li>

                   <li><a href="<%=basePath%>/zt/selectBook.action?PageNum=${pageInfo.pageNum-1 }"
                          aria-label="Previous">
                       <span aria-hidden="true">&laquo;</span>
                   </a>
                   </li>
               </c:if>
               <c:forEach items="${pageInfo.navigatepageNums }" var="num">
                   <c:if test="${num == pageInfo.pageNum }">
                       <li class="active"><a href="<%=basePath%>/zt/selectBook.action?PageNum=${num }">${num }</a>
                       </li>
                   </c:if>
                   <c:if test="${num != pageInfo.pageNum }">
                       <li><a href="<%=basePath%>/zt/selectBook.action?PageNum=${num }">${num }</a></li>
                   </c:if>
               </c:forEach>
               <c:if test="${!pageInfo.isLastPage}">
                   <li>
                       <a href="<%=basePath%>/zt/selectBook.action?PageNum=${pageInfo.pageNum+1 }"
                          aria-label="Next">
                           <span aria-hidden="true">&raquo;</span>
                       </a>
                   </li>
                   <li><a href="<%=basePath%>/zt/selectBook.action?PageNum=${pageInfo.lastPage}">尾页</a></li>
               </c:if>
           </ul>
       </nav>
   </div>
 <a href="/zt/toaddB.action">去添加图书</a>

</body>
</html>



添加购物车 查询总价格
TCart selnums();
//select sum(cprice) from th_cart
<tr>
    <td colspan="3">${cartnum}</td>
</tr>








模糊查询
//查询所有加模糊查询
List<Stock> selectAll(@Param("code")Integer code);

<select id="selectAll" resultType="Stock" parameterType="Integer">
    select * from t_stock
    <where>
        <if test="code!=null and code!=''">
          code like '%${code}%'
        </if>
    </where>

<td colspan="6">
    <form action="/stock/selectAll.action">
        <input type="text" name="code">
        <input type="submit" value="模糊查询">
    </form>
</td>








<td><a href="/stock/update.action?id=${one.id}">删除</a></td>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值