{"id":303277,"date":"2020-05-09T09:00:14","date_gmt":"2020-05-09T09:00:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=303277"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=303277","title":{"rendered":"Spring MVC: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u043e\u0432 \u0438 RESTful \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/500572\/\">\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Spring MVC \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u043e\u0432 \u0438\u043b\u0438 RESTful \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u0437\u043e\u0440 \u0447\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u043e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 Spring MVC.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0421\u0442\u0430\u0442\u044c\u044f ~ 7500 \u0441\u043b\u043e\u0432, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0435 \u043d\u0430 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435. \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0435\u0435 \u0432 \u0437\u0430\u043a\u043b\u0430\u0434\u043a\u0438 \u0438 \u0432\u0435\u0440\u043d\u0438\u0442\u0435\u0441\u044c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"soderzhanie\">\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"#t1\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <\/a><\/li>\n<li><a href=\"#t2\">HttpServlets 101 <\/a><\/li>\n<li><a href=\"#t3\">DispatcherServlet <\/a><\/li>\n<li><a href=\"#t4\">\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 HTML<\/a><\/li>\n<li><a href=\"#t5\">REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 XML \/ JSON<\/a><\/li>\n<li><a href=\"#t6\">\u0427\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b <\/a><\/li>\n<li><a href=\"#t7\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/li>\n<li><a href=\"#t8\">\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u0438<\/a><a name=\"habracut\"><\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"anchort1anchor-vvedenie\"><a name=\"t1\"><\/a> \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<h3 id=\"chto-takoe-spring-mvc\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Spring MVC?<\/h3>\n<p>  <\/p>\n<p>Spring MVC \u2014 \u044d\u0442\u043e \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Spring. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u044b \u0438\u043b\u0438 RESTful \u0441\u0435\u0440\u0432\u0438\u0441\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, JSON\/XML) \u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443 Spring, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0438 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0432 \u0432\u0430\u0448\u0438\u0445 Spring Boot \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043c\u043e\u0433\u043b\u043e, \u043d\u0435 \u0442\u0430\u043a \u043b\u0438?<\/p>\n<p>  <\/p>\n<p><strong>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0435\u0441\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442<\/strong>: \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>(\u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u0437\u043d\u0430\u0435\u0442\u0435 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Spring \u0438\u043b\u0438 Spring Boot, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c, <a href=\"https:\/\/habr.com\/ru\/post\/490586\/\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Spring Framework?<\/a>)<\/p>\n<p>  <\/p>\n<h2 id=\"anchort2anchor-httpservlets-101\"><a name=\"t2\"><\/a> HttpServlets 101<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Spring \u0438\u043b\u0438 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e (MVC\/Boot) \u0432\u044b \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0438\u043c\u0435\u0435\u0442\u0435 \u0432 \u0432\u0438\u0434\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p>  <\/p>\n<ol>\n<li><strong>HTML<\/strong> \u2192 \u0412\u0430\u0448\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435.<\/li>\n<li><strong>JSON\/XML<\/strong> \u2192 \u0412\u0430\u0448\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0435\u0440\u0432\u0438\u0441\u044b RESTful, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 JSON \u0438\u043b\u0438 XML. \u0421\u0430\u0439\u0442\u044b \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c Javascript \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u044d\u0442\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b.<\/li>\n<li>\u0414\u0430, \u0435\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u043f\u043e\u043a\u0430 \u043c\u044b \u0438\u0445 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0431\u044b \u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <strong>\u0431\u0435\u0437<\/strong> \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432? \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 Java?<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u043d\u0438\u0437\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 Java \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 <strong>HttpServlets<\/strong>. \u041e\u043d\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0432\u0430\u0448 HTML, JSON \u0438\u043b\u0438 XML. \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0438\u0437 1 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u043d\u0430 Java (Spring MVC, Wicket, Struts) \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 HttpServlets.<\/p>\n<p>  <\/p>\n<p>(<u>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u0438\u0434\u0438\u0440<\/u>: \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0431\u0435\u0437 HttpServlets, \u043d\u043e \u043c\u044b \u043f\u043e\u043a\u0430 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u043e.)<\/p>\n<p>  <\/p>\n<h3 id=\"sozdanie-html-stranic-s-pomoschyu-httpservlets\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e HttpServlets<\/h3>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u0443\u043f\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 HttpServlet, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;  public class MyServletV1 extends HttpServlet {      @Override     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {         if (req.getRequestURI().equals(&quot;\/&quot;)) {             resp.setContentType(&quot;text\/html&quot;);             resp.getWriter().print(&quot;&lt;html&gt;&lt;head&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;Welcome!&lt;\/h1&gt;&lt;p&gt;This is a very cool page!&lt;\/p&gt;&lt;\/body&gt;&lt;\/html&gt;&quot;);         }         else {             throw new IllegalStateException(&quot;Help, I don't know what to do with this url&quot;);         }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class MyServletV1 extends HttpServlet {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u0448 \u0441\u0435\u0440\u0432\u043b\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 Java HttpServlet.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (\u043b\u044e\u0431\u043e\u0439) \u0437\u0430\u043f\u0440\u043e\u0441 GET, \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 doGet () \u0438\u0437 \u0441\u0443\u043f\u0435\u0440\u043a\u043b\u0430\u0441\u0441\u0430. \u0414\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 POST \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c doPost (). \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 HTTP \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">if (req.getRequestURI().equals(&quot;\/&quot;)) {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u0448 \u0441\u0435\u0440\u0432\u043b\u0435\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 URL-\u0430\u0434\u0440\u0435\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c. \u041f\u043e\u043a\u0430 \u0441\u0435\u0440\u0432\u043b\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u00ab\/\u00bb, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 www.marcobehler.com, \u043d\u043e \u041d\u0415 www.marcobehler.com\/hello.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">resp.setContentType(&quot;text\/html&quot;);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0432 ServletResponse, \u0447\u0442\u043e\u0431\u044b \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0437\u043d\u0430\u043b, \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0432\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0435. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e HTML.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">resp.getWriter().print(&quot;&lt;html&gt;&lt;head&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;Welcome!&lt;\/h1&gt;&lt;p&gt;This is a very cool page!&lt;\/p&gt;&lt;\/body&gt;&lt;\/html&gt;&quot;);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u043d\u0438\u0442\u0435: \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0438 HTML! \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c HTML-\u0441\u0442\u0440\u043e\u043a\u0443 \u043b\u044e\u0431\u044b\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0432\u0430\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0435\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ServletResponse. \u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e response writer.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u043e\u0432, \u0442\u0430\u043a\u043e\u043c \u043a\u0430\u043a Tomcat \u0438\u043b\u0438 Jetty. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430, \u0432\u0435\u0441\u044c \u043a\u043e\u0434, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; import org.apache.catalina.Wrapper; import org.apache.catalina.startup.Tomcat;  public class TomcatApplicationLauncher {      public static void main(String[] args) throws LifecycleException {         Tomcat tomcat = new Tomcat();         tomcat.setPort(8080);         tomcat.getConnector();          Context ctx = tomcat.addContext(&quot;&quot;, null);         Wrapper servlet = Tomcat.addServlet(ctx, &quot;myServlet&quot;, new MyServletV2());         servlet.setLoadOnStartup(1);         servlet.addMapping(&quot;\/*&quot;);          tomcat.start();     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); tomcat.getConnector();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 Tomcat, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u043f\u043e\u0440\u0442 8080.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">        Context ctx = tomcat.addContext(&quot;&quot;, null);         Wrapper servlet = Tomcat.addServlet(ctx, &quot;myServlet&quot;, new MyServletV2());<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u0432\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0435 \u0441\u0432\u043e\u0439 \u0441\u0435\u0440\u0432\u043b\u0435\u0442 \u0432 Tomcat. \u042d\u0442\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c, \u0433\u0434\u0435 \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442\u0435 Tomcat \u043e \u0441\u0432\u043e\u0435\u043c \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">        servlet.addMapping(&quot;\/*&quot;);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 Tomcat, \u0437\u0430 \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u0435\u0440\u0432\u043b\u0435\u0442, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \/* \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043b\u044e\u0431\u043e\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 (\/users, \/register, \/checkout).<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">        tomcat.start();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 main(), \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u0435 \u043d\u0430 \u043f\u043e\u0440\u0442 8080 \u0432 \u0441\u0432\u043e\u0435\u043c \u043b\u044e\u0431\u0438\u043c\u043e\u043c \u0432\u0435\u0431-\u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 (<a href=\"http:\/\/localhost:8080\" rel=\"nofollow\">http:\/\/localhost:8080<\/a> \/), \u0438 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 HTML.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e \u0441\u0443\u0442\u0438, \u043f\u043e\u043a\u0430 \u0432\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b doGet () \u0438 doPost (), \u0432\u0441\u0435 \u0432\u0430\u0448\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u044d\u0442\u043e.<\/p>\n<p>  <\/p>\n<h3 id=\"sozdanie-json-s-pomoschyu-httpservlets\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 JSON \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e HttpServlets<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435, \u0447\u0442\u043e \u043f\u043e\u043c\u0438\u043c\u043e \u0432\u0430\u0448\u0435\u0439 (\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0443\u0441\u0442\u043e\u0439) HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u0430\u043a\u0436\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c REST API \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u0433\u043e\u0442\u043e\u0432\u044f\u0449\u0435\u0433\u043e\u0441\u044f \u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0422\u0430\u043a \u0447\u0442\u043e \u0432\u0430\u0448 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 React \u0438\u043b\u0438 AngularJS \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c URL-\u0430\u0434\u0440\u0435\u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/api\/users\/{userId}<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c userId. \u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0448 MyServlet \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043e\u043f\u044f\u0442\u044c \u0436\u0435, \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432?<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;  public class MyServletV2 extends HttpServlet {      @Override     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {         if (req.getRequestURI().equals(&quot;\/&quot;)) {             resp.setContentType(&quot;text\/html&quot;);             resp.getWriter().print(&quot;&lt;html&gt;&lt;head&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;Welcome!&lt;\/h1&gt;&lt;p&gt;This is a very cool page!&lt;\/p&gt;&lt;\/body&gt;&lt;\/html&gt;&quot;);         } else if (req.getRequestURI().startsWith(&quot;\/api\/users\/&quot;)) {              Integer prettyFragileUserId = Integer.valueOf(req.getRequestURI().lastIndexOf(&quot;\/&quot;) + 1);              resp.setContentType(&quot;application\/json&quot;);              \/\/ User user = dao.findUser(prettyFragileUserId)             \/\/ actually: jsonLibrary.toString(user)             resp.getWriter().print(&quot;{\\n&quot; +                     &quot;  \\&quot;id\\&quot;:&quot; + prettyFragileUserId + &quot;,\\n&quot; +                     &quot;  \\&quot;age\\&quot;: 55,\\n&quot; +                     &quot;  \\&quot;name\\&quot; : \\&quot;John Doe\\&quot;\\n&quot; +                     &quot;}&quot;);         } else {             throw new IllegalStateException(&quot;Help, I don't know what to do with this url&quot;);         }     } } <\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">        } else if (req.getRequestURI().startsWith(&quot;\/api\/users\/&quot;)) {<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d if \u0432 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 doGet \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \/api\/users\/.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">  Integer prettyFragileUserId = Integer.valueOf(req.getRequestURI().lastIndexOf(&quot;\/&quot;) + 1);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0434\u0435\u043b\u0430\u0435\u043c <strong><em>\u043e\u0447\u0435\u043d\u044c<\/em><\/strong> \u0441\u043b\u0430\u0431\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 URL. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0447\u0430\u0441\u0442\u044c URL \u2014 \u044d\u0442\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f userID, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 5 \u0434\u043b\u044f \/api\/users\/5. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 int, \u0447\u0442\u043e \u043d\u0430\u043c \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c!<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">resp.setContentType(&quot;application\/json&quot;);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c JSON \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">\/\/ User user = dao.findUser(prettyFragileUserId) \/\/ actually: jsonLibrary.toString(user) resp.getWriter().print(&quot;{\\n&quot; +         &quot;  \\&quot;id\\&quot;:&quot; + prettyFragileUserId + &quot;,\\n&quot; +         &quot;  \\&quot;age\\&quot;: 55,\\n&quot; +         &quot;  \\&quot;name\\&quot; : \\&quot;John Doe\\&quot;\\n&quot; +         &quot;}&quot;);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u044f\u0442\u044c \u0436\u0435, JSON \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0435\u043a\u0441\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 HTTPServletResponse. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043c\u044b \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 JSON \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e Java-\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443, \u043d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0437\u0434\u0435\u0441\u044c.<\/p>\n<p>  <\/p>\n<h3 id=\"problema-s-nashim-podhodom-odin-servlet-dlya-vsego\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u043d\u0430\u0448\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u00ab\u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u043b\u0435\u0442 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e\u00bb<\/h3>\n<p>  <\/p>\n<p>\u0425\u043e\u0442\u044f \u043d\u0430\u0448 \u0441\u0435\u0440\u0432\u043b\u0435\u0442 \u0432\u044b\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u0430 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0435 \u0432\u0430\u0441 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043d\u0435\u043c\u0430\u043b\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0412\u0430\u0448 \u0441\u0435\u0440\u0432\u043b\u0435\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0443\u0447\u043d\u044b\u0445 HTTP-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c URI \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0442.\u0434. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c <strong>\u0427\u0422\u041e<\/strong> \u0445\u043e\u0442\u044f\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438.<\/li>\n<li>\u0417\u0430\u0442\u0435\u043c \u043e\u043d \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0439\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, <strong>\u041a\u0410\u041a<\/strong>. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0438\u0441\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0437\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438.<\/li>\n<li>\u0417\u0430\u0442\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 JSON \u0438\u043b\u0438 HTML \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043e\u0431\u044f\u0437\u0430\u043d\u043d\u043e\u0441\u0442\u0435\u0439, \u043d\u0435 \u0442\u0430\u043a \u043b\u0438? \u0420\u0430\u0437\u0432\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u043b\u0443\u0447\u0448\u0435, \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e\u0431\u043e \u0432\u0441\u0435\u043c \u044d\u0442\u043e\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u043a\u043e\u0434\u0435? \u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 URI \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043d\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 JSON, \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430?<\/p>\n<p>  <\/p>\n<p><strong>\u0418\u043c\u0435\u043d\u043d\u043e<\/strong> \u0437\u0434\u0435\u0441\u044c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 <a href=\"https:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/web.html\" rel=\"nofollow\">Spring MVC<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"anchort3anchor-dispatcherservlet\"><a name=\"t3\"><\/a> DispatcherServlet<\/h2>\n<p>  <\/p>\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043e Spring MVC \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e \u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 Model-View-Controller. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0440\u0430\u0437\u043d\u0438\u043c \u0432\u0430\u0441.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u044f \u0441\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u0447\u0442\u043e Spring MVC \u2014 \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u043b\u0435\u0442, \u043a\u0430\u043a \u043d\u0430\u0448 \u0432\u044b\u0448\u0435 \u0441\u0443\u043f\u0435\u0440-\u0441\u0435\u0440\u0432\u043b\u0435\u0442?<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0442\u0440\u0435\u0447\u0430\u0439\u0442\u0435 <strong>DispatcherServlet<\/strong>.<\/p>\n<p>  <\/p>\n<p>(\u041e \u0434\u0430, \u0432 \u044d\u0442\u043e\u043c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u043c\u0430\u043d\u0430)<\/p>\n<p>  <\/p>\n<h3 id=\"chto-delaet-spring-mvc-dispatcherservlet\">\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 Spring MVC DispatcherServlet?<\/h3>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 Java \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 Spring MVC \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u0435\u043d \u0441\u0435\u0440\u0432\u043b\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441 (\u043f\u043e\u044d\u0442\u043e\u043c\u0443 DispatcherServlet \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <em>\u0444\u0440\u043e\u043d\u0442-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c<\/em>).<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0436\u0435 \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 <strong><em>\u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c<\/em><\/strong> HTTP-\u0437\u0430\u043f\u0440\u043e\u0441, \u0442\u043e\u0447\u043d\u043e? \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u00ab\u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u00bb, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0444\u043e\u0440\u043c\u0443 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e HTML \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0430\u0448 DispatcherServlet \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c URI \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 HTTP \u0438 \u043b\u044e\u0431\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: POST \/register?name=john&amp;age33.<\/li>\n<li>\u041e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b\/\u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430) \u0432 \u0441\u0438\u043c\u043f\u0430\u0442\u0438\u0447\u043d\u044b\u0435 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Java \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0432 \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043b\u0438 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440,, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 <strong>\u0432\u044b<\/strong> \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438.<\/li>\n<li>\u0412\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0438\u0441\u044c\u043c\u043e \u0438 \u0442.\u0434. \u041e\u043d, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043a\u0430 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<\/li>\n<li>\u041e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0437\u044f\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0432\u044b\u0432\u043e\u0434 \u0438\u0437 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 HTML\/JSON\/XML.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0412\u0435\u0441\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0440\u0435\u043d\u0435\u0431\u0440\u0435\u0436\u0435\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e DispatcherServlet \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0430\u043c.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/cd\/3n\/fk\/cd3nfkgh_84hwdxm56uoy9bpgbq.png\"><\/p>\n<p>  <\/p>\n<p>\u0414\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u043b\u044b\u0432\u0447\u0430\u0442\u043e \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 ModelAndView \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0432\u044b\u0448\u0435? \u041a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e DispatcherServlet \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435?<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 Let&#8217;s-write-HTML? \u041e\u0431 \u044d\u0442\u043e\u043c \u0443\u0437\u043d\u0430\u0435\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"anchort4anchor-kontrollery--sozdanie-html\"><a name=\"t4\"><\/a> \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 HTML<\/h2>\n<p>  <\/p>\n<p>\u0412\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c HTML \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435, \u0442\u0430\u043a\u043e\u043c \u043a\u0430\u043a \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0441 Spring MVC (\u0432\u043a\u043b\u044e\u0447\u0430\u044f Spring Boot), \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441.<\/p>\n<p>  <\/p>\n<h3 id=\"kak-napisat-kontroller-v-spring\">\u041a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0432 Spring<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432\u044b\u0448\u0435 (POST\/register?name=john&amp;age33) \u043c\u044b \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam;  @Controller public class RegistrationController {      @PostMapping(&quot;\/register&quot;)     public String registerUser(@RequestParam(required = false) Integer age, @RequestParam String name, Model model) {         User user = new User(name, age);          \/\/ TODO save user to database         \/\/ userDao.save(user);          \/\/ TODO send out registration email         \/\/ mailService.sendRegistrationEmail(user);          model.addAttribute(&quot;user&quot;, user);         return &quot;registration-success&quot;;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Controller public class RegistrationController {<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 Spring \u043f\u0440\u043e\u0441\u0442\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <strong><a href=\"https:\/\/habr.com\/ru\/users\/controller\/\" class=\"user_link\">Controller<\/a><\/strong>, \u0435\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u043b\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c\u0441\u044f \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@PostMapping(&quot;\/register&quot;)<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043d\u0430\u0448\u0435\u043c\u0443 DispatcherServlet, \u0447\u0442\u043e \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 POST \u0434\u043b\u044f \u043f\u0443\u0442\u0438 <strong><em>\/register<\/em><\/strong>, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043b\u044e\u0431\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, ?Username=), \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    public String registerUser(@RequestParam(required = false) Integer age, @RequestParam String name, Model model) {<\/code><\/pre>\n<p>  <\/p>\n<p><em><u>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/u><\/em> \u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e.<br \/>  \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e \u0447\u0430\u0441\u0442\u044c\u044e URL (?age=10&amp;name=Joe), \u043b\u0438\u0431\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 POST. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>name<\/strong> (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>age<\/strong> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c)<\/p>\n<p>  <\/p>\n<p>\u0418 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>age<\/strong>, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0435\u0433\u043e, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Integer (\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0434\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c Integer)<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0447\u0442\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u0430\u0436\u043d\u043e, Spring MVC \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043d\u0435\u0434\u0440\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>model<\/strong> \u0432 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u042d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043a\u0430\u0440\u0442\u0443, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043d\u0430 \u0432\u0430\u0448\u0435\u0439 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435, \u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">User user = new User(name, age);  \/\/ TODO save user to database \/\/ userDao.save(user);  \/\/ TODO send out registration email \/\/ mailService.sendRegistrationEmail(user);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0432\u0441\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u0435. \u042d\u0442\u043e \u0432\u0430\u0448\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">model.addAttribute(&quot;user&quot;, user);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043a\u043b\u044e\u0447\u043e\u043c \u00abuser\u00bb. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u0433\u043e \u0432 \u0441\u0432\u043e\u0435\u043c HTML-\u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u043f\u043e\u0437\u0436\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u00ab${user.name}\u00bb. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u043a\u0443\u043d\u0434\u0443.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">return &quot;registration-success&quot;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <strong>registration-success<\/strong>. \u042d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430, \u044d\u0442\u043e \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0432\u0430\u0448\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0442.\u0435. \u0448\u0430\u0431\u043b\u043e\u043d HTML, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b Spring \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b.<\/p>\n<p>  <\/p>\n<h3 id=\"views-predstavleniya\">Views (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f)<\/h3>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043a\u0430 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a (\u0438\u043b\u0438, \u0441\u043a\u043e\u0440\u0435\u0435, \u0433\u0434\u0435) Spring MVC \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0442.\u0435. \u0432\u0430\u0448 \u0448\u0430\u0431\u043b\u043e\u043d, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u0430\u0448 \u0448\u0430\u0431\u043b\u043e\u043d <strong>registration-success.html<\/strong>.<\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt;     &lt;meta charset=&quot;UTF-8&quot;&gt;     &lt;title&gt;Title&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt;  &lt;p th:text=&quot;'Hello ' + ${user.name} + '!'&quot;&gt;&lt;\/p&gt;  &lt;\/body&gt; &lt;\/html&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 <em>\u0448\u0430\u0431\u043b\u043e\u043d\u0430<\/em>. \u041e\u043d \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;p th:text=&quot;'Hello ' + ${user.name} + '!'&quot;&gt;&lt;\/p&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 th:text=? \u041e\u043d \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0434\u043b\u044f Spring? \u0418\u043b\u0438 \u044d\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0435?<\/p>\n<p>  <\/p>\n<p>\u0418 \u043e\u0442\u0432\u0435\u0442 \u0442\u0430\u043a\u043e\u0432: Spring MVC \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445 HTML. \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 HTML-\u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044f\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432\u044b \u0432\u044b\u0431\u0435\u0440\u0435\u0442\u0435.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u0448\u0430\u0431\u043b\u043e\u043d <a href=\"https:\/\/www.thymeleaf.org\/\" rel=\"nofollow\">Thymeleaf<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u0435\u043d \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438 Spring MVC.<\/p>\n<p>  <\/p>\n<h3 id=\"spring-mvc-i-biblioteki-shablonov\">Spring MVC \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432<\/h3>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441 Spring MVC, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c: <a href=\"https:\/\/www.thymeleaf.org\/\" rel=\"nofollow\">Thymeleaf<\/a>, <a href=\"https:\/\/velocity.apache.org\/\" rel=\"nofollow\">Velocity<\/a>, <a href=\"https:\/\/freemarker.apache.org\/\" rel=\"nofollow\">Freemarker<\/a>, <a href=\"https:\/\/mustache.github.io\/\" rel=\"nofollow\">Mustache<\/a> \u0438 \u0434\u0430\u0436\u0435 <a href=\"https:\/\/en.wikipedia.org\/wiki\/JavaServer_Pages\" rel=\"nofollow\">JSP<\/a> (\u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043d\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432).<\/p>\n<p>  <\/p>\n<p>\u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0432\u044b <strong>\u0434\u043e\u043b\u0436\u043d\u044b<\/strong> \u044f\u0432\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0432 \u0432\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0442\u043e \u0432\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0432\u0430\u0448\u0443 HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u2014 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. <\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0441\u0435 \u043e\u043d\u0438 <strong><em>\u043d\u0435\u043c\u043d\u043e\u0433\u043e<\/em><\/strong> \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430. \u0412\u0435\u0441\u0435\u043b\u043e, \u043f\u0440\u0430\u0432\u0434\u0430?<\/p>\n<p>  <\/p>\n<h3 id=\"chto-takoe-viewresolver\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 ViewResolver?<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u0443\u043c\u0430\u0435\u043c, \u0433\u0434\u0435 Spring \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0432\u0430\u0448\u0438 HTML-\u0448\u0430\u0431\u043b\u043e\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440.<\/p>\n<p>  <\/p>\n<p>\u041a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f <em>\u043d\u0430\u0439\u0442\u0438<\/em> \u0432\u0430\u0448 \u0448\u0430\u0431\u043b\u043e\u043d, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>ViewResolver<\/strong>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432 \u0432\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, Spring \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 ViewResolvers \u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u0438\u0445, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0448\u0430\u0431\u043b\u043e\u043d \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 ViewResolvers, \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 Thymeleaf. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0430\u043c \u043d\u0443\u0436\u0435\u043d ThymeleafViewResolver.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.context.annotation.Bean; import org.thymeleaf.spring5.SpringTemplateEngine; import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver; import org.thymeleaf.spring5.view.ThymeleafViewResolver;  public class ThymeleafConfig {      @Bean     public ThymeleafViewResolver viewResolver() {         ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();          SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();         templateResolver.setPrefix(&quot;classpath:\/templates&quot;);         templateResolver.setSuffix(&quot;.html&quot;);         \/\/ some other lines neglected...          SpringTemplateEngine templateEngine = new SpringTemplateEngine();         templateEngine.setTemplateResolver(templateResolver);         \/\/ some other lines neglected...          viewResolver.setTemplateEngine(templateEngine);         return viewResolver;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    @Bean     public ThymeleafViewResolver viewResolver() {         ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, ThymeleafViewResolver \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Spring <strong>ViewResolver<\/strong>. \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0438\u043c\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430 (\u043f\u043e\u043c\u043d\u0438\u0442\u0435: <strong>registration-success<\/strong>), ViewResolvers \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0448\u0430\u0431\u043b\u043e\u043d.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">        SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b ThymeleafViewResolver \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0445 \u0434\u043b\u044f Thymeleaf \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <strong>SpringResourceTemplateResolver<\/strong>. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043f\u043e\u0438\u0441\u043a\u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430.<\/p>\n<p>  <\/p>\n<p><em><u>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/u><\/em> SpringResourceTemplateResolver \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u043c Thymeleaf<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">templateResolver.setPrefix(&quot;classpath:\/templates&quot;); templateResolver.setSuffix(&quot;.html&quot;);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443, \u0432\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0435 (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 Spring Resources): \u00ab\u0412\u0441\u0435 \u043c\u043e\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u043f\u0443\u0442\u0438 classpath, \u0432 \u043f\u0430\u043f\u043a\u0435 <strong>\/templates<\/strong>\u00bb. \u0418 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u0441\u0435 \u043e\u043d\u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 .html. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442:<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 String, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 registration-success, ThymeleafViewResolver \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d: <strong>classpath:\/templates\/registration-success.html<\/strong>.<\/p>\n<p>  <\/p>\n<h3 id=\"zametka-na-polyah-spring-boot\">\u0417\u0430\u043c\u0435\u0442\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b\u044f\u0445: Spring Boot<\/h3>\n<p>  <\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c: \u041c\u0430\u0440\u043a\u043e, <strong>\u043c\u043d\u0435 \u043d\u0438\u043a\u043e\u0433\u0434\u0430<\/strong> \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 ViewResolver, \u0440\u0430\u0431\u043e\u0442\u0430\u044f \u043d\u0430\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438 Spring Boot. \u0418 \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Spring Boot \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u0434\u043b\u044f \u0432\u0430\u0441 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u0432 \u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u043a <strong>spring-boot-starter-thymeleaf<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 ViewResolver \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b \u0432\u0430\u0448 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 src\/main\/resources\/template.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, Spring Boot \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 Spring MVC \u0434\u043b\u044f \u0432\u0430\u0441. \u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435.<\/p>\n<p>  <\/p>\n<h3 id=\"rezyume-model-view-controller\">\u0420\u0435\u0437\u044e\u043c\u0435: Model-View-Controller<\/h3>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/habr.com\/ru\/users\/controller\/\" class=\"user_link\">Controller<\/a> &amp; ViewResolver, \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 Spring <strong>M<\/strong>odel-<strong>V<\/strong>iew-<strong>C<\/strong>ontroller.<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 (<a href=\"https:\/\/habr.com\/ru\/users\/controller\/\" class=\"user_link\">Controller<\/a>, @PostMapping, @RequestParam) \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <strong>\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/li>\n<li>\u0412\u0430\u0448\u0430 <strong>\u043c\u043e\u0434\u0435\u043b\u044c<\/strong> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0438 <em>\u0442\u043e\u043b\u044c\u043a\u043e<\/em> \u0434\u0430\u043d\u043d\u044b\u0435), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \u042d\u0442\u043e \u0432\u0430\u0448\u0430 \u0440\u0430\u0431\u043e\u0442\u0430, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u043a\u0430\u0440\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u0438.<\/li>\n<li>\u0412\u0430\u0448\u0435 <strong>\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/strong> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d HTML. \u041d\u0435\u0432\u0430\u0436\u043d\u043e, \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u044b \u0432\u0437\u044f\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043c\u043e\u0434\u0435\u043b\u0438). \u0418\u043b\u0438 \u043a\u0430\u043a\u043e\u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441. \u0418\u043b\u0438 \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 HTTP-\u0441\u0435\u0430\u043d\u0441 \u0438\u043b\u0438 \u043d\u0435\u0442.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u0441\u0435 \u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438, \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 Spring \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435, \u0441 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u043d\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 HTTP, \u0447\u0435\u043c \u043d\u0430\u0448 \u0441\u0443\u043f\u0435\u0440-\u0441\u0435\u0440\u0432\u043b\u0435\u0442 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043d\u0430\u0447\u0430\u043b\u0430.<\/p>\n<p>  <\/p>\n<h3 id=\"podrobnee-o-kontrollerah\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445<\/h3>\n<p>  <\/p>\n<p>\u041c\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c Spring MVC \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0432\u0445\u043e\u0434\u043e\u0432 HTTP.<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0412\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f \u0441 requestURI, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e.<\/li>\n<li>\u0412\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f\u043c\u0438 \u0442\u0438\u043f\u043e\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438\u043b\u0438, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438\u043b\u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c <em>\u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435<\/em> HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>  <\/p>\n<h3 id=\"getmapping-i-requestmappping\">@GetMapping \u0438 @RequestMappping<\/h3>\n<p>  <\/p>\n<p>\u0412\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <strong>@GetMapping<\/strong> \u0432\u044b\u0448\u0435. \u041e\u043d\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>*@RequestMapping*<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@GetMapping(&quot;\/books&quot;) public void book() {         \/\/ }  \/* these two mappings are identical *\/  @RequestMapping(value = &quot;\/books&quot;, method = RequestMethod.GET) public void book2() {  }<\/code><\/pre>\n<p>  <\/p>\n<p>@GetMapping, @[Post|Put|Delete|Patch]Mapping \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e @RequestMapping(method=XXX). \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 (Spring 4.3+) \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u043f\u0438\u043d\u0433\u0430 (\u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f) \u0441 URL, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435, \u0447\u0442\u043e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f @RequestMapping \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u044b\u0445, \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 Spring.<\/p>\n<p>  <\/p>\n<h3 id=\"requestparam\">@RequestParam<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0431\u0443\u0434\u044c \u0442\u043e \u0432 \u0432\u0430\u0448\u0435\u043c URL (?Key=value) \u0438\u043b\u0438 \u0432 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u0442\u0435\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0444\u043e\u0440\u043c\u044b, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <em>@RequestParam<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0412\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438, \u0447\u0442\u043e \u043e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 HTTP String \u0432 int), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043b\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@PostMapping(&quot;\/users&quot;)   \/* First Param is optional *\/ public User createUser(@RequestParam(required = false) Integer age, @RequestParam String name) {    \/\/ does not matter }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0431\u0443\u0434\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430 <strong>400 Bad Request<\/strong> \u0438, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Spring Boot, \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"json\">{&quot;timestamp&quot;:&quot;2020-04-26T08:34:34.441+0000&quot;,&quot;status&quot;:400,&quot;error&quot;:&quot;Bad Request&quot;,&quot;message&quot;:&quot;Required Integer parameter 'age' is not present&quot;,&quot;path&quot;:&quot;\/users&quot;}<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c Spring \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 @RequestParams \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439. \u041f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0436\u0438\u0442\u0435 \u0432\u0430\u0448 <strong>\u043e\u0431\u044a\u0435\u043a\u0442<\/strong> \u043a\u0430\u043a &quot;<em>\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043c\u0435\u0442\u043e\u0434\u0430<\/em>&quot;.<\/p>\n<p>  <\/p>\n<p>\u0412\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0435\u0441\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b getter\/setter.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@PostMapping(&quot;\/users&quot;)   \/* Spring \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u044d\u0442\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c getters and setters *\/ public User createUser(UserDto userDto) {     \/\/ }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"pathvariable\">@PathVariable<\/h3>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u0438\u0445 \u0432 URI \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u0430\u043a <em>@PathVariable<\/em>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 <em>userId=123<\/em>, \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 URL: <strong>GET \/ users\/123<\/strong><\/p>\n<p>  <\/p>\n<ol>\n<li>\u0412\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043c\u0435\u0436\u0434\u0443 {} \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. <\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, <strong>PathVariables<\/strong> \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438\u043b\u0438 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@GetMapping(&quot;\/users\/{userId}&quot;)    public User getUser(@PathVariable(required = false) String userId) {        \/\/ ...        return user;    }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 PathVariables, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u044b \u0432 Java-\u043e\u0431\u044a\u0435\u043a\u0442 (\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0435\u0441\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b getter\/setter).<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@GetMapping(&quot;\/users\/{userId}&quot;) public User getUser(UserDto userDto) {     \/\/ ...     return user; }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"rezyume-kontrollery\">\u0420\u0435\u0437\u044e\u043c\u0435: \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b<\/h3>\n<p>  <\/p>\n<p>\u041a\u043e\u0440\u043e\u0447\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring MVC \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0449\u0435\u0439:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u0432\u043e\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, &quot;\u043f\u0440\u0438\u0441\u044b\u043f\u0430\u043d\u043d\u044b\u0435&quot; \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438. Spring \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u0441\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0432\u043e\u0434\u0430 (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u0443\u0442\u0438) \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/li>\n<li>\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043b\u044e\u0431\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<\/li>\n<li>\u0421\u043e\u043e\u0431\u0449\u0438\u0442\u0435 \u0432\u0430\u0448\u0435\u043c\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0443, \u043a\u0430\u043a\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d HTML \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c, \u0438 \u0432\u0435\u0440\u043d\u0438\u0442\u0435 \u0438\u043c\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438.<\/li>\n<li>\u0412\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441, Spring \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0432\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438 \u043f\u0440\u0438\u043c\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442 \u0435\u0433\u043e \u0432 HTML-\u0441\u0442\u0440\u043e\u043a\u0443 \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440.<\/li>\n<li>\u041f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0447\u0442\u043e Spring Boot \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0434\u043b\u044f \u0432\u0430\u0441, \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0432\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"anchort5anchor-rest-kontrollery---sozdanie-xmljson\"><a name=\"t5\"><\/a> REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 XML\/JSON<\/h2>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 RESTFul \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0432\u0441\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443. \u0412\u0430\u0448 \u043a\u043b\u0438\u0435\u043d\u0442, \u0431\u0443\u0434\u044c \u0442\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441, \u0431\u0443\u0434\u0435\u0442 (\u043e\u0431\u044b\u0447\u043d\u043e) \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b JSON \u0438\u043b\u0438 XML. \u041a\u043b\u0438\u0435\u043d\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442, \u0441\u043a\u0430\u0436\u0435\u043c, \u0437\u0430\u043f\u0440\u043e\u0441 JSON, \u0432\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u0435\u0433\u043e, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 JSON. <\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u043c \u044d\u0442\u043e\u0442 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 JSON \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u0442\u0435\u043b\u0430 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">POST http:\/\/localhost:8080\/users  ### {&quot;email&quot;: &quot;angela@merkel.de&quot;}<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Java (\u0432 \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 Spring MVC) \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u043c\u0435\u0442\u044c \u0434\u0435\u043b\u043e \u0441 JSON \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438. \u041d\u0438 \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u043d\u0438 \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0443. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043c\u0435\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b Java, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 Spring \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 JSON.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class UserDto {     private String email;     \/\/... }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0430\u043c <em>\u043d\u0435 \u043d\u0443\u0436\u043d\u0430<\/em> \u0432\u0441\u044f \u044d\u0442\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0435 HTML \u0432 \u0432\u0430\u0448\u0438\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445. \u0414\u043b\u044f RESTful \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0447\u0438\u0442\u0430\u044e\u0449\u0435\u0439 \u0448\u0430\u0431\u043b\u043e\u043d HTML \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u0439 \u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u0430\u0441 \u043e\u0442\u0432\u0435\u0442 JSON.<\/p>\n<p>  <\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 <strong>HTTP \u0437\u0430\u043f\u0440\u043e\u0441<\/strong> \u2192 <strong>Java \u043e\u0431\u044a\u0435\u043a\u0442<\/strong> \u0438 \u0438\u0437 <strong>Java \u043e\u0431\u044a\u0435\u043a\u0442<\/strong> \u2192 <strong>HTTP \u043e\u0442\u0432\u0435\u0442<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u044d\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e Spring MVC \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 <strong> REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/strong>.<\/p>\n<p>  <\/p>\n<h3 id=\"kak-napisat--rest-kontroller\">\u041a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/h3>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 XML\/JSON, \u044d\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @RestController \u0432\u043c\u0435\u0441\u0442\u043e <a href=\"https:\/\/habr.com\/ru\/users\/controller\/\" class=\"user_link\">Controller<\/a>. (\u0425\u043e\u0442\u044f @RestController \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/habr.com\/ru\/users\/controller\/\" class=\"user_link\">Controller<\/a>, \u0441\u043c. FAQ \u0434\u043b\u044f \u0442\u043e\u0447\u043d\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b).<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 REST-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043b\u044f \u0431\u0430\u043d\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043e\u043d \u043c\u043e\u0433 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;  import java.util.Collections; import java.util.List;  @RestController public class BankController {      @GetMapping(&quot;\/transactions\/{userId}&quot;)     public List&lt;Transaction&gt; transactions(String userId) {          \/\/ find transaction by user         \/\/ List&lt;Transaction&gt; = dao.findByUserId(userId);          List&lt;Transaction&gt; transactions = Collections.emptyList();         return transactions;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RestController public class BankController {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b \u0441\u043d\u0430\u0431\u0434\u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 BankController \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 @RestController, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 Spring, \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c HTML-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 ModelAndView. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c XML\/JSON (\u0438\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442) \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430 HTTP.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public List&lt;Transaction&gt; transactions(String userId) {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 String (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435). \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <em>List, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 Spring \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 JSON \u0438\u043b\u0438 XML. \u041f\u043e \u0441\u0443\u0442\u0438, \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u0448\u0438 Java \u043e\u0431\u044a\u0435\u043a\u0442\u044b Transaction \u0441\u0442\u0430\u043b\u0438 \u0442\u0430\u043a\u0438\u043c\u0438 (\u043a\u0442\u043e-\u0442\u043e \u0436\u0430\u0436\u0434\u0430\u043b \u0444\u0430\u0441\u0442-\u0444\u0443\u0434 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u043d\u043e \u0443\u0442\u0440\u043e\u043c):<\/em>  <\/p>\n<pre><code class=\"json\">[   {     &quot;occurred&quot;: &quot;28.04.2020 03:18&quot;,     &quot;description&quot;: &quot;McDonalds - Binging&quot;,     &quot;id&quot;: 1,     &quot;amount&quot;: 10   },   {     &quot;occurred&quot;: &quot;28.04.2020 06:18&quot;,     &quot;description&quot;: &quot;Burger King - Never enough&quot;,     &quot;id&quot;: 2,     &quot;amount&quot;: 15   } ]<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u043a\u0430\u043a Spring MVC \u0443\u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0430\u0448 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d \u0432 JSON? \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 XML? \u0418\u043b\u0438 YAML? \u041a\u0430\u043a \u0432\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u0430?<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 Spring \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f <strong>\u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430<\/strong>.<\/p>\n<p>  <\/p>\n<h3 id=\"soglasovanie-kontenta-otveta---accept-header\">\u0421\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 \u2014 Accept Header<\/h3>\n<p>  <\/p>\n<p>\u041a\u043e\u0440\u043e\u0447\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u0432\u0430\u0448\u0435\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043a\u0430\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u043d \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a? \u0423\u043a\u0430\u0437\u0430\u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a Accept \u0432 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">GET http:\/\/localhost:8080\/transactions\/{userid} Accept: application\/json<\/code><\/pre>\n<p>  <\/p>\n<p>Spring MVC \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u0442 \u044d\u0442\u043e\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a Accept \u0438 \u0443\u0437\u043d\u0430\u0435\u0442: \u043a\u043b\u0438\u0435\u043d\u0442 \u0445\u043e\u0447\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c JSON (application\/json), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0439 <em>List \u0432 JSON. (\u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e, \u043d\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a Accept \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.)<\/em>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u044d\u0442\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u0430 HTTP, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a.<\/p>\n<p>  <\/p>\n<h3 id=\"soglasovanie-kontenta--zaprosa---content-type-header-zagolovok-tipa-kontenta\">\u0421\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 Content-Type Header (\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0442\u0438\u043f\u0430 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430)<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 RESTful API \u043e\u0447\u0435\u043d\u044c \u0432\u044b\u0441\u043e\u043a\u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u0430\u0448\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0442\u0430\u043a\u0436\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON \u0438\u043b\u0438 XML. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u043e\u0432\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u043d\u0430\u0447\u0430\u043b\u0430 \u0433\u043b\u0430\u0432\u044b, \u0433\u0434\u0435 \u0432\u044b \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 REST \u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">POST http:\/\/localhost:8080\/users  ### {&quot;email&quot;: &quot;angela@merkel.de&quot;}<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a Spring \u0443\u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b\u0448\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 JSON, \u0430 \u043d\u0435 XML \u0438\u043b\u0438 YAML? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044d\u0442\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <strong>Content-Type<\/strong>.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">POST ...  Content-Type: application\/json; charset=UTF-8  ### ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430?<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController;  @RestController public class BookingController {      @PostMapping(&quot;\/transactions&quot;)     public Transaction transaction(@RequestBody TransactionDto dto) {         \/\/ do something with the dto..create the booking..convert it to a transaction         Transaction transaction = null;         return transaction;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    public Transaction transaction(@RequestBody TransactionDto dto) {<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u043e @RequestParam \u0438\u043b\u0438 @Pathvariable, \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0430\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f <em>@RequestBody<\/em>. <\/p>\n<p>  <\/p>\n<p>@RequestBody \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c <strong>Content-Type<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c Spring \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0435\u043b\u043e HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043b\u044e\u0431\u043e\u0439 Content-Type, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c: JSON \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">    \/\/ do something with the dto..create the booking..convert it to a transaction     Transaction transaction = null;     return transaction; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0432\u0430\u0448\u0435\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e\u0431 \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 JSON, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 TransactionDTO, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 Transaction, \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e. \u0412 \u044d\u0442\u043e\u043c \u0441\u0438\u043b\u0430 Spring MVC.<\/p>\n<p>  <\/p>\n<h3 id=\"sam-spring-ne-mozhet-konvertirovat-formaty-dannyh\">\u0421\u0430\u043c Spring \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: Spring \u0437\u043d\u0430\u0435\u0442 \u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445 Accept \u0438 Content-Type, \u043d\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 Java \u0438 JSON. \u0418\u043b\u0438 XML. \u0418\u043b\u0438 \u042f\u041c\u041b.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0433\u0440\u044f\u0437\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044f\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 (\u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f <em>\u043c\u0430\u0440\u0448\u0430\u043b\u0438\u043d\u0433 \/ \u0434\u0435\u043c\u0430\u0440\u0448\u0430\u043b\u043b\u0438\u043d\u0433<\/em> \u0438\u043b\u0438 <em>\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \/ \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/em>.)<\/p>\n<p>  <\/p>\n<p>\u0410 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 Spring MVC \u0438 \u044d\u0442\u0438\u043c\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438, \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <strong>HttpMessageConverters<\/strong>.<\/p>\n<p>  <\/p>\n<h3 id=\"chto-takoe-httpmessageconverter\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 HttpMessageConverter?<\/h3>\n<p>  <\/p>\n<p>HttpMessageConverter \u2014 \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441 \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u043c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438).<\/p>\n<p>  <\/p>\n<ol>\n<li><strong>canRead (MediaType)<\/strong> \u2192 \u041c\u043e\u0436\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 \u0447\u0438\u0442\u0430\u0442\u044c (JSON | XML | YAML | \u0438 \u0442. \u0434.)? \u041f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0437\u0434\u0435\u0441\u044c MediaType \u043e\u0431\u044b\u0447\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 Content-Type.<\/li>\n<li><strong>canWrite (MediaType)<\/strong> \u2192 \u041c\u043e\u0436\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0438\u0441\u0430\u0442\u044c (JSON | XML | YAML | \u0438 \u0442. \u0434.)? \u0422\u0438\u043f MediaType, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0437\u0434\u0435\u0441\u044c, \u043e\u0431\u044b\u0447\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 Accept.<\/li>\n<li><strong>read(Object, InputStream, MediaType)<\/strong> \u2192 \u0427\u0438\u0442\u0430\u0442\u044c \u043c\u043e\u0439 Java-\u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 (JSON | XML | YAML | \u0438 \u0442. \u0434.) InputStream<\/li>\n<li><strong>write(Object, OutputStream, MediaType)<\/strong> \u2192 \u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043e\u0439 Java-\u043e\u0431\u044a\u0435\u043a\u0442 \u0432 OutputStream \u043a\u0430\u043a (JSON | XML | YAML | \u0438 \u0442. \u0434.)<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041a\u043e\u0440\u043e\u0447\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, MessageConverter \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 MediaTypes \u043e\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, application\/json), \u0430 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \/ \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u044d\u0442\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<h3 id=\"kakie-est-httpmessageconverters\">\u041a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c HttpMessageConverters?<\/h3>\n<p>  <\/p>\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. Spring MVC \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0430\u0440\u0443 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 HTTPMessageConverters \u0434\u043b\u044f \u0432\u0430\u0441 \u2014 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432 \u043f\u0443\u0442\u0438 \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a \u043c\u0430\u0433\u0438\u044f. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 Spring <strong>AllEncompassingFormHttpMessageConverter<\/strong> (\u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u044d\u0442\u043e \u0438\u043c\u044f).<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">static {         ClassLoader classLoader = AllEncompassingFormHttpMessageConverter.class.getClassLoader();         jaxb2Present = ClassUtils.isPresent(&quot;javax.xml.bind.Binder&quot;, classLoader);         jackson2Present = ClassUtils.isPresent(&quot;com.fasterxml.jackson.databind.ObjectMapper&quot;, classLoader) &amp;&amp;                                         ClassUtils.isPresent(&quot;com.fasterxml.jackson.core.JsonGenerator&quot;, classLoader);         jackson2XmlPresent = ClassUtils.isPresent(&quot;com.fasterxml.jackson.dataformat.xml.XmlMapper&quot;, classLoader);         jackson2SmilePresent = ClassUtils.isPresent(&quot;com.fasterxml.jackson.dataformat.smile.SmileFactory&quot;, classLoader);         gsonPresent = ClassUtils.isPresent(&quot;com.google.gson.Gson&quot;, classLoader);         jsonbPresent = ClassUtils.isPresent(&quot;javax.json.bind.Jsonb&quot;, classLoader); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">jaxb2Present = ClassUtils.isPresent(&quot;javax.xml.bind.Binder&quot;, classLoader);<\/code><\/pre>\n<p>  <\/p>\n<p>Spring MVC \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 javax.xml.bind.Binder \u0438, \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 \u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 <a href=\"https:\/\/javaee.github.io\/jaxb-v2\/\" rel=\"nofollow\">JAXB<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">jackson2Present = ClassUtils.isPresent(&quot;com.fasterxml.jackson.databind.ObjectMapper&quot;, classLoader) &amp;&amp; ClassUtils.isPresent(&quot;com.fasterxml.jackson.core.JsonGenerator&quot;, classLoader);<\/code><\/pre>\n<p>  <\/p>\n<p>Spring MVC \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0434\u0432\u0443\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 <em>..jackson..ObjectMapper<\/em> \u0438 <em>..jackson..JsonGenerator<\/em> \u0438, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/FasterXML\/jackson\" rel=\"nofollow\">Jackson<\/a> \u0432 \u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 JSON.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">jackson2XmlPresent = ClassUtils.isPresent(&quot;com.fasterxml.jackson.dataformat.xml.XmlMapper&quot;, classLoader);<\/code><\/pre>\n<p>  <\/p>\n<p>Spring MVC \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 <em>..jackson..XmlMapper<\/em> \u0438, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 XML \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/FasterXML\/jackson\" rel=\"nofollow\">Jackson<\/a> s \u0432 \u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 XML.<\/p>\n<p>  <\/p>\n<p>\u0418 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0418 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u043a Spring \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 HttpMessageConverter \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u043d \u00ab\u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u00bb.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">if (jaxb2Present &amp;&amp; !jackson2XmlPresent) {         addPartConverter(new Jaxb2RootElementHttpMessageConverter()); }  if (jackson2Present) {         addPartConverter(new MappingJackson2HttpMessageConverter()); } else if (gsonPresent) {         addPartConverter(new GsonHttpMessageConverter()); }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"zametka-na-polyah-spring-boot-1\">\u0417\u0430\u043c\u0435\u0442\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b\u044f\u0445: Spring Boot<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 Spring Boot \u0432\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Spring MVC \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u041d\u043e Spring Boot \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 Jackson \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<p>  <\/p>\n<p><strong>\u0412\u043e\u0442<\/strong> \u043f\u043e\u0447\u0435\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 JSON \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring Boot, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 HttpMessageConverts \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043b\u044f \u0432\u0430\u0441.<\/p>\n<p>  <\/p>\n<h3 id=\"rezyume-rest-kontrollery\">\u0420\u0435\u0437\u044e\u043c\u0435: REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b<\/h3>\n<p>  <\/p>\n<p>\u041f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 HTML \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 JSON \/ XML \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 Model \u0438 View.<\/p>\n<p>  <\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u0430\u0448\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Java, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 Spring MVC \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 JSON \/ XML \u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u043b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e HttpMessageConverters.<\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0432\u0435\u0449\u0430\u0445, \u043e\u0434\u043d\u0430\u043a\u043e:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0418\u043c\u0435\u044e\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 \u043f\u0443\u0442\u0438 \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c.<\/li>\n<li>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 Accept \u0438\u043b\u0438 Content-Type \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"anchort6anchor-chasto-zadavaemye-voprosy\"><a name=\"t6\"><\/a> \u0427\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b<\/h2>\n<p>  <\/p>\n<h3 id=\"vy-gde-nibud-publikovali-ishodnyy-kod-etoy-stati\">\u0412\u044b \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438?<\/h3>\n<p>  <\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 GitHub:<br \/>  <a href=\"https:\/\/github.com\/marcobehler\/spring-mvc-article\" rel=\"nofollow\">https:\/\/github.com\/marcobehler\/spring-mvc-article<\/a><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e \u043a\u043b\u043e\u043d\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043a\u043b\u0430\u0441\u0441 <strong>SpringMvcArticleApplication<\/strong>, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<h3 id=\"v-chem-raznica-mezhdu-spring-mvc-i-spring-boot\">\u0412 \u0447\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 Spring MVC \u0438 Spring Boot?<\/h3>\n<p>  <\/p>\n<p>\u0412\u043a\u0440\u0430\u0442\u0446\u0435: <em>\u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b<\/em>, Spring Boot \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0438 \u0441\u0442\u0440\u043e\u0438\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <strong>\u043f\u043e\u0432\u0435\u0440\u0445<\/strong> Spring MVC.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"https:\/\/habr.com\/ru\/post\/490586\/\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Spring Framework?<\/a>.<\/p>\n<p>  <\/p>\n<h3 id=\"kakoy-samyy-bystryy-sposob-sozdat-novoe-prilozhenie-spring-mvc\">\u041a\u0430\u043a\u043e\u0439 \u0441\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 Spring MVC?<\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Spring MVC, \u0441\u0430\u043c\u044b\u043c \u0431\u044b\u0441\u0442\u0440\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e Spring Boot \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043d\u0430 \u0441\u0430\u0439\u0442: <a href=\"https:\/\/start.spring.io\/\" rel=\"nofollow\">https:\/\/start.spring.io\/<\/a>.<\/li>\n<li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0431\u0435\u0440\u0438\u0442\u0435 <strong>Spring Web<\/strong> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0435\u0431 \/ RESTful-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring MVC.<\/p>\n<p>  <\/p>\n<h3 id=\"kakoy-tip-vvoda-http-zaprosa-ponimaet-spring-mvc\">\u041a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u0432\u0432\u043e\u0434\u0430 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 Spring MVC?<\/h3>\n<p>  <\/p>\n<p>Spring MVC \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 HTTP \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u0442\u0435\u043b\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 JSON, XML \u0438\u043b\u0438 HTTP (Multipart) Fileuploads, \u0438 Spring \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u0432\u043e\u0434 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Java.<\/p>\n<p>  <\/p>\n<h3 id=\"kakie-http-otvety-mozhet-sozdavat-spring-mvc\">\u041a\u0430\u043a\u0438\u0435 HTTP-\u043e\u0442\u0432\u0435\u0442\u044b \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c Spring MVC?<\/h3>\n<p>  <\/p>\n<p>Spring MVC \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0432 HttpServletResponse \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a.<\/p>\n<p>  <\/p>\n<p>\u0411\u0443\u0434\u044c \u0442\u043e HTML, JSON, XML \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0442\u0435\u043b\u0430 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 WebSocket. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043e\u043d \u0431\u0435\u0440\u0435\u0442 \u0432\u0430\u0448\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Java \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u0438 \u0442\u0435\u043b\u0430 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0434\u043b\u044f \u0432\u0430\u0441.<\/p>\n<p>  <\/p>\n<h3 id=\"v-chem-raznica-mezhdu-kontrollerom--i-rest-kontrollerom\">\u0412 \u0447\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c \u0438 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c<\/h3>\n<p>  <\/p>\n<ol>\n<li><strong>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/strong> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 HTML \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @ResponseBody \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c XML \/ JSON.<\/li>\n<li>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 <strong>REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/strong> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e <strong>\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/strong> \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 @ResponseBody. \u0427\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 @ResponseBody \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"java\">@Controller @ResponseBody public @interface RestController {<\/code><\/pre>\n<p>  <\/p>\n<ol>\n<li>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 XML \/ JSON \u0432\u043c\u0435\u0441\u0442\u043e HTML.<\/li>\n<\/ol>\n<p>  <\/p>\n<p><strong><u>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435.<\/u><\/strong> XML \u0438 JSON \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0430\u043c\u044b\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Spring MVC. \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0430\u0448\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \/ REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0447\u0442\u043e-\u043b\u0438\u0431\u043e \u0435\u0449\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, YAML. \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 HttpMessageConverter \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u0432\u0430\u0448\u0435\u043c ApplicationContext.<\/p>\n<p>  <\/p>\n<h3 id=\"kakuyu-biblioteku-shablonov-mne-vybrat\">\u041a\u0430\u043a\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u043c\u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c?<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u043c\u043d\u043e\u0433\u0438\u0445 \u043b\u0435\u0442 \u044f \u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u043e\u0447\u0442\u0438 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0438, \u0445\u043e\u0442\u044f \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0441\u0442\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e Thymeleaf \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 Spring, \u0443 \u043c\u0435\u043d\u044f \u043d\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439. \u0418\u0442\u0430\u043a, \u043b\u0438\u0431\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c Thymeleaf (\u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u043e\u043f\u044b\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438), \u043b\u0438\u0431\u043e \u0432\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0430\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u0435\u043d.<\/p>\n<p>  <\/p>\n<h3 id=\"pochemu-moy-kontroller-vyvodit-404-vse-mapingi-verny\">\u041f\u043e\u0447\u0435\u043c\u0443 \u043c\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 404? \u0412\u0441\u0435 \u043c\u0430\u043f\u0438\u043d\u0433\u0438 \u0432\u0435\u0440\u043d\u044b.<\/h3>\n<p>  <\/p>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 JSON \u0438\u043b\u0438 XML, \u043d\u043e \u0432\u0430\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @ResponseBody.<\/p>\n<p>  <\/p>\n<p>Spring \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 404 Not Found \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.ResponseBody;  @Controller public class _404WithMissingResponseBodyController {      @GetMapping(&quot;\/users\/{id}&quot;)   \/* This won't work and lead to a 404 *\/     public User getUser_404(@PathVariable String id) {         return new User(&quot;Everyone's name is John&quot;, id);     }      @GetMapping(&quot;\/users2\/{id}&quot;)     @ResponseBody  \/* This will work *\/     public User getUser_200(@PathVariable String id) {         return new User(&quot;Everyone's name is John&quot;, id);     } }<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/strong>: \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 @ResponseBody \u0438\u043b\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u0430\u0448 <em>\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/em> \u0432 <em>REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/em>.<\/p>\n<p>  <\/p>\n<h3 id=\"chto-proizoydet-esli-vy-opredelite-odin-i-tot-zhe-maping-zaprosov-dlya-dvuh-raznyh-metodov\">\u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043c\u0430\u043f\u0438\u043d\u0433 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432?<\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u044d\u0442\u0438 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 HTTP \u043c\u0435\u0442\u043e\u0434\u044b, \u044d\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">\/* \u044d\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 *\/  @PostMapping(&quot;\/users&quot;) public void method1() {  }  @GetMapping(&quot;\/users&quot;) publi void method(2) {  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u0435 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0435 HTTP \u043c\u0435\u0442\u043e\u0434\u044b \u0441 \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 \u043f\u0443\u0442\u0435\u043c, \u0443 \u0432\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">\/* \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 *\/  @PostMapping(&quot;\/users&quot;) public void method1() {  }  @PostMapping(&quot;\/users&quot;) publi void method(2) {  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e <em>IllegalStateException<\/em>, \u0447\u0442\u043e \u043d\u0430\u043c\u0435\u043a\u0430\u0435\u0442 \u043d\u0430 \u0432\u0430\u0448\u0435 \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"powershell\">Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'howToPassAndRetrieveRequestParametersController' method com.marcobehler.springmvcarticle.HowToPassAndRetrieveRequestParametersController#createUser(User) to {POST \/users3}: There is already 'howToPassAndRetrieveRequestParametersController' bean method<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"nuzhno-li-v-url-kodirovat-requestparams\">\u041d\u0443\u0436\u043d\u043e \u043b\u0438 \u0432 URL \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c @RequestParams?<\/h3>\n<p>  <\/p>\n<p>\u0414\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Spring <strong>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438<\/strong> \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u0438\u0445 \u0438\u0437 URL. \u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430:<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435\u043c \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u043a \u00ab+\u00bb \u043d\u0430 \u0441\u0432\u043e\u0435\u043c \u0430\u0434\u0440\u0435\u0441\u0435 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"http:\/\/marco+wantsnospam@marcobehler.com\" rel=\"nofollow\">marco+wantsnospam@marcobehler.com<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@GetMapping(&quot;\/confirm&quot;) public void confirm(@RequestParam String email, @RequestParam String token){     \/\/ confirm user... }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0431\u044b\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u043a \u2018+\u2019 \u0432 URL \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0438\u0441\u044c\u043c\u0435-\u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0438 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 \u043a\u0430\u043a \u0435\u0441\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043a\u0430\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u0430\u044f \u043f\u043e\u0447\u0442\u0430 @RequestParam?<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u00abmarco[space]wantnospam@marcobehler.com\u00bb, \u0442\u0430\u043a \u043a\u0430\u043a Spring \u0437\u0430\u043c\u0435\u043d\u0438\u0442 + \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u043c, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 RFC3986.<\/p>\n<p>  <\/p>\n<p><strong>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435:<\/strong> \u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e URL-\u0430\u0434\u0440\u0435\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0432\u0432\u043e\u0434\u0438\u0442\u0435 \u0432 \u0441\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u044b: <a href=\"http:\/\/marco+wantsnospam@marcobehler.com\" rel=\"nofollow\">marco%2Bwantsnospam@marcobehler.com<\/a>, \u0442\u0430\u043a \u043a\u0430\u043a Spring \u0431\u0443\u0434\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0445 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<h3 id=\"kak-poluchit-dostup-k-tekuschey-httpsession-polzovatelya\">\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u0439 HttpSession \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f?<\/h3>\n<p>  <\/p>\n<p>\u0412 Spring MVC \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u0438\u043b\u0438 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c HttpSession \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u0435\u0442\u043e\u0434\u0430, \u0438 Spring <strong>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438<\/strong> \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u0435\u0433\u043e (\u0441\u043e\u0437\u0434\u0430\u0432 \u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0449\u0435 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442).<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RestController public class HttpSessionController {      @GetMapping(&quot;\/session&quot;)     public String getSession(HttpSession httpSession) {         System.out.println(&quot;httpSession = &quot; + httpSession);         return httpSession.getId();     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438, \u043d\u043e \u0432\u044b \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c HttpSession \u0432 \u043d\u0438\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Service class SomeOtherService {      @Autowired     private HttpSession httpSession;      public HttpSession getHttpSession() {         return httpSession;     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"kak-poluchit-dostup-k-httpservletrequest\">\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a HttpServletRequest?<\/h3>\n<p>  <\/p>\n<p>\u0412 \u0432\u0430\u0448\u0435\u043c Spring MVC \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u0438\u043b\u0438 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c HttpServletRequest \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u0435\u0442\u043e\u0434\u0430, \u0438 Spring <strong>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438<\/strong> \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u0435\u0433\u043e (\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f, \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0449\u0435 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442)<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RestController public class HttpServletRequestController {      @Autowired     private SomeRequestService someRequestService;      @GetMapping(&quot;\/request&quot;)     public String getRequest(HttpServletRequest request) {         System.out.println(&quot;request = &quot; + request);         return request.toString();     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438, \u043d\u043e \u0432\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c HttpServletRequest \u0432 \u043d\u0438\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Service class SomeRequestService {      @Autowired     private HttpServletRequest httpServletRequest;      public HttpServletRequest getRequest() {         return httpServletRequest;     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"kak-chitat-http-zagolovki\">\u041a\u0430\u043a \u0447\u0438\u0442\u0430\u0442\u044c HTTP \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438?<\/h3>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0445\u043e\u0442\u0438\u0442\u0435 \u043b\u0438 \u0432\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u043a\u0430\u0440\u0442\u0443 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0438\u0437 \u043d\u0438\u0445. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e @RequestHeader.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a\u0443\u044e \u0431\u044b \u0432\u0435\u0440\u0441\u0438\u044e \u0432\u044b \u043d\u0438 \u0432\u044b\u0431\u0440\u0430\u043b\u0438, \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u0431\u044b\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0441 \u0432\u0430\u0448\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader;  import java.util.Map;  @Controller public class HttpHeaderController {      @GetMapping(&quot;\/headers1&quot;)     public void singleHeader(@RequestHeader(&quot;x-forwarded-for&quot;) String xForwardedFor) {        \/\/ ...     }      @GetMapping(&quot;\/headers2&quot;)     public void headersAsMap(@RequestHeader Map&lt;String,String&gt; headers) {  \/\/ or MultiValueMap&lt;String,String&gt;         \/\/ ...     }      @GetMapping(&quot;\/headers3&quot;)     public void headersAsObject(HttpHeaders headers) {         \/\/ ...     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"kak-chitat-i-pisat-cookie\">\u041a\u0430\u043a \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c cookie?<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432 cookie \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <em>@CookieValue<\/em> \u0432 \u0441\u0432\u043e\u0438\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445. \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c cookie \u043f\u0440\u044f\u043c\u043e \u0432 HttpServletResponse.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.GetMapping;  import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse;  @Controller public class CookieController {      @GetMapping(&quot;\/cookie&quot;)     public void handle(@CookieValue(&quot;JSESSIONID&quot;) String cookie, HttpServletResponse response) {          response.addCookie(new Cookie(&quot;SOME_COOKIE_NAME&quot;, &quot;This is a crazy new cookie!&quot;));         \/\/...     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"kak-poluchit-ip-adres-polzovatelya\">\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c IP-\u0430\u0434\u0440\u0435\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f?<\/h3>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u0441 \u043f\u043e\u0434\u0432\u043e\u0445\u043e\u043c. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <em>httpServletRequest.getRemoteAddr()<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043e\u0434\u043d\u0430\u043a\u043e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e IP-\u0430\u0434\u0440\u0435\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u043a\u0441\u0438-\u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0432\u0448\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441, \u0432 99,99% \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u044d\u0442\u043e \u0432\u0430\u0448 Nginx \u0438\u043b\u0438 Apache.<\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <em>X-Forwarded-For<\/em> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e IP-\u0430\u0434\u0440\u0435\u0441\u0430. \u041d\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0437\u0430 CDN, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 CloudFront? \u0422\u043e\u0433\u0434\u0430 \u0432\u0430\u0448 X-Forwarded-For \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">X-Forwarded-For: MaybeSomeSpoofedIp, realIp, cloudFrontIp<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0434\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a X-Forwarded-For. \u0412\u0430\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u0434\u0442\u0438 <em>\u0441\u043f\u0440\u0430\u0432\u0430<\/em> \u043d\u0430\u043b\u0435\u0432\u043e \u0438 <em>\u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0442\u044c<\/em> \u0432\u0441\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 IP-\u0430\u0434\u0440\u0435\u0441\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 CloudFront \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u043d\u0430\u0442\u044c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b IP-\u0430\u0434\u0440\u0435\u0441\u043e\u0432 CloudFront \u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0445 \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430. \u0410\u0433\u0430!<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443, \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u044e\u0449\u0435\u043c\u0443 IP. \u0423\u0433\u0430\u0434\u0430\u0439\u0442\u0435, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u044d\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e!<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;  import javax.servlet.http.HttpServletRequest;  @RestController public class IpController {      private static final String[] HEADERS_TO_TRY = {             &quot;X-Forwarded-For&quot;,             &quot;Proxy-Client-IP&quot;,             &quot;WL-Proxy-Client-IP&quot;,             &quot;HTTP_X_FORWARDED_FOR&quot;,             &quot;HTTP_X_FORWARDED&quot;,             &quot;HTTP_X_CLUSTER_CLIENT_IP&quot;,             &quot;HTTP_CLIENT_IP&quot;,             &quot;HTTP_FORWARDED_FOR&quot;,             &quot;HTTP_FORWARDED&quot;,             &quot;HTTP_VIA&quot;,             &quot;REMOTE_ADDR&quot;};      @GetMapping(&quot;\/ip&quot;)     public String getClientIpAddress(HttpServletRequest request) {         for (String header : HEADERS_TO_TRY) {             String ip = request.getHeader(header);             if (ip != null &amp;&amp; ip.length() != 0 &amp;&amp; !&quot;unknown&quot;.equalsIgnoreCase(ip)) {                 return getRealClientIpAddress(ip);             }         }         return request.getRemoteAddr();     }      \/**      * Goes through the supplied ip string (could be one or multiple). Traverses it through the right side...      * and removes any known ip address ranges      *      * @param ipString      * @return      *\/     public String getRealClientIpAddress(String ipString) {         String[] manyPossibleIps = ipString.split(&quot;,&quot;);          for (int i = manyPossibleIps.length - 1; i &gt;= 0; i--) {             String rightMostIp = manyPossibleIps[i].trim();             if (isKnownAddress(rightMostIp)) {                 continue; \/\/ skip this ip as it is trusted             } else {                 return rightMostIp;             }         }          return ipString;     }      private boolean isKnownAddress(String rightMostIp) {         \/\/ do your check here..for cloudfront you'd need to download their ip address ranges         \/\/ from e.g. http:\/\/d7uri8nf7uskq.cloudfront.net\/tools\/list-cloudfront-ips         \/\/ and compare the current ip against them         return false;     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"kak-vy-mozhete-upravlyat-zagruzkoy-faylov-v-prilozhenii-spring-mvc\">\u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Spring MVC?<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 HTML-\u0444\u0430\u0439\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;form method=&quot;POST&quot; enctype=&quot;multipart\/form-data&quot; action=&quot;\/upload&quot;&gt;     File to upload:&lt;input type=&quot;file&quot; name=&quot;file&quot; \/&gt;     &lt;input type=&quot;submit&quot; value=&quot;Upload&quot; \/&gt; &lt;\/form&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u0435\u043d \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 @PostMapping \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c MultiPartFile, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u0434\u0438\u0441\u043a\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile;  import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths;  @Controller public class FileUploadController {      @PostMapping(&quot;\/upload&quot;)     public String handleFileUpload(@RequestParam MultipartFile file) throws IOException {         \/\/ don't generate upload files like this in a real project.         \/\/ give them random names and save their uploaded name as metadata in a database or similar         final Path uploadDestination = Paths.get(&quot;C:\\\\uploads&quot;).resolve(file.getName());          file.transferTo(uploadDestination);         return &quot;redirect:\/&quot;;     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"kak-obrabatyvat-zagruzku-binarnyh-faylov-xls-pdf-csv-jpg-zip-s-pomoschyu-spring-kontrollerov\">\u041a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 (xls, pdf, csv, jpg, zip) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432?<\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043e\u0442 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 HttpServletResponse \u0438\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 byte[] \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0441\u0430\u043c\u0430\u044f Spring-\u0438 \u0438 \u0433\u0438\u0431\u043a\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0435 &#8216;<em>ResponseEntity &#8216;. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0433\u0434\u0435 \u0432\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u0444\u0430\u0439\u043b, \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/em>  <\/p>\n<ul>\n<li>\u041d\u0430 \u0434\u0438\u0441\u043a\u0435 \u2192 FileSystemResource<\/li>\n<li>\u041d\u0430 \u043f\u0443\u0442\u0438 \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u2192 ClassPathResource<\/li>\n<li>\u041f\u043e\u0442\u043e\u043a\u043e\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0438\u0437 \u00ab\u0433\u0434\u0435-\u0442\u043e\u00bb \u2192 InputStreamResource<\/li>\n<li>\u0421\u0434\u0435\u043b\u0430\u043b\u0438 \u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u043a\u0430\u043a \u043c\u0430\u0441\u0441\u0438\u0432 byte[] \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u2192 ByteArrayResource<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 HTTP-\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 (\u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430, \u0442\u0438\u043f \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u0442.\u0434.).<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.server.ResponseStatusException;  import java.io.IOException;  @Controller public class FileDownloadController {      @RequestMapping(value = &quot;\/download\/{jpgName}&quot;, method = RequestMethod.GET)     public ResponseEntity&lt;Resource&gt; downloadJpg(             @PathVariable String jpgName) throws IOException {          \/\/  Resource downloadResource = new InputStreamResource(soimeinputStream)         \/\/  Resource downloadResource = new ByteArrayResource(someByteArray)         \/\/  Resource downloadResource = new FileSystemResource(someFile)         final ClassPathResource downloadResource = new ClassPathResource(jpgName);          if (!downloadResource.exists()) {             throw new ResponseStatusException(HttpStatus.BAD_REQUEST);         }          HttpHeaders headers = new HttpHeaders();          \/\/ 1. set the correct content type         headers.setContentType(MediaType.IMAGE_JPEG);          \/\/ 2. set the correct content length, maybe stored in a db table         headers.setContentLength(downloadResource.contentLength());          \/\/ 3. if you want to force downloads, otherwise attachments might be displayed directly in the brwoser         headers.setContentDispositionFormData(&quot;attachment&quot;, jpgName);          return new ResponseEntity&lt;&gt;(downloadResource, headers, HttpStatus.OK);     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"kak-ya-mogu-globalno-obrabatyvat-isklyucheniya-v-moih-kontrollerah\">\u041a\u0430\u043a \u044f \u043c\u043e\u0433\u0443 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u043c\u043e\u0438\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445?<\/h3>\n<p>  <\/p>\n<p>\u0412 Spring MVC \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0441\u0432\u043e\u0438\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445, \u0430 \u0432 \u043e\u0434\u043d\u043e\u043c \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043a\u043b\u0430\u0441\u0441 <em>ControllerAdvice<\/em> \u0438\u043b\u0438 <em>RestControllerAdvice<\/em> \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 @ResponseStatus \u0438 @ExceptionHandler. \u041d\u0435\u0441\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f \u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0435 \u043c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c\u0438 \u0434\u0432\u0443\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u043f\u043e\u043d\u0438\u043c\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c \u0438 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c.<\/li>\n<li>@ResponseStatus \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 HTTP, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/li>\n<li>@ExceptionHandler \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0430\u0448 \u043c\u0435\u0442\u043e\u0434-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.<\/li>\n<li>\u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e, \u044d\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u043b\u0438 REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.http.HttpStatus; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus;  @ControllerAdvice public class GlobalControllerExceptionHandler {      @ResponseStatus(HttpStatus.CONFLICT)  \/\/ 409     @ExceptionHandler(SomeConflictException.class)     public String handleConflict(SomeConflictException e, Model model) {         \/\/ do something         model.addAttribute(&quot;message&quot;, e.getMessage());         return &quot;new-template&quot;;     }      @ResponseStatus(HttpStatus.NOT_IMPLEMENTED)  \/\/ 409     @ExceptionHandler(NotYetImplementedExceptoin.class)     public void handleBandwithLimitExceeded(NotYetImplementedExceptoin e) {         \/\/ do nothing;     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"kak-vernut-lyuboy-kod-sostoyaniya-400-404-i-td-iz-vashih-kontrollerov\">\u041a\u0430\u043a \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u0434 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f (400, 404 \u0438 \u0442.\u0434.) \u0438\u0437 \u0432\u0430\u0448\u0438\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432?<\/h3>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <em>ResponseStatusException<\/em> \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439.<\/p>\n<p>  <\/p>\n<p>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 ResponseEntity, \u043d\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">package com.marcobehler.springmvcarticle;  import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.server.ResponseStatusException;  @Controller public class HttpStatusCodeController {      @GetMapping(&quot;\/somePath&quot;)     public void alwaysThrowsException() {          \/\/throw new ResponseStatusException(HttpStatus.NOT_FOUND, &quot;Meeepp, not found.&quot;);          throw new ResponseStatusException(HttpStatus.BAD_REQUEST, &quot;Well, that just wasn't right!&quot;);     } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"kak-naschet-koncepcii-xyz-v-spring-mvc\">\u041a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 XYZ \u0432 Spring MVC?<\/h3>\n<p>  <\/p>\n<p>\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f <a href=\"https:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/web.html#spring-web\" rel=\"nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Spring MVC<\/a> \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u043e\u0442\u043d\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e \u043c\u043e\u0434\u0435\u043b\u044f\u0445, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445, ViewHandlers, InitBinders, RootContexts, \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0445, \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 \u0442.\u0434., \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0430\u043c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e Spring MVC. \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430, \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"anchort7anchor-zaklyuchenie\"><a name=\"t7\"><\/a> \u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0431\u044b\u043b\u0430 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u043f\u0440\u043e\u0433\u0443\u043b\u043a\u0430. \u041d\u0430\u043a\u043e\u043d\u0435\u0446 \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0449\u0435\u0439 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>Spring MVC \u2014 \u044d\u0442\u043e \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 MVC-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u044b HTML \u0438\u043b\u0438 JSON\/XML \u0432\u0435\u0431-\u0441\u043b\u0443\u0436\u0431\u044b.<\/li>\n<li>\u041e\u043d \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b Spring, \u0442\u0430\u043a\u043e\u0439 \u043a\u0430\u043a Spring Boot.<\/li>\n<li>\u0413\u043b\u0430\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0441\u0432\u043e\u0435\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438, \u043d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u044f\u0441\u044c \u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430, \u0440\u0430\u0437\u0431\u043e\u0440\u0435 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \/ \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435 \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"anchort8anchor-blagodarnosti\"><a name=\"t8\"><\/a> \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e <a href=\"https:\/\/www.linkedin.com\/in\/patomos\/\" rel=\"nofollow\">Patricio &quot;Pato&quot; Moschcovich<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0443\u0440\u0443 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u043d\u043e \u0438 \u0434\u0430\u043b \u0431\u0435\u0441\u0446\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0437\u044b\u0432!<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/500572\/\"> https:\/\/habr.com\/ru\/post\/500572\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/500572\/\">\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Spring MVC \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u043e\u0432 \u0438\u043b\u0438 RESTful \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u0437\u043e\u0440 \u0447\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u043e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 Spring MVC.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0421\u0442\u0430\u0442\u044c\u044f ~ 7500 \u0441\u043b\u043e\u0432, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0435 \u043d\u0430 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435. \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0435\u0435 \u0432 \u0437\u0430\u043a\u043b\u0430\u0434\u043a\u0438 \u0438 \u0432\u0435\u0440\u043d\u0438\u0442\u0435\u0441\u044c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"soderzhanie\">\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"#t1\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <\/a><\/li>\n<li><a href=\"#t2\">HttpServlets 101 <\/a><\/li>\n<li><a href=\"#t3\">DispatcherServlet <\/a><\/li>\n<li><a href=\"#t4\">\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 HTML<\/a><\/li>\n<li><a href=\"#t5\">REST \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 XML \/ JSON<\/a><\/li>\n<li><a href=\"#t6\">\u0427\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b <\/a><\/li>\n<li><a href=\"#t7\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/li>\n<li><a href=\"#t8\">\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u0438<\/a><br \/>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-303277","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303277"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303277\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}