1 2 3 4 5 6 7 8 9 | <airport> <iata>oma</iata> <name>Eppley Airfield</name> <city>Omaha</city> <state>NE</state> <country>US</country> <lat>41.3019419</lat> <lng>-95.8939015</lng> </airport> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | def index = { switch(request.method){ case "POST": def airport = new Airport(params.airport) if(airport.save()){ response.status = 201 // Created render airport as XML } else{ response.status = 500 //Internal Server Error render "Could not create new Airport due to errors:\n ${airport.errors}" } break case "GET": //... case "PUT": //... case "DELETE": //... } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | $ curl --verbose --request POST --header "Content-Type: text/xml" --data @simpleAirport.xml http://localhost:9090/trip/rest/airport > POST /trip/rest/airport HTTP/1.1 > Content-Type: text/xml > Content-Length: 176 > < HTTP/1.1 201 Created < Content-Type: text/xml; charset=utf-8 <?xml version="1.0" encoding="utf-8"?><airport id="14"> <arrivals> <null/> </arrivals> <city>Omaha</city> <country>US</country> <departures> <null/> </departures> <iata>oma</iata> <lat>41.3019419</lat> <lng>-95.8939015</lng> <name>Eppley Airfield</name> <state>NE</state> </airport> |
1 2 3 4 5 6 7 | <airport iata="oma"> <official-name>Eppley Airfield</official-name> <city>Omaha</city> <state>NE</state> <country>US</country> <location latitude="41.3019419" longitude="-95.8939015"/> </airport> |
1 2 3 4 5 6 7 8 | def airport = new Airport() airport.iata = request.XML.@iata airport.name = request.XML."official-name" airport.city = request.XML.city airport.state = request.XML.state airport.country = request.XML.country airport.lat = request.XML.location.@latitude airport.lng = request.XML.location.@longitude |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | def index = { switch(request.method){ case "POST": //... case "GET": //... case "PUT": def airport = Airport.findByIata(params.airport.iata) airport.properties = params.airport if(airport.save()){ response.status = 200 // OK render airport as XML } else{ response.status = 500 //Internal Server Error render "Could not create new Airport due to errors:\n ${airport.errors}" } break case "DELETE": //... } } |
1 2 3 4 5 6 7 8 9 | <airport> <iata>oma</iata> <name>xxxEppley Airfield</name> <city>Omaha</city> <state>NE</state> <country>US</country> <lat>41.3019419</lat> <lng>-95.8939015</lng> </airport> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |