发表于: 2017-12-27 23:53:35

2 489


今天完成的事:

遇到的困难:

1、对基本概念理解不清楚,比如static代表静态的,但具体也解释不太清,于是出现以下的问题

在单元测试中没有问题,但是在主方法中报空指针异常


2、超链接提交方式是get,form表单提交方式是get和post,对于rest接口中的update和delete,如果是以超链接形式提交,必须用jQuery和form表单,代码如下:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
   <title>Title</title>
   <script type="text/javascript" src="/scripts/jquery-1.9.1.min.js"></script>
   <script type="text/javascript">
       $(function(){
$(".delete").click(function(){
var href = $(this).attr("href");
               $("form").attr("action", href).submit();
               return false;
           });
       })
</script>
</head>
<body>

<form action="" method="post">
   <input type="hidden" name="_method" value="DELETE">
</form>

<c:if test="${studentlist==null}">
<h2>数据库没有数据</h2>
</c:if>
<c:if test="${studentlist != null}">



<table border="1" cellspacing="0" cellpadding="10" >
   <tr>
       <th>编号</th>
       <th>姓名</th>
       <th>年龄</th>
       <th>操作</th>
   </tr>
<c:forEach var="student" items="${studentlist}" >
<tr>
       <td>${student.id}</td>
       <td>${student.name}</td>
       <td>${student.age}</td>
       <th>
           <a href="<%= request.getContextPath()%>/u/${student.id}">修改</a>
           <a class="delete" href="d/${student.id}">删除</a>
           <%--<input type="submit" value="删除"/>--%>
       </th>
   </tr>
</c:forEach>
</table>

   <br/>
   <a href="${pageContext.request.contextPath}/a/student">添加</a>
</c:if>
<br>
<c:out value="${pageContext.request.contextPath}"/>
</body>
</html>

但是没跑通,controller中不用rest风格可以删除,而加上delete之后就会出现http405的报错,说明请求有问题, 伪post没有实现,然后对照了好几遍仍然不知道错误在哪。

url请求地址没错,引入jQuery文件没错,肯定是有一个小细节没找到。


3、写例子,没跑通,改,再改,找到大致方向但仍没跑通,对比着看,还不行,一上午过去了,效率低

有些例子按照网上的跑通了,但是一些原理性的东西说不清,只知道应该有哪几部,自己理解的过程也不知道对不对准确不准确

焦虑,无力,烦躁,找不到合适学习的方法,受打击,没信心,不写了,不符合格式就不符合吧,



明天计划:

1、看基础,包括动态代理、映射、map、事务等相关基础知识。

2、绝对路径和相对路径,相对路径的根是什么。一塌糊涂。


收获:

打日志的地方:

1、能否进入方法

2、关键变量是否正常获取


昨天的redirect的问题,加/后没问题了,应该是绝对路径和相对路径的问题,虽然解决了但知识点没仔细看呢。

 return "redirect:list";



返回列表 返回列表
评论

    分享到