璁㈠崟鍔熻兘妯″潡

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了璁㈠崟鍔熻兘妯″潡相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%bb%a3%e7%a0%81' title='浠g爜'>浠g爜   鍥㈤槦   string   rsh   framework   bsp   閫嗗悜宸ョ▼   insert   response   

璁㈠崟鍔熻兘妯″潡璁捐涓庡疄鐜?/h1>

鍦ㄥ晢鍩庨」鐩腑锛屼箣鍓嶆垜浠粙缁嶄簡璐墿杞﹀姛鑳芥ā鍧楃殑瀹炵幇锛屽晢鍝佸姞鍏ュ埌璐墿杞︿箣鍚庯紝灏辨槸鍒拌喘鐗╄溅缁撶畻锛岀劧鍚庢樉绀鸿喘鐗╄溅鐨勫晢鍝佸垪琛紝鐐瑰嚮鍘荤粨绠楋紝鐒跺悗鍒颁簡鏈彁浜ゅ墠鐨勮鍗曞垪琛紝

鐐瑰嚮鎻愪氦璁㈠崟鍚庯紝鐢熸垚姝よ鍗曪紝杩斿洖璁㈠崟鐨勮鍗曞彿锛屼粯娆鹃噾棰濓紝璁㈠崟棰勮鍒拌揪鏃堕棿銆傝鍗曠郴缁熸槸涓€涓潪甯搁噸瑕佺殑绯荤粺锛屾垜浠殑绉诲姩绔€丳C绔兘闇€瑕佽鍗曠郴缁燂紝鎵€浠ヨ繖閲屾垜浠皢璁㈠崟绯荤粺鍗曠嫭浣滀负涓€涓湇鍔℃潵锛岀暀鍑烘帴鍙d緵瀹㈡埛鍗曟潵璋冪敤銆?/p>

浠婂ぉ鎴戜滑鏉ョ湅涓嬭繖涓鍗曠郴缁熷埌搴曟槸濡備綍瀹炵幇鐨勶細

涓€銆佽鍗曠郴缁熷姛鑳?/p>

璁㈠崟绯荤粺涓昏鍖呭惈鍝簺鍔熻兘妯″潡鍛紵

鍒涘缓璁㈠崟鍔熻兘銆佹煡鐪嬭鍗曞垪琛ㄣ€佹牴鎹鍗昳d鏌ヨ璁㈠崟鐨勮缁嗕俊鎭€佽鍗曚慨鏀广€佽鍗曞彇娑堛€佽鍗曠姸鎬併€佽鍗曡瘎浠风瓑鍔熻兘鐨勫疄鐜般€?/p>

浠婂ぉ鎴戜滑鏉ョ湅涓嬪垱寤鸿鍗曠殑娴佺▼锛?/p>

浜屻€佽鍗曠郴缁熺殑鏁版嵁搴撹〃鐨勮璁?/p>

鍒涘缓璁㈠崟璇村埌搴曞氨鏄悜璁㈠崟琛ㄤ腑娣诲姞鏁版嵁锛屽嵆insert杩欎簺淇℃伅銆?/p>

涓嬪崟鍔熻兘涓€瀹氳浣跨敤鍏崇郴鍨嬫暟鎹簱琛紝淇濊瘉鏁版嵁鐨勪竴鑷存€э紝鍥犱负鍒涘缓璁㈠崟瑕佷繚璇佸湪涓€涓簨鍔★紙涓€涓簨鍔″氨鏄寚鍚戞暟鎹簱涓繘琛岀殑涓€绉嶆搷浣滐細姣斿鎻掑叆锛屽垹闄ょ瓑绛夛級閲岄潰锛宯osql鏁版嵁搴撲笉鏀寔浜嬪姟锛屽彲鑳戒細涓㈠け鏁版嵁銆?/p>

鎴戜滑鍦ㄧ綉涓婅喘鐗╃殑鏃跺€欓€氬父杩欎釜璁㈠崟鍖呭惈鐨勪俊鎭瘮杈冨锛屾墍浠ュ浜庤鍗曠郴缁熷浣曞垱寤哄畠鐨勬暟鎹簱涔熸槸闈炲父閲嶈鐨勩€傚垱寤烘暟鎹簱閬靛惊鏁版嵁搴撹璁$殑涓夊ぇ鑼冨紡鍘熷垯鏉ヨ璁°€?/p>

鎴戜滑鍒涘缓浜嗕笁涓〃锛歵b_order(璁㈠崟淇℃伅琛?,tb_order_item锛堣鍗曡鎯呰〃锛?tb_order_shipping锛堣鍗曢厤閫佽〃锛?

tb_order:杩欓噷鍖呭惈浜嗚鍗曠殑鍩烘湰淇℃伅

  鎶€鏈浘鐗? src=

tb_order_item:璁㈠崟璇︽儏琛細璁㈠崟鐨勮鎯呬富瑕佸氨鏄喘涔板晢鍝佺殑淇℃伅锛岄€氳繃璁㈠崟鐨刬d鏉ュ疄鐜板叧鑱?/p>

鎶€鏈浘鐗? src=

tb_order_shipping锛氳鍗曢厤閫佽〃锛?/p>

鎶€鏈浘鐗? src=

杩欐槸涓変釜鍩烘湰鐨勮〃锛屽叾瀹炶繕鍙互鏈夌墿娴佷俊鎭〃锛岃鍗曚氦鏄撲俊鎭〃銆傝繖閲屾垜浠噰鐢ㄨ繖涓夊紶琛ㄨ冻澶熴€?/p>

涓夈€佽鍗曠郴缁熸帴鍙f枃妗o紝涓€鑸垜浠紑鍙戠殑鏃跺€欎細鏀跺埌宸茬粡鍐欏ソ鐨勬帴鍙f枃妗o紝姣斿鍒涘缓璁㈠崟鐨勬帴鍙f枃妗c€?/p>

鎶€鏈浘鐗? src=

鎶€鏈浘鐗? src=

浠庝笂闈㈣繖涓〃涓紝鎴戜滑鍙互鐪嬪埌璇ユ帴鍙g殑url锛屾帴鍙g殑浼犲叆鍙傛暟鍜岃繑鍥炲€笺€?/p>

鎺ヤ笅鏉ユ垜浠拡瀵硅繖涓変釜鏉ヨ繘琛屼唬鐮佺殑缂栧啓锛?/p>

url灞炰簬controller灞傦紝

浼犲叆鍙傛暟杩欓噷鎴戜滑鍙互鐪嬪埌鏄暟鎹簱寤虹珛鐨勪笁寮犺〃淇℃伅锛氱涓€涓槸tb_order,绗簩涓槸涓€涓泦鍚堝紡鐨勮鍗曟槑缁哃ist锛岀涓変釜鏄鍗曠殑閰嶉€佷俊鎭〃銆?/p>

鎵€浠ヤ紶鍏ュ弬鏁板氨鏄繖涓変釜瀵硅薄銆傝繖閲屾垜浠槸缂栧啓鎺ュ彛锛屼緵瀹㈡埛绔皟鐢紝鑷充簬瀹㈡埛绔€庝箞灏嗚繖浜涘弬鏁颁紶閫掕繃鏉ワ紝閭f槸瀹㈡埛绔洟闃熻€冭檻鐨勪簨鎯呫€?/p>

杩斿洖鍊艰繖閲屼娇鐢ㄤ簡taotaoresult鏉ュ寘瑁呬簡涓嬶紝鍥犱负鎴戜滑鎻愪氦璁㈠崟鎴愬姛鍚庯紝杩斿洖鐨勬槸璁㈠崟鍙凤紝鍗宠鍗曠殑id鎵€浠ワ紝鎴戜滑闇€瑕佸悜瀹㈡埛绔紶閫掕鍗昳d杩囧幓锛屽苟鏄剧ず鍦ㄨ鍗曞垱寤烘垚鍔熺殑椤甸潰銆?/p>

涓嬮潰鐪嬩笅璁㈠崟鏈嶅姟鎺ュ彛鐨剆ervice灞傜殑瀹炵幇锛?/p>

service灞傜殑涓昏瀹炵幇鏄皢璁㈠崟淇℃伅娣诲姞鍒版暟鎹簱涓紝鍗虫帴鏀禼ontroller浼犻€掕繃鏉ョ殑瀵硅薄锛岀劧鍚庤ˉ鍏ㄩ〉闈㈡病鏈夌殑瀛楁锛宨nsert鏁版嵁搴擄紝杩欓噷鍙互浣跨敤閫嗗悜宸ョ▼鐢熸垚鐨刣ao銆?/p>

鍙﹀杩樻湁涓棶棰橈細

璁㈠崟缂栧彿锛氳鍗曠紪鍙风敤浠€涔堝舰寮忔瘮杈冨ソ鍛紵

瑙e喅鏂规涓€锛堜笉鑳戒娇鐢級锛?/p>

浣跨敤mysql鐨勮嚜澧為暱銆?/p>

浼樼偣锛氫笉闇€瑕佹垜浠嚜宸辩敓鎴愯鍗曞彿锛宮ysql浼氳嚜鍔ㄧ敓鎴愩€?/p>

缂虹偣锛氬鏋滆鍗曡〃鏁伴噺澶ぇ鏃堕渶瑕佸垎搴撳垎琛紝姝ゆ椂璁㈠崟鍙蜂細閲嶅銆傚鏋滄暟鎹浠藉悗鍐嶆仮澶嶏紝璁㈠崟鍙蜂細鍙樸€?/p>

鏂规浜岋細鏃ユ湡+闅忔満鏁?/p>

閲囩敤姣+闅忔満鏁般€?/p>

缂虹偣锛氫粛鐒舵湁閲嶅鐨勫彲鑳姐€備笉寤鸿閲囩敤姝ゆ柟妗堛€傚湪娌℃湁鏇村ソ鐨勮В鍐虫柟妗堜箣鍓嶅彲浠ヤ娇鐢ㄣ€?/p>

鏂规涓夛細浣跨敤UUID 

浼樼偣锛氫笉浼氶噸澶嶃€?/p>

缂虹偣锛氶暱銆傚彲璇绘€ф煡銆備笉寤鸿浣跨敤銆?nbsp;

鏂规鍥涳細鍙鎬уソ锛屼笉鑳藉お闀裤€備竴鑸鍗曢兘鏄叏鏁板瓧鐨勩€傚彲浠ヤ娇鐢╮edis鐨刬ncr鍛戒护鐢熸垚璁㈠崟鍙枫€?/p>

浼樼偣锛氬彲璇绘€уソ锛屼笉浼氶噸澶?/p>

缂虹偣锛氶渶瑕佹惌寤簉edis鏈嶅姟鍣ㄣ€?/p>

鎵€浠ユ垜浠€夊彇鏂规鍥涗綔涓虹敓鎴愯鍗曞彿鐨勬柟妗堛€?/p>

閭d箞service灞傜殑缂栫爜濡備笅锛?/p>

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
package com.taotao.order.service.impl;
 
import java.util.Date;
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import com.taotao.common.utils.TaotaoResult;
import com.taotao.mapper.TbOrderItemMapper;
import com.taotao.mapper.TbOrderMapper;
import com.taotao.mapper.TbOrderShippingMapper;
import com.taotao.order.dao.JedisClient;
import com.taotao.order.service.OrderService;
import com.taotao.pojo.TbOrder;
import com.taotao.pojo.TbOrderItem;
import com.taotao.pojo.TbOrderShipping;
//璁㈠崟妯″潡瀹炵幇
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private TbOrderMapper orderMapper;
    @Autowired
    private TbOrderItemMapper orderItemMapper;
    @Autowired
    private TbOrderShippingMapper shippingMapper;
    @Autowired
    private JedisClient jedisClient;
    @Value("${ORDER_GEN_KEY}")
    private String ORDER_GEN_KEY;
    @Value("${ORDER_DEFAULT_KEY}")
    private String ORDER_DEFAULT_KEY;
    @Value("${ORDER_ITEM_KEY}")
    private String ORDER_ITEM_KEY;
     
//鍒涘缓璁㈠崟鍔熻兘瀹炵幇
    @Override
    public TaotaoResult createOrder(TbOrder order,List<TbOrderItem> orderItem, TbOrderShipping orderShipping) {
        //閫昏緫姝ラ锛氬垱寤鸿鍗曞嵆鍚戞暟鎹簱涓笁涓〃涓彃鍏ユ暟鎹紝鎵€浠ヨ鏁版嵁搴撲腑鐨勫瓧娈佃ˉ鍏ㄥ嵆鍙€傞〉闈紶閫掕繃鏉ョ殑灏变笉闇€瑕佽ˉ鍏ㄤ簡锛岀洿鎺ュ彲浠ュ啓鍏ユ暟鎹簱
        /*绗竴姝ワ細璁㈠崟鍙风殑鐢熸垚鏂瑰紡锛氬洜涓鸿鍗曞彿鐨勭壒娈婃€э紝璁㈠崟鍚庢渶濂介噰鐢ㄦ暟瀛楃粍鎴愶紝涓斾笉鑳介噸澶嶏紝鍙互閲囩敤redis涓嚜澧為暱鐨勬柟寮忔潵瀹炵幇锛?/code>
         * 鍦╮edis涓?濡傛灉鏃爇ey锛屽垯redis鑷姩鍒涘缓浣犲啓鐨刱ey鐨勫悕瀛椼€傞噰鐢╥ncr鐨勫懡浠ゆ潵瀹炵幇璁㈠崟鍙风殑鑷銆傞粯璁よ嚜澧炴槸浠?寮€濮嬬殑锛屽洜涓鸿€冭檻鍒扮敤鎴风殑鍘熷洜锛屽湪redis涓缃竴涓粯璁ょ殑key鍊?/code>
         * 杩欐牱鐢ㄦ埛浣撻獙浼氬ソ浜涳紝涓嶄細鍥犱负鐪嬪埌绠€鍗曠殑1锛?锛?锛屾墍浠ヨ缃竴涓粯璁ょ殑key鍊?/code>
        */
        String string = jedisClient.get(ORDER_GEN_KEY);
        if (StringUtils.isBlank(string)) {
            //濡傛灉redis涓殑key涓虹┖锛屽垯鍒╃敤榛樿鍊?/code>
            String defaultKey = jedisClient.set(ORDER_GEN_KEY,ORDER_DEFAULT_KEY);  
        }
        //濡傛灉瀛樺湪姝ey鍒欙紝閲囩敤incr鍛戒护鑷
        long orderId= jedisClient.incr(ORDER_GEN_KEY);
        //鐒跺悗鍚戣鍗曡〃涓彃鍏ユ暟鎹?/code>
        order.setOrderId(orderId+"");
        //璁㈠崟鐘舵€侊細鐘舵€侊細1銆佹湭浠樻锛?銆佸凡浠樻锛?銆佹湭鍙戣揣锛?銆佸凡鍙戣揣
        order.setStatus(1);
        order.setCreateTime(new Date());
        order.setUpdateTime(new Date());
        order.setBuyerRate(0);
        //琛ュ叏瀹屼俊鎭悗锛屾彃鍏ユ暟鎹簱琛?/code>
        orderMapper.insert(order);
        //琛ュ叏瀹岃鍗曡〃鍚庯紝灏嗚鍗曟槑缁嗚〃琛ュ叏锛屽洜涓轰箣鍓嶈鍗曞啓鍏edis锛岃鍗曟槑缁嗙殑id涔熷啓鍏edis鍚э紝鑷姩鍒涘缓杩欎釜id鐨刱ey銆傝繖涓笉闇€瑕侀粯璁ょ紪鍙蜂簡銆傚姣旈〉闈紶閫掔殑鍙傛暟锛屽皢鍓╀笅鐨勮ˉ鍏?/code>
       String string2 = jedisClient.get(ORDER_ITEM_KEY);
       long orderItemId = jedisClient.incr(string2);
       //鍥犱负浼犻€掕繃鏉ョ殑鏄竴涓泦鍚堝垪琛紝鎵€浠ラ亶鍘嗗垪琛?/code>
       for (TbOrderItem tbOrderItem : orderItem) {
           tbOrderItem.setId(orderItemId+"");
           tbOrderItem.setOrderId(orderId+""); 
           orderItemMapper.insert( tbOrderItem);
    
        //鎺ヤ笅鏉ヨˉ鍏ㄨ鍗曢厤閫佽〃
        orderShipping.setOrderId(orderId+"");
        orderShipping.setCreated(new Date());
        orderShipping.setUpdated(new Date());
        shippingMapper.insert(orderShipping);
         
        return TaotaoResult.ok(orderId);
    }
 
}

銆€controller锛氬眰瀹炵幇

controller闇€瑕佸皢瀵硅薄浼犻€掔粰service灞傦細锛堝鎴风鍚戞湇鍔″櫒绔紶鍏ョ殑鍙傛暟鏍煎紡锛岃瑙佸悗闈㈠崥鏂囷級

鎴戜滑鐪嬪埌鎺ュ彛鏂囨。涓紝controller鎺ユ敹鐨勫弬鏁版槸涓€涓猨son鏍煎紡鐨勫瓧绗︿覆锛屼篃灏辨槸璇村鎴风浼犻€掕繃鏉ョ殑鏄痡son鏍煎紡鐨勫瓧绗︿覆銆?/p>

杩欏氨娑夊強鍒皊pringMVC鏄浣曟帴鏀秊son瀛楃涓茬殑锛岄渶瑕佺敤鍒癅RequestBody娉ㄨВ銆傝繖閲屽璇村嚑鍙ワ細

@ResponseBody娉ㄨВ鐨勫師鐞嗘槸response鍙兘鍝嶅簲涓€涓瓧绗︿覆锛屽綋鎴戜滑鐨勮繑鍥炲€兼槸java瀵硅薄鐨勬椂鍊欙紝瀹冩湁涓€涓粯璁よ涓猴紝鍗冲埄鐢╦ackson鍖呭皢java瀵硅薄杞负瀛楃涓插搷搴斻€傝繖鏄竴涓粯璁よ嚜鍔ㄧ殑琛屼负锛屼笉闇€瑕佹垜浠缃紝鍙杩欎釜娉ㄨВ鍗冲彲銆?/p>

@RequestBody娉ㄨВ鍚岀悊锛氬埄鐢ㄨ繖涓敞瑙e憡璇塻pringMVC鎴戜滑鐜板湪鎺ユ敹鐨勬槸涓€涓猨son瀛楃涓诧紝闇€瑕侀噰鍙栭粯璁よ涓哄埄鐢╦ackson鍖呭皢json瀛楃涓茶浆鎹负java瀵硅薄锛屾墍浠ontroller灞傛垜浠渶瑕佷竴涓猨ava瀵硅薄鐨刾ojo銆?/p>

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
package com.taotao.order.pojo;
 
import java.util.List;
 
import com.taotao.pojo.TbOrder;
import com.taotao.pojo.TbOrderItem;
import com.taotao.pojo.TbOrderShipping;
 
public class Order extends TbOrder {
    private List<TbOrderItem> orderItems;
    private TbOrderShipping orderShipping;
    public List<TbOrderItem> getOrderItems() {
        return orderItems;
    }
    public void setOrderItems(List<TbOrderItem> orderItems) {
        this.orderItems = orderItems;
    }
    public TbOrderShipping getOrderShipping() {
        return orderShipping;
    }
    public void setOrderShipping(TbOrderShipping orderShipping) {
        this.orderShipping = orderShipping;
    }
 
}

銆€銆€controller灞傚疄鐜帮細

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
package com.taotao.order.controller;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.taotao.common.utils.ExceptionUtil;
import com.taotao.common.utils.TaotaoResult;
import com.taotao.order.pojo.Order;
import com.taotao.order.service.OrderService;
//璁㈠崟绠$悊妯″潡
@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @RequestMapping("/create")
    @ResponseBody
    public TaotaoResult createOrder(@RequestBody Order order ){//鍒涘缓璁㈠崟妯″潡瀹炵幇
        try {
            TaotaoResult taotaoResult = orderService.createOrder(order ,order.getOrderItems(), order.getOrderShipping());
            return taotaoResult;
        catch (Exception e) {
            e.printStackTrace();
            return TaotaoResult.build(500,ExceptionUtil.getStackTrace(e));
        }
     
    }
 
}

銆€銆€浠ヤ笂浠g爜鏄鍗曟湇鍔℃帴鍙g殑鍒涘缓璁㈠崟鎺ュ彛浠g爜瀹炵幇銆?/p>

鎺ヤ笅鏉ユ垜浠湅涓嬪鎴风濡備綍璋冪敤璁㈠崟鏈嶅姟灞傜殑锛?/p>

瀹㈡埛绔綋鎴戜滑鐐瑰嚮鍘昏喘鐗╄溅缁撶畻鐨勬椂鍊欙紝鏄剧ず璐墿杞﹀垪琛ㄣ€?/p>

鍦ㄨ喘鐗╄溅鍒楄〃椤甸潰锛屽綋鐐瑰嚮鍘荤粨绠楃殑鏃跺€欙紝璺宠浆鍒版湭鎻愪氦璁㈠崟鐨勯〉闈€?/p>

鐐瑰嚮鎻愪氦璁㈠崟锛岃烦杞埌鏄剧ず鎴愬姛椤甸潰銆?/p>

controller灞傚疄鐜?

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
package com.taotao.portal.controller;
 
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.taotao.portal.pojo.CartItem;
import com.taotao.portal.pojo.Order;
import com.taotao.portal.service.CartService;
import com.taotao.portal.service.OrderService;
 
@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private CartService cartService;
    @Autowired
    private OrderService orderService;
    @RequestMapping("/order-cart")
    //鐐瑰嚮鍘荤粨绠楋紝鏄剧ず璁㈠崟鐨勯〉闈?/code>
    public String showOrderPage(HttpServletRequest request,HttpServletResponse response,Model model){
        List<CartItem> list= cartService.showCartList(request);
        model.addAttribute("cartList", list);
        return "order-cart";   
    }
    //鐐瑰嚮鎻愪氦璁㈠崟锛屾樉绀鸿鍗曞彿锛岃鍗曢噾棰濓紝棰勮閫佽揪鏃堕棿
    @RequestMapping("/create")
    public String showSuccessOrder(Order order,Model model){
     try {
 
        String orderId= orderService.createOrder(order);
        model.addAttribute("orderId ",orderId);
        model.addAttribute("payment",order.getPayment());
        model.addAttribute("date"new DateTime().plusDays(3).toString("yyyy-mm-dd"));
        return "success";
     
    catch (Exception e) {
    e.printStackTrace();
    model.addAttribute("message""鍒涘缓璁㈠崟鍑洪敊");
    return "error/exception";
   }
    }
}

銆€銆€service灞傚疄鐜帮細

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
package com.taotao.portal.service.impl;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import com.taotao.common.utils.HttpClientUtil;
import com.taotao.common.utils.JsonUtils;
import com.taotao.common.utils.TaotaoResult;
import com.taotao.portal.pojo.Order;
import com.taotao.portal.service.OrderService;
@Service
public class OrderServiceImpl implements OrderService {
    @Value("${ORDER_BASE_URL}")
    private String ORDER_BASE_URL;
    @Value("${ORDER_CREATE_URL}")
    private String ORDER_CREATE_URL;
     
//鍒涘缓璁㈠崟鐨勫鎴风瀹炵幇
    @Override
    public String createOrder(Order order) {
    //鍥犱负httpclientUtil涓璬opost浼犻€掔殑鏄痡son鏍煎紡鐨勬暟鎹紝鎵€浠ラ渶瑕佸皢order杩欎釜java瀵硅薄杞崲鎴怞son鏍煎紡 
        String json = HttpClientUtil.doPost(ORDER_BASE_URL+ORDER_CREATE_URL+JsonUtils.objectToJson(order));
        //涓轰簡鑾峰彇閲岄潰鐨勮鍗昳d锛屾垜浠渶瑕佸皢鑾峰緱鐨勫瓧绗︿覆杞崲涓簍aotaoresult锛岀劧鍚庤幏鍙栨暟鎹?鍥犱负鏈嶅姟灞備紶閫掕繃鏉ョ殑灏辨槸璁㈠崟鐨刬d锛屾墍浠ヨ幏寰楁暟鎹篃鏄幏寰楃殑id
        TaotaoResult result= TaotaoResult.format(json);
        if (result.getStatus()==200) {
            Object orderId = result.getData();
            return orderId.toString();
        }
        return "";
    }
 
}

銆€銆€杩欓噷鍚屾牱鐢ㄤ簡pojo绫籓rder绫汇€?/p>

鎷︽埅鍣ㄧ殑闂锛氬洜涓烘彁浜よ鍗曟垜浠渶瑕佺敤鎴风櫥褰曪紝鎵€浠ュ湪springMVC.xml鏂囦欢涓厤缃笂锛?/p>

鎶€鏈浘鐗? src=

 

以上是关于璁㈠崟鍔熻兘妯″潡的主要内容,如果未能解决你的问题,请参考以下文章

R璇█涓嚑涓父鐢ㄧ殑鏁板鍔熻兘

淇濇姢鍔熻兘璁板綍

pandas 甯哥敤鍔熻兘

link rel=alternate缃戠珯鏇挎崲鍔熻兘

涓篢ypecho澧炲姞鏂囩珷闃呰娆℃暟缁熻鍔熻兘

Java鍗冪櫨闂甠08JDK璇﹁В锛?15锛塤JVMTI鎻愪緵鍝簺鍔熻兘