首页 > 代码库 > 传递数据到后台的几种方式

传递数据到后台的几种方式

0 cell-data-list.jsp

<form action="cell-data-list.jhtml?functionId=1093" theme="simple" method="post" target="_self" name="searchform" id="searchform">    <div class="s_top_opt">        <ul class="clear">            <li class="ck">cat</li>            <li><input type="text" class="w_t100" name="cat" value="http://www.mamicode.com/

 

 

 

1. form表单:1. 提交表单的时候先执行check()方法,为真时才去提交表单,付款时间用了wdatepicker插件

<div class="back_cform"><s:form action="savePrepaymentItem" onsubmit="return check()">    <input type="hidden" name="prepayment.id" value="http://www.mamicode.com/
1.2    public String prepaymentOrderInfo() {        Map<String, Object> json = new HashMap<>();        Optional<OrderDTO> orderDTO = prepaymentService.findOrderInfoByOrderNo(orderNo);        if (orderDTO.isPresent()) {            OrderDTO order = orderDTO.get();            json.put("id", order.getId());            json.put("no", order.getNo());            json.put("unitAl", order.getUnitAL());            if (order.calcUnitPriceFirst()) {                json.put("price", order.getLocalPrice());            } else {                double price = order.getRealPrice() - Math.floor(order.getRealPrice() * 0.1 * (10 - order.getDiscount())) + order.getShippingFee() - order.getDiscounts();                json.put("price", price);            }        } else {            json.put("id", null);        }        writeJSON(json);        return null;    }
1.3    @Override    public Optional<OrderDTO> findOrderInfoByOrderNo(String orderNo) {        String sql = "select id, no, unitAL, calcType, localPrice, realprice, discount, shippingFee, discounts" +                "\n from selleck_order" +                "\n where no=:no";        Map<String, Object> params = new HashMap<>();        params.put("no", orderNo);        List<Map<String, Object>> list = dao.findRawBySql(sql, params);        if (list.isEmpty()) {            return Optional.empty();        } else {            Map<String, Object> map = list.get(0);            OrderDTO order = new OrderDTO();            order.setId(((Number) map.get("id")).intValue());            order.setNo((String) map.get("no"));            order.setUnitAL((String) map.get("unitAL"));            order.setCalcType((String) map.get("calcType"));            if (map.get("localPrice") != null) {                order.setLocalPrice(((Number) map.get("localPrice")).doubleValue());            }            order.setRealPrice(((Number) map.get("realprice")).doubleValue());            order.setDiscount(((Number) map.get("discount")).doubleValue());            order.setShippingFee(((Number) map.get("shippingFee")).doubleValue());            order.setDiscounts(((Number) map.get("discounts")).doubleValue());            return Optional.of(order);        }    }
//1.4	protected void writeJSON(Object obj) {		try {			String json = mapper.writeValueAsString(obj);			HttpServletResponse response = ServletActionContext.getResponse();			response.setContentLength(json.getBytes(utf8).length);			response.setContentType("application/json;charset=UTF-8");			response.getWriter().write(json);		} catch (Exception e) {			e.printStackTrace();			throw new RuntimeException(e);		}	}

 

注意:js上面还有单独的

<s:url action="deletePrepaymentItem" var="deleteAction" escapeAmp="false">    <s:param name="prepayment.id" value="http://www.mamicode.com/prepayment.id"/>    <s:param name="item.id" value="http://www.mamicode.com/item.id"/></s:url>
//1.0  window.location = url;<script type="text/javascript">    $(‘#orderNo‘).on(‘change‘, function() {        $(‘#save‘).hide();        $.getJSON(‘<s:url action="prepaymentOrderInfo"/>‘, {orderNo: $(this).val()})                .done(function(json) {                    $(‘#orderId‘).val(json.id);                    $(‘#orderUnitAl‘).val(json.unitAl);                    $(‘#orderPrice‘).val(json.price);                    $(‘#orderPriceText‘).text(json.unitAl + ‘ ‘ + json.price);                })                .always(function() {                    $(‘#save‘).show();                })    });    $(‘#delete‘).on(‘click‘, function () {        if (confirm(‘由预付款中删除此订单?‘)) {            window.location = ‘<s:url action="deletePrepaymentItem"/>‘ + ‘?prepayment.id=‘ + ‘<s:property value="http://www.mamicode.com/prepayment.id"/>‘ + ‘&item.id=‘ + ‘<s:property value="http://www.mamicode.com/item.id"/>‘;        }    });</script>

 window.open(url);

    <script language="javascript">        function exportExcel() {            var company = $("#precompany").val();            var salesman = $("#presalesman").val();            var remainAmountType = $("#preselect").val();            var url = arshare/exportExcel.jhtml?company= + (encodeURI(company)) + &remainAmountType= + (encodeURI(remainAmountType)) + &salesman= + (encodeURI(salesman));            window.open(url)        }    </script>

 3. 通过a标签

                                    <s:iterator var="item" value="http://www.mamicode.com/#prepayment.items">                                    <tr>                                        <td class="w80"><label><s:property value="http://www.mamicode.com/#item.orderNo"/></label></td>                                        <td class="w100"><label><s:property value="http://www.mamicode.com/#item.orderUnitAl"/> <s:property value="http://www.mamicode.com/#item.orderPrice"/></label></td>                                        <td class="w100"><label><s:property value="http://www.mamicode.com/#prepayment.unitAl"/> <s:property value="http://www.mamicode.com/#item.paidPrice"/></label></td>                                        <td class="w120"><label><s:date name="#item.payDate" format="yyyy-MM-dd"/></label></td>                                        <td class="w100"><label><s:property value="http://www.mamicode.com/#item.operator"/></label></td>                                        <td class="w30">                                            <label>                                                <a href="http://www.mamicode.com/

 

传递数据到后台的几种方式