spring boot ´´½¨·½Ê½
ÅäÖ÷½Ê½£º
server.context-path= xxx
ÅäÖ÷½Ê½£º
×¢ÒâÊôÐÔֵðºÅºóÃæÒª¼ÓÒ»¸ö¿Õ¸ñ
ÅäÖÃÎļþµÄ¿Ó£º
application.properties ÅäÖÃÖÐÎÄÖµµÄʱºò£¬¶ÁÈ¡³öÀ´µÄÊôÐÔÖµ»á³öÏÖÂÒÂëÎÊÌâ¡£µ«ÊÇ application.yml ²»»á³öÏÖÂÒÂëÎÊÌâ¡£ÔÒòÊÇ£¬Spring Boot ÊÇÒÔ iso-8859 µÄ±àÂ뷽ʽ¶ÁÈ¡ application.properties ÅäÖÃÎļþ¡£
´´½¨ºÍÅäÖöÔÓ¦µÄ¶ÔÏó
@Controller+@responseBody×éºÏ×¢½â
·µ»ØjsonÊý¾Ý
À¹½ØÇëÇó
url: localhost:8080/url/100
»ñÈ¡urlÀïµÄ²ÎÊý
url: localhost:8080/url?id=100
»ñÈ¡ÇëÇóÖеIJÎÊý
REST ÊÇÊôÓÚ WEB ×ÔÉíµÄÒ»Öּܹ¹·ç¸ñ£¬ÊÇÔÚ HTTP 1.1 ¹æ·¶ÏÂʵÏֵġ£Representational State Transfer È«³Æ·ÒëΪ±íÏÖ²ã״̬ת»¯¡£Resource£º×ÊÔ´¡£±ÈÈç newsfeed£»Representational£º±íÏÖÐÎʽ£¬±ÈÈçÓÃJSON£¬¸»Îı¾µÈ£»State Transfer£º×´Ì¬±ä»¯¡£Í¨¹ýHTTP ¶¯×÷ʵÏÖ¡£
Îå¸ö¹Ø¼üÒªËØ:
×ÊÔ´£¨Resource£©
×ÊÔ´µÄ±íÊö£¨Representation£©
״̬תÒÆ£¨State Transfer£©
ͳһ½Ó¿Ú£¨Uniform Interface£©
³¬Îı¾Çý¶¯£¨Hypertext Driven£©
6 ¸öÖ÷ÒªÌØÐÔ£º
ÃæÏò×ÊÔ´£¨Resource Oriented£©
¿ÉÑ°Ö·£¨Addressability£©
Á¬Í¨ÐÔ£¨Connectedness£©
ÎÞ״̬£¨Statelessness£©
ͳһ½Ó¿Ú£¨Uniform Interface£©
³¬Îı¾Çý¶¯£¨Hypertext Driven£©
@RequestMapping
´¦ÀíÇëÇóµØÖ·
method ¨C Ö¸¶¨ÇëÇóµÄ·½·¨ÀàÐÍ£ºPOST/GET/DELETE/PUT µÈ
value ¨C Ö¸¶¨Êµ¼ÊµÄÇëÇóµØÖ·
consumes ¨C Ö¸¶¨´¦ÀíÇëÇóµÄÌá½»ÄÚÈÝÀàÐÍ£¬ÀýÈç Content-Type Í·²¿ÉèÖÃapplication/json, text/html
produces ¨C Ö¸¶¨·µ»ØµÄÄÚÈÝÀàÐÍ
@PathVariable »ñÈ¡urlÓ³Éä Äõ½ÇëÇóµÄ²ÎÊýµ½·½·¨
@RequestBody ÓÃÀ´¶ÁÈ¡ÇëÇóÌåbodyÖеÄÊý¾Ý ͨ¹ýhttpMessageConverter ½âÎö°ó¶¨µ½¶ÔÏóÖÐ
GET ÇëÇó»ñÈ¡Request-URIËù±êʶµÄ×ÊÔ´
POST ÔÚRequest-URIËù±êʶµÄ×ÊÔ´ºó¸½¼ÓеÄÊý¾Ý
HEAD ÇëÇó»ñÈ¡ÓÉRequest-URIËù±êʶµÄ×ÊÔ´µÄÏìÓ¦ÏûÏ¢±¨Í·
PUT ÇëÇó·þÎñÆ÷´æ´¢Ò»¸ö×ÊÔ´£¬²¢ÓÃRequest-URI×÷ΪÆä±êʶ
DELETE ÇëÇó·þÎñÆ÷ɾ³ýRequest-URIËù±êʶµÄ×ÊÔ´
TRACE ÇëÇó·þÎñÆ÷»ØËÍÊÕµ½µÄÇëÇóÐÅÏ¢£¬Ö÷ÒªÓÃÓÚ²âÊÔ»òÕï¶Ï
CONNECT ±£Áô½«À´Ê¹ÓÃ
OPTIONS ÇëÇó²éѯ·þÎñÆ÷µÄÐÔÄÜ£¬»òÕß²éѯÓë×ÊÔ´Ïà¹ØµÄÑ¡ÏîºÍÐèÇó
ΪÕý³£Ê¹ÓÃÀ´±ØÁ¦ÆÀÂÛ¹¦ÄÜÇ뼤»îJavaScript
¡¡