更新之后,创建时间不见了,问题出现在哪里?老师在视频里把设置创建时间给去掉了

更新之后,创建时间不见了,问题出现在哪里?老师在视频里把设置创建时间给去掉了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public void update(ClaimVoucher claimVoucher, List<ClaimVoucherItem> items) {
    claimVoucher.setNextDealSn(claimVoucher.getCreateSn());
    claimVoucher.setStatus(Constant.CLAIMVOUCHER_CREATED);
    claimVoucherDao.update(claimVoucher);
 
    List<ClaimVoucherItem> olds=claimVoucherItemDao.selectByClaimVoucher(claimVoucher.getId());
    for(ClaimVoucherItem old:olds){
        boolean isHave=false;
        for(ClaimVoucherItem item:items){
            if(old.getId()==item.getId()){
                isHave=true;
                break;
            }
        }
 
        if(!isHave){
            claimVoucherItemDao.delete(old.getId());
        }
    }
 
    for(ClaimVoucherItem item:items){
        item.setClaimVoucherId(claimVoucher.getId());
       if(item.getId()!=null&&item.getId()>0){
           claimVoucherItemDao.update(item);
       }else{
           claimVoucherItemDao.insert(item);
       }
    }
 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//去更新
@RequestMapping("/to_update")
public String toUpdate(int id,Map<String,Object> map){
    map.put("items", Constant.getItems());
    ClaimVoucherInfo info=new ClaimVoucherInfo();
    info.setClaimVoucher(claimVoucherBiz.get(id));
    info.setItems(claimVoucherBiz.getItems(id));
    map.put("info",info);
    return "claim_voucher_update";
}
//更新
@RequestMapping("/update")
public String update(HttpSession session,ClaimVoucherInfo info){
    Employee employee=(Employee)session.getAttribute("employee");
    info.getClaimVoucher().setCreateSn(employee.getSn());
    claimVoucherBiz.update(info.getClaimVoucher(),info.getItems());
    return "redirect:deal";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="top.jsp"/>
<section id="content" class="table-layout animated fadeIn">
    <div class="tray tray-center">
        <div class="content-header">
            <h2> 修改报销单 </h2>
            <p class="lead"></p>
        </div>
        <div class="admin-form theme-primary mw1000 center-block" style="padding-bottom: 175px;">
            <div class="panel heading-border">
                <form:form id="admin-form" name="addForm" modelAttribute="info" action="/claim_voucher/update" >
                    <form:hidden path="claimVoucher.id"/>
                    <div class="panel-body bg-light">
                        <div class="section-divider mt20 mb40">
                            <span> 基本信息 </span>
                        </div>
                        <div class="section">
                            <label for="claimVoucher.cause" class="field prepend-icon">
                                <form:input path="claimVoucher.cause" class="gui-input" placeholder="事由..."/>
                                <label for="claimVoucher.cause" class="field-icon">
                                    <i class="fa fa-lock"></i>
                                </label>
                            </label>
                        </div>
                        <div class="section-divider mt20 mb40">
                            <span> 费用明细 </span>
                        </div>
                        <div class="section row" id="items">
                            <c:forEach items="${info.items}" varStatus="sta">
                            <div>
                                <div class="col-md-3">
                                    <label for="items[${sta.index}].item" class="field prepend-icon">
                                        <form:hidden path="items[${sta.index}].id"/>
                                        <form:hidden path="items[${sta.index}].claimVoucherId"/>
                                        <form:select path="items[${sta.index}].item" cssClass="gui-input" placeholder="花销类型..." items="${items}"/>
                                    </label>
                                </div>
                                <div class="col-md-3">
                                    <label for="items[${sta.index}].amount" class="field prepend-icon">
                                        <form:input path="items[${sta.index}].amount" cssClass="gui-input money" placeholder="金额..." />
                                        <label for="items[${sta.index}].amount" class="field-icon">
                                            <i class="fa fa-lock"></i>
                                        </label>
                                    </label>
                                </div>
                                <div class="col-md-5">
                                    <label for="items[${sta.index}].comment" class="field prepend-icon">
                                        <form:input path="items[${sta.index}].comment" cssClass="gui-input" placeholder="备注..." />
                                        <label for="items[${sta.index}].comment" class="field-icon">
                                            <i class="fa fa-lock"></i>
                                        </label>
                                    </label>
                                </div>
                                <div class="col-md-1" style="text-align:right;">
                                    <button type="button" class="button"> X </button>
                                </div>
                            </div>
                            </c:forEach>
                        </div>
                        <div class="section row">
                            <div class="col-md-3">
                                <label for="totalMoney" class="field prepend-icon">
                                    <form:input id="totalMoney" path="claimVoucher.totalAmount" cssClass="gui-input" placeholder="总金额..." readonly="true" />
                                    <label for="totalMoney" class="field-icon">
                                        <i class="fa fa-user"></i>
                                    </label>
                                </label>
                            </div>
                            <div class="section" style="text-align:right;">
                                <div class="col-md-9">
                                    <button type="button" class="button" id="addItemButton"> + </button>
                                </div>
                            </div>
                        </div>
                        <div class="panel-footer text-right">
                            <button type="submit" class="button"> 保存 </button>
                            <button type="button" class="button" onclick="javascript:window.history.go(-1);"> 返回 </button>
                        </div>
                    </div>
                </form:form>
            </div>
        </div>
    </div>
</section>
<jsp:include page="bottom.jsp"/>
<%--<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>--%>
<%--<%@ page contentType="text/html;charset=UTF-8" language="java" %>--%>
 
<%--<jsp:include page="top.jsp"/>--%>
 
<%--<section id="content" class="table-layout animated fadeIn">--%>
<%--    <div class="tray tray-center">--%>
<%--        <div class="content-header">--%>
<%--            <h2> 填写报销单 </h2>--%>
<%--            <p class="lead"></p>--%>
<%--        </div>--%>
<%--        <div class="admin-form theme-primary mw1000 center-block" style="padding-bottom: 175px;">--%>
<%--            <div class="panel heading-border">--%>
<%--                <form:form id="admin-form" name="addForm" action="/claim_voucher/add" modelAttribute="info">--%>
<%--                    <div class="panel-body bg-light">--%>
<%--                        <div class="section-divider mt20 mb40">--%>
<%--                            <span> 基本信息 </span>--%>
<%--                        </div>--%>
<%--                        <div class="section">--%>
<%--                            <label for="claimVoucher.cause" class="field prepend-icon">--%>
<%--                                <form:input path="claimVoucher.cause" cssClass="gui-input" placeholder="事由..."/>--%>
<%--                                <label for="claimVoucher.cause" class="field-icon">--%>
<%--                                    <i class="fa fa-lock"></i>--%>
<%--                                </label>--%>
<%--                            </label>--%>
<%--                        </div>--%>
<%--                        <div class="section-divider mt20 mb40">--%>
<%--                            <span> 费用明细 </span>--%>
<%--                        </div>--%>
<%--                        <div class="section row" id="items">--%>
<%--                            <div>--%>
<%--                                <div class="col-md-3">--%>
<%--                                    <label for="items[0].item" class="field prepend-icon">--%>
<%--                                        <form:select path="items[0].item" cssClass="gui-input" placeholder="花销类型..." items="${items}"/>--%>
<%--                                    </label>--%>
<%--                                </div>--%>
<%--                                <div class="col-md-3">--%>
<%--                                    <label for="items[0].amount" class="field prepend-icon">--%>
<%--                                        <form:input path="items[0].amount" cssClass="gui-input money" placeholder="金额..."/>--%>
<%--                                        <label for="items[0].amount" class="field-icon">--%>
<%--                                            <i class="fa fa-lock"></i>--%>
<%--                                        </label>--%>
<%--                                    </label>--%>
<%--                                </div>--%>
<%--                                <div class="col-md-5">--%>
<%--                                    <label for="items[0].comment" class="field prepend-icon">--%>
<%--                                        <form:input path="items[0].comment" cssClass="gui-input" placeholder="备注..." />--%>
<%--                                        <label for="items[0].comment" class="field-icon">--%>
<%--                                            <i class="fa fa-lock"></i>--%>
<%--                                        </label>--%>
<%--                                    </label>--%>
<%--                                </div>--%>
<%--                                <div class="col-md-1" style="text-align:right;">--%>
<%--                                    <button type="button" class="button"> X </button>--%>
<%--                                </div>--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                        <div class="section row">--%>
<%--                            <div class="col-md-3">--%>
<%--                                <label for="totalMoney" class="field prepend-icon">--%>
<%--                                    <form:input id="totalMoney" path="claimVoucher.totalAmount" cssClass="gui-input" placeholder="总金额..." readonly="true"/>--%>
<%--                                    <label for="totalMoney" class="field-icon">--%>
<%--                                        <i class="fa fa-user"></i>--%>
<%--                                    </label>--%>
<%--                                </label>--%>
<%--                            </div>--%>
<%--                            <div class="section" style="text-align:right;">--%>
<%--                                <div class="col-md-9">--%>
<%--                                    <button type="button" class="button" id="addItemButton"> + </button>--%>
<%--                                </div>--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                        <div class="panel-footer text-right">--%>
<%--                            <button type="submit" class="button"> 保存 </button>--%>
<%--                            <button type="button" class="button" onclick="javascript:window.history.go(-1);"> 返回 </button>--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                </form:form>--%>
<%--            </div>--%>
<%--        </div>--%>
<%--    </div>--%>
<%--</section>--%>
 
<%--<jsp:include page="bottom.jsp"/>--%>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕阿慧 2020-09-02 17:02:45

同学你好,老师这边测试同学代码是没有问题的。

1、更新报销单并不会修改创建时间。更新后创建时间不见了,建议同学检查一下更新sql语句中是否修改了创建时间。如下:

http://img1.sycdn.imooc.com//climg/5f4f5f50093d785f11400140.jpg

2、同学说的添加和删除按钮指的是修改报销单页面中添加和删除报销项吗?如下:

http://img1.sycdn.imooc.com//climg/5f4f602a09c36b2307670339.jpg

如果是,老师这边测试是没有问题的。

3、同学可以重启Tomcat,清理一下浏览器缓存或者换个浏览器访问试试。

如果问题没有解决,建议同学详细说明一下问题,并提供一下相关jsp页面等代码。

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 提问者 慕标0359786 #1
    我的jsp代码完全复制老师的,我现在修改了sql语句之后,创建时间正常了,但是我添加两个报销单条目,我查看详细信息的时候它跳出很多条。。。 交通3000.0 旅游交通3000.0 旅游交通3000.0 旅游交通3000.0 旅游交通3000.0 旅游餐饮2000.0吃饭
    2020-09-02 17:55:34
  • 提问者 慕标0359786 #2
    我另外开一个问题截图给你看
    2020-09-02 17:56:18
  • 好帮手慕阿慧 回复 提问者 慕标0359786 #3
    同学你好,老师在另一个问答中回复了同学,同学可以参考另一个问答中的回复进行修改,如下 https://class.imooc.com/course/qadetail/252054 祝学习愉快~
    2020-09-02 19:01:27
提问者 慕标0359786 2020-09-02 15:52:18

而且添加按钮和那个删除按钮也失效了,我在添加报销单那里没问题的,代码是一样的,有引用items.js,不知道为什么突然就失效了

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码