JSON

spring boot ѧϰ±Ê¼Ç

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-09-19 12:23 ÎÒÒªÆÀÂÛ( )

spring boot ´´½¨·½Ê½ ´´½¨springÆô¶¯ÏîÄ¿ ÉèÖÃurl£ºhttps://start.spring.io ÔÚhttps://start.spring.io ÍøÕ¾´´½¨mavenÏîÄ¿µ¼Èë mavenÐ޸ĹúÄÚ¾µÏñ spring boot Æô¶¯·½Ê½ Ö±½ÓÔÚÏîÄ¿ÖÐÔËÐÐapplication ͨ¹ýmavenÆô¶¯ mvn - spring-boot:run jarÎļþÔËÐÐÏîÄ¿

spring boot ´´½¨·½Ê½

  • ´´½¨springÆô¶¯ÏîÄ¿ ÉèÖÃurl£ºhttps://start.spring.io
  • ÔÚhttps://start.spring.io ÍøÕ¾´´½¨mavenÏîÄ¿µ¼Èë
  • mavenÐ޸ĹúÄÚ¾µÏñ
  • spring boot Æô¶¯·½Ê½
  • Ö±½ÓÔÚÏîÄ¿ÖÐÔËÐÐapplication
  • ͨ¹ýmavenÆô¶¯ mvn - spring-boot:run
  • jarÎļþÔËÐÐÏîÄ¿
  • ʹÓÃmav install±àÒë
  • ÔÚtargetÎļþ¼ÐÕÒµ½±àÒëµÄjar°ü java -jar xxxx.jar
  • spring boot ÅäÖÃÎļþ
  • application.properties
  • ÅäÖ÷½Ê½£º

    server.context-path= xxx

  • application.yml
  • ÅäÖ÷½Ê½£º

    ×¢ÒâÊôÐÔֵðºÅºóÃæÒª¼ÓÒ»¸ö¿Õ¸ñ

    ÅäÖÃÎļþµÄ¿Ó£º

    application.properties ÅäÖÃÖÐÎÄÖµµÄʱºò£¬¶ÁÈ¡³öÀ´µÄÊôÐÔÖµ»á³öÏÖÂÒÂëÎÊÌâ¡£µ«ÊÇ application.yml ²»»á³öÏÖÂÒÂëÎÊÌâ¡£Ô­ÒòÊÇ£¬Spring Boot ÊÇÒÔ iso-8859 µÄ±àÂ뷽ʽ¶ÁÈ¡ application.properties ÅäÖÃÎļþ¡£

    spring boot »ñÈ¡ÅäÖÃÎļþÊôÐÔ
  • ÊôÐÔ×¢Èë
  • ÊôÐÔ¶ÔÏóÓ³Éä
    ´´½¨ºÍÅäÖöÔÓ¦µÄ¶ÔÏó
  • controllerµÄʹÓÃ
  • @RestController
    @Controller+@responseBody×éºÏ×¢½â
    ·µ»ØjsonÊý¾Ý
  • @Controller
    À¹½ØÇëÇó
  • @RequestMapping(value=¡±/url¡±,method=¡±get/post¡±)
  • ´¦ÀíurlÀïµÄ²ÎÊý
  • @PathVariable
    url: localhost:8080/url/100
    »ñÈ¡urlÀïµÄ²ÎÊý
  • @RequestParam
    url: localhost:8080/url?id=100
    »ñÈ¡ÇëÇóÖеIJÎÊý
  • @GetMapping
  • sprinboot-restful
  • ʲôÊÇrestful
    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 ½âÎö°ó¶¨µ½¶ÔÏóÖÐ

    http ²¹³ä

    GET ÇëÇó»ñÈ¡Request-URIËù±êʶµÄ×ÊÔ´

    POST ÔÚRequest-URIËù±êʶµÄ×ÊÔ´ºó¸½¼ÓеÄÊý¾Ý

    HEAD ÇëÇó»ñÈ¡ÓÉRequest-URIËù±êʶµÄ×ÊÔ´µÄÏìÓ¦ÏûÏ¢±¨Í·

    PUT ÇëÇó·þÎñÆ÷´æ´¢Ò»¸ö×ÊÔ´£¬²¢ÓÃRequest-URI×÷ΪÆä±êʶ

    DELETE ÇëÇó·þÎñÆ÷ɾ³ýRequest-URIËù±êʶµÄ×ÊÔ´

    TRACE ÇëÇó·þÎñÆ÷»ØËÍÊÕµ½µÄÇëÇóÐÅÏ¢£¬Ö÷ÒªÓÃÓÚ²âÊÔ»òÕï¶Ï

    CONNECT ±£Áô½«À´Ê¹ÓÃ

    OPTIONS ÇëÇó²éѯ·þÎñÆ÷µÄÐÔÄÜ£¬»òÕß²éѯÓë×ÊÔ´Ïà¹ØµÄÑ¡ÏîºÍÐèÇó

    ΪÕý³£Ê¹ÓÃÀ´±ØÁ¦ÆÀÂÛ¹¦ÄÜÇ뼤»îJavaScript

    ¡¡

    1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

    Ïà¹ØÎÄÕÂ
    • litjsonµÄÉú³ÉºÍ½âÎö

      litjsonµÄÉú³ÉºÍ½âÎö

      2017-09-17 18:03

    • ³¬Ïêϸ Spring @RequestMapping ×¢½âʹÓü¼ÇÉ

      ³¬Ïêϸ Spring @RequestMapping ×¢½âʹÓü¼ÇÉ

      2017-09-17 08:00

    • MDN JSѧϰ֮json

      MDN JSѧϰ֮json

      2017-09-16 13:02

    • FastXML Jackson / JSON ѧϰ¼Ç¼

      FastXML Jackson / JSON ѧϰ¼Ç¼

      2017-09-15 14:23

    ÍøÓѵãÆÀ
    ´