璁㈠崟鍔熻兘妯″潡
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:杩欓噷鍖呭惈浜嗚鍗曠殑鍩烘湰淇℃伅
tb_order_item:璁㈠崟璇︽儏琛細璁㈠崟鐨勮鎯呬富瑕佸氨鏄喘涔板晢鍝佺殑淇℃伅锛岄€氳繃璁㈠崟鐨刬d鏉ュ疄鐜板叧鑱?/p>
tb_order_shipping锛氳鍗曢厤閫佽〃锛?/p>
杩欐槸涓変釜鍩烘湰鐨勮〃锛屽叾瀹炶繕鍙互鏈夌墿娴佷俊鎭〃锛岃鍗曚氦鏄撲俊鎭〃銆傝繖閲屾垜浠噰鐢ㄨ繖涓夊紶琛ㄨ冻澶熴€?/p>
涓夈€佽鍗曠郴缁熸帴鍙f枃妗o紝涓€鑸垜浠紑鍙戠殑鏃跺€欎細鏀跺埌宸茬粡鍐欏ソ鐨勬帴鍙f枃妗o紝姣斿鍒涘缓璁㈠崟鐨勬帴鍙f枃妗c€?/p>
浠庝笂闈㈣繖涓〃涓紝鎴戜滑鍙互鐪嬪埌璇ユ帴鍙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>
以上是关于璁㈠崟鍔熻兘妯″潡的主要内容,如果未能解决你的问题,请参考以下文章