{"id":377587,"date":"2024-05-30T21:00:28","date_gmt":"2024-05-30T21:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=377587"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=377587","title":{"rendered":"<span>MapStruct \u2014 \u0441\u043c\u0430\u043f\u043f\u044c \u043c\u0435\u043d\u044f, \u0435\u0441\u043b\u0438 \u0441\u043c\u043e\u0436\u0435\u0448\u044c<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/strong> <a href=\"https:\/\/github.com\/yayauheny\/javanotice-mapstruct\" rel=\"noopener noreferrer nofollow\">github<\/a><\/p>\n<blockquote>\n<p><em>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u044f\u043c\u0438 \u043a\u0430\u043a <\/em><strong><em>DTO<\/em><\/strong><em>, <\/em><strong><em>Mapping<\/em><\/strong><em>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f (\u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0434\u043e\u043f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u043f\u043e \u0442\u0435\u043c\u0435).<\/em><\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/049\/94c\/1da\/04994c1daac0533255e6aec2d630b604.jpg\" alt=\"MapStruct\" title=\"MapStruct\" width=\"1097\" height=\"585\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/049\/94c\/1da\/04994c1daac0533255e6aec2d630b604.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>MapStruct<\/figcaption><\/div>\n<\/figure>\n<p>\u042f \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b \u043d\u0430 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0435\u043c\u0430\u043b\u043e \u043d\u0435\u0440\u0432\u043d\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a, \u0438 \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0443\u0437\u043d\u0430\u043b \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0438 \u043b\u0430\u0439\u0444\u0445\u0430\u043a\u0438, \u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0442\u0430\u0440\u0442\u0430 \u043d\u0435 \u0438\u0441\u043f\u044b\u0442\u044b\u0432\u0430\u043b\u0438 &#171;\u043d\u0435\u0436\u0434\u0430\u043d\u0447\u0438\u043a\u043e\u0432&#187; \u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043b\u0438 \u0441\u0432\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u0445 \u043d\u0430\u0439\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431.<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<p><strong><em>\u0421\u041f\u041e\u0419\u041b\u0415\u0420<\/em><\/strong><em>: \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u044f \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0441\u043b\u043e\u0439 <\/em><strong><em>service<\/em><\/strong><em>, \u0430 \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0441\u044c \u043a <\/em><strong><em>repository <\/em><\/strong><em>\u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0438 \u0442\u0430\u043a\u0436\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u0441\u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u0435\u043c\u0435.<\/em><\/p>\n<\/div>\n<\/details>\n<h2>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p><strong>\u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e<\/strong>: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u043b\u0435\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <strong>User<\/strong> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a: <strong>id, username, email, password<\/strong>.<\/p>\n<div class=\"floating-image\">\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/577\/ecb\/c0d\/577ecbc0d28d9021072e000358617f7c.png\" alt=\"\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c User\" title=\"\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c User\" width=\"424\" height=\"513\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/577\/ecb\/c0d\/577ecbc0d28d9021072e000358617f7c.png\"\/><\/p>\n<div><figcaption>\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c User<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c <strong>\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435<\/strong>, \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/555760\/\" rel=\"noopener noreferrer nofollow\">\u0411\u0414 <\/a>(\u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445), \u0438 \u0437\u0430\u0442\u0435\u043c <strong>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong>, \u0430 \u0442\u0430\u043a\u0436\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA_%D0%BA%D0%BE%D0%B4%D0%BE%D0%B2_%D1%81%D0%BE%D1%81%D1%82%D0%BE%D1%8F%D0%BD%D0%B8%D1%8F_HTTP\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u0443\u0441<\/a>, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u0443\u0441\u043f\u0435\u0445 \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0443).<\/p>\n<p><strong><em>\u0412\u043e\u043f\u0440\u043e\u0441<\/em><\/strong><em>: \u043a\u0430\u043a \u0432\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u043e\u043b\u0435 <\/em><strong><em>password<\/em><\/strong><em> \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f? <\/em><\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<p><strong><em>\u0421\u043f\u043e\u0439\u043b\u0435\u0440<\/em><\/strong><em>: \u043d\u0435\u0442!<\/em><\/p>\n<\/div>\n<\/details>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e <strong>\u043e\u0431\u043d\u0443\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u0435 password,<\/strong> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0443 &#8212; \u043d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c <strong>\u0437\u0430\u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0431\u043d\u0443\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f<\/strong>, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 &#8212; \u0430 \u0442\u0430\u043c \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 <strong>\u043c\u043e\u0433\u0443\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c<\/strong> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0438\u0445 \u0446\u0435\u043b\u044f\u0445 <em>(\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440 &#8212; \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043d\u0430\u0448 API).<\/p>\n<p><\/em>\u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <strong>\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 UserResponse<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 <strong>\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f DTO<\/strong>, \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u043f\u043e\u043b\u0435 <strong>password<\/strong>, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5ce\/e4f\/3f6\/5cee4f3f6962407137b97fcb255a1e97.png\" alt=\"\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c UserResponse\" title=\"\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c UserResponse\" width=\"455\" height=\"472\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5ce\/e4f\/3f6\/5cee4f3f6962407137b97fcb255a1e97.png\"\/><\/p>\n<div><figcaption>\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c UserResponse<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p><em>\u041c\u044b, \u043a\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435. \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b, \u043b\u0438\u0431\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0441\u043e\u0431\u0443\u044e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0435 <\/em><strong><em>password<\/em><\/strong><em> &#8212; \u043f\u0430\u0440\u043e\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f), \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u0445 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 (\u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0448 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441, \u043b\u0438\u0431\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440, \u043b\u0438\u0431\u043e \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443)<\/em><\/p>\n<\/blockquote>\n<p><em>\u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f: <\/em><a href=\"https:\/\/habr.com\/ru\/articles\/495698\/\" rel=\"noopener noreferrer nofollow\"><em>\u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430<\/em><\/a><em> \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0439, \u043a\u0442\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c. \u0410 \u0442\u043e\u0442, \u043a\u0442\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0445, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c. \u0422\u043e \u0435\u0441\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u0434\u0430\u0436\u0435 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<br \/><\/em><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/17f\/0ee\/9ae\/17f0ee9ae5ce9eaa3aa568a189dea246.png\" alt=\"\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\" title=\"\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\" width=\"1916\" height=\"384\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/17f\/0ee\/9ae\/17f0ee9ae5ce9eaa3aa568a189dea246.png\"\/><\/p>\n<div><figcaption>\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p><em>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e <\/em><strong><em>DTO (Data transfer object) &#8212; \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/em><\/strong><em>, \u0441\u043c\u044b\u0441\u043b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f <\/em><strong><em>\u0432 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/em><\/strong><em>. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c <\/em><strong><em>DTO<\/em><\/strong><em> \u043e\u0431\u044c\u0435\u043a\u0442 (\u0435\u0441\u043b\u0438 \u0442\u043e\u0433\u043e  \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0430), \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <\/em><strong><em>id<\/em><\/strong><em>, <\/em><strong><em>username<\/em><\/strong><em>, <\/em><strong><em>email<\/em><\/strong><em>).<\/em><\/p>\n<\/blockquote>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, <strong>DTO <\/strong>&#8212; \u044d\u0442\u043e <strong>\u043e\u0431\u044b\u0447\u043d\u044b\u0439 Java \u043e\u0431\u044a\u0435\u043a\u0442<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u0438\u0437\u043d\u0435\u0441 \u043c\u043e\u0434\u0435\u043b\u0438 <em>(\u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u043d\u0430\u0448 User &#8212; \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445)<\/em>, \u043d\u043e \u0441\u043b\u0443\u0436\u0438\u0442 \u043d\u0435\u043a\u0438\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c <em>(\u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 &#8212; \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445).<\/em><\/p>\n<h2>Mapping: \u0447\u0442\u043e \u0442\u044b, \u0447\u0435\u0440\u0442 \u0432\u043e\u0437\u044c\u043c\u0438, \u0442\u0430\u043a\u043e\u0435?<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443: <strong>\u043a\u0430\u043a<\/strong> \u043d\u0430\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e <strong>\u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438<\/strong> <strong>\u043e\u0431\u044a\u0435\u043a\u0442 User \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443 UserResponse? <\/p>\n<p><\/strong>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0432 \u0438\u0433\u0440\u0443 \u0432\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 <strong>\u043c\u0430\u043f\u043f\u0438\u043d\u0433 <\/strong><em>(eng: mapping), <\/em>\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 X \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 Y, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>User &#8212;> UserResponse. <br \/><\/strong><\/p>\n<blockquote>\n<p><em>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u043d\u0443\u0436\u0435\u043d \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043f\u043e\u043b\u044f \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c.<\/em><\/p>\n<\/blockquote>\n<h2>MapStruct: \u0441\u043c\u0430\u043f\u043f\u044c \u043c\u0435\u043d\u044f, \u0435\u0441\u043b\u0438 \u0441\u043c\u043e\u0436\u0435\u0448\u044c<\/h2>\n<p><a href=\"https:\/\/mapstruct.org\/documentation\/stable\/reference\/html\/\" rel=\"noopener noreferrer nofollow\"><strong>MapStruct<\/strong> <\/a>&#8212; \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e \u0441\u0443\u0442\u0438 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043f\u043f\u0435\u0440\u043e\u043c. \u041c\u0430\u043f\u043f\u0435\u0440\u043e\u0432 \u0431\u044b\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e, \u043d\u043e <strong>\u0441\u0430\u043c\u044b\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0439<\/strong> &#8212; MapStruct.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u043f\u043f\u0435\u0440\u0430 \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0440\u0443\u043a\u0430\u043c\u0438 <em>(\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043b\u0430\u0441\u0442\u044c \u0442\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0430\u0448 DTO)<\/em>, \u0432\u0441\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043d\u0443 \u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0438..<\/p>\n<p><strong><em>\u0417\u0430\u0447\u0435\u043c \u043d\u0430\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0443\u0436\u0435\u043d \u043c\u0430\u043f\u043f\u0435\u0440, \u043a \u0447\u0435\u043c\u0443 \u043b\u0438\u0448\u043d\u0438\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438?<\/em><\/strong><em> <br \/><\/em><\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<p><em>\u0425\u043e\u0440\u043e\u0448\u0438\u0439 \u0432\u043e\u043f\u0440\u043e\u0441. \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438, \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 (\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f, \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \/ enum-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 (\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u043e\u043b\u044c, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0438\u043a\u043d\u0435\u0439\u043c), \u0438 \u0442.\u043f).<\/p>\n<p>\u041f\u0440\u043e\u0449\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u0432\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f, \u043d\u0435\u0440\u0432\u044b, \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439.<\/em><\/p>\n<\/div>\n<\/details>\n<h2>\u0422\u0435\u043e\u0440\u0438\u044f &#8212; \u0445\u043e\u0440\u043e\u0448\u043e, \u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 &#8212; \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435!<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e <strong>\u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0431\u043e\u0440\u043a\u0438<\/strong> \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <em>(\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e <\/em><strong><em>Gradle<\/em><\/strong><em>, \u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f <\/em><strong><em>Maven<\/em><\/strong><em> \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435)<\/em>.<\/p>\n<p><a href=\"https:\/\/mapstruct.org\/documentation\/installation\/#gradle\" rel=\"noopener noreferrer nofollow\"><strong><em>Gradle<\/em><\/strong><\/a><strong><em>:<\/em><\/strong><\/p>\n<pre><code class=\"java\">dependencies {     \/\/...      \/\/ MapStruct     implementation 'org.mapstruct:mapstruct:1.5.5.Final'     annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' }<\/code><\/pre>\n<p><a href=\"https:\/\/mapstruct.org\/documentation\/installation\/#apache-maven\" rel=\"noopener noreferrer nofollow\"><strong><em>Maven<\/em><\/strong><\/a><strong><em>:<\/em><\/strong><\/p>\n<pre><code class=\"java\">&lt;properties>     &lt;org.mapstruct.version>1.5.5.Final&lt;\/org.mapstruct.version> &lt;\/properties> ... &lt;dependencies>     &lt;dependency>         &lt;groupId>org.mapstruct&lt;\/groupId>         &lt;artifactId>mapstruct&lt;\/artifactId>         &lt;version>${org.mapstruct.version}&lt;\/version>     &lt;\/dependency> &lt;\/dependencies> ... &lt;build>     &lt;plugins>         &lt;plugin>             &lt;groupId>org.apache.maven.plugins&lt;\/groupId>             &lt;artifactId>maven-compiler-plugin&lt;\/artifactId>             &lt;version>3.8.1&lt;\/version>             &lt;configuration>                 &lt;source>1.8&lt;\/source>                 &lt;target>1.8&lt;\/target>                 &lt;annotationProcessorPaths>                     &lt;path>                         &lt;groupId>org.mapstruct&lt;\/groupId>                         &lt;artifactId>mapstruct-processor&lt;\/artifactId>                         &lt;version>${org.mapstruct.version}&lt;\/version>                     &lt;\/path>                 &lt;\/annotationProcessorPaths>             &lt;\/configuration>         &lt;\/plugin>     &lt;\/plugins> &lt;\/build><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <strong>User<\/strong>:<\/p>\n<pre><code class=\"java\">@Data @Entity @NoArgsConstructor @AllArgsConstructor @Table(name = \"users\") public class User {      @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     private Long id;     private String username;     private String email;     private String password; }<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 <strong>UserResponse <\/strong>(dto) \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0443:<\/p>\n<pre><code class=\"java\">public record UserResponse(         Long id,         String username,         String email) { }<\/code><\/pre>\n<blockquote>\n<p><em>\u041d\u0435 \u043f\u0443\u0433\u0430\u0439\u0442\u0435\u0441\u044c, \u0435\u0441\u043b\u0438 \u0443\u0432\u0438\u0434\u0435\u043b\u0438 <\/em><a href=\"https:\/\/habr.com\/ru\/articles\/487308\/\" rel=\"noopener noreferrer nofollow\"><strong><em>record <\/em><\/strong><\/a><em>\u0432\u043f\u0435\u0440\u0432\u044b\u0435: \u044d\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0432 Java, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 final \u043f\u043e\u043b\u044f\u043c\u0438 (\u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u044f \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 hashcode()&amp;equals() + toString() + get() \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438.<\/em><\/p>\n<\/blockquote>\n<h2>UserMapper &#8212; \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0430\u043f\u043f\u0435\u0440<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <strong>interface UserMapper<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u0430\u043a\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <strong>\u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438<\/strong> (\u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430) \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 DTO:<\/p>\n<pre><code class=\"java\">@Mapper(componentModel = MappingConstants.ComponentModel.SPRING) public interface UserMapper {      UserResponse toUserResponse(User user); \/\/map User to UserResponse  List&lt;UserResponse> toUserResponseList(List&lt;User> users); \/\/map list of User to list of UserResponse }<\/code><\/pre>\n<p><strong><em>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e: <\/em><\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <\/strong>(\u0438\u043b\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441) \u0441 \u0438\u043c\u0435\u043d\u0435\u043c &#8216;Mapper&#8217; \u0432 \u043a\u043e\u043d\u0446\u0435 (\u044d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0442\u043e\u043d\u0430, \u043d\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 mapper (\u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u043e \u0437\u043e\u043d\u0430\u043c \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438)<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e<\/strong> @Mapper (org.mapstruct.Mapper), \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 <strong>MapStruct <\/strong>\u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e (\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c MapStruct \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u0434\u0430\u043d\u043d\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439, \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\/\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c), \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c componentModel (\u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Spring-framework \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435)<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b<\/strong> \u0432 \u043d\u0430\u0448 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u043e\u0437\u044c\u043c\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f <strong>MapStruct<\/strong><\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u0411\u0435\u0437 Spring:<\/p>\n<\/blockquote>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Spring, \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>INSTANCE <\/strong>\u0432\u043d\u0443\u0442\u0440\u0438 <strong>UserMapper <\/strong>interface, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<pre><code class=\"java\">@Mapper public interface UserMapper {      UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); \/\/add instance to call mapper      UserResponse toUserResponse(User user); \/\/map User to UserResponse      List&lt;UserResponse> toUserResponseList(List&lt;User> users); \/\/map list of User to list of UserResponse }<\/code><\/pre>\n<h2>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <strong>UserController<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"java\">@RestController @RequestMapping(\"\/api\/users\") @RequiredArgsConstructor public class UserController {      private final UserRepository userRepository;     private final UserMapper userMapper;      @GetMapping     public ResponseEntity&lt;List&lt;UserResponse>> findAll() {         List&lt;User> users = userRepository.findAll();         List&lt;UserResponse> userResponseList = userMapper.toUserResponseList(users);         return ResponseEntity.ok(userResponseList);     }      @GetMapping(\"\/{id}\")     public ResponseEntity&lt;UserResponse> findById(@PathVariable Long id) {         Optional&lt;User> user = userRepository.findById(id);         return user.isPresent()                 ? ResponseEntity.ok(userMapper.toUserResponse(user.get()))                 : ResponseEntity.notFound().build();     } }<\/code><\/pre>\n<blockquote>\n<p><em>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b <\/em><strong><em>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Spring<\/em><\/strong><em>, \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @RequiredArgsConstructor \u043e\u0442 <\/em><a href=\"https:\/\/habr.com\/ru\/companies\/piter\/articles\/676394\/\" rel=\"noopener noreferrer nofollow\"><em>Lombok<\/em><\/a><em>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 final \u043f\u043e\u043b\u0435\u0439 &#8212; \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043e\u0431\u044c\u0435\u043a\u0442\u044b UserRepository, UserMapper (Spring \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442 \u043d\u0430\u043c \u044d\u0442\u0438 \u043e\u0431\u044c\u0435\u043a\u0442\u044b \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 <\/em><a href=\"https:\/\/docs.spring.io\/spring-framework\/reference\/core\/beans\/dependencies\/factory-collaborators.html\" rel=\"noopener noreferrer nofollow\"><em>DI<\/em><\/a><em>)<\/em><\/p>\n<\/blockquote>\n<blockquote>\n<p><em>\u0411\u0435\u0437 Spring:<\/em><\/p>\n<\/blockquote>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b <strong>\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Spring<\/strong> &#8212; \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <strong>UserMapper<\/strong> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432 \u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435, \u0433\u0434\u0435 \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440:<\/p>\n<pre><code class=\"java\">private final UserMapper mapper = UserMapper.INSTANCE;<\/code><\/pre>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <strong>MapStruct<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d, \u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u043a\u0430\u043a @Mapper, \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u043d\u0430\u0448\u0435\u043c \u043c\u0430\u043f\u043f\u0435\u0440\u0435.<\/p>\n<blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u043e\u0439 <strong>\u043a\u043e\u0434 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b <\/strong>\u043d\u0430\u043c <strong>MapStruct<em> <\/em><\/strong><em>(\u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0436\u043c\u0435\u043c shift + shift \u0432 IntelijIdea  \u0438 \u0432\u0432\u0435\u0434\u0435\u043c \u0438\u043c\u044f UserMapperImpl \u0432 \u043f\u043e\u0438\u0441\u043a\u0435 Classes)<\/em><\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/98f\/f5c\/35c\/98ff5c35c71203b7897846d78b929207.png\" alt=\"\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f MapStruct \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 toUserResponse()\" title=\"\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f MapStruct \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 toUserResponse()\" width=\"1675\" height=\"1317\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/98f\/f5c\/35c\/98ff5c35c71203b7897846d78b929207.png\"\/><\/p>\n<div><figcaption>\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f MapStruct \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 toUserResponse()<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430: \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <strong>source<\/strong>-\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 null, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441 null \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u0438 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f get() \u043c\u0435\u0442\u043e\u0434\u044b \u0443 <strong>target<\/strong>-\u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<\/blockquote>\n<p><strong>\u0421\u0442\u043e\u043f\u043f<\/strong>.. source, target, <strong>\u0442\u044b \u043e \u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435<\/strong>?<\/p>\n<p>\u0427\u0442\u043e-\u0436, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u043d\u0430\u0448\u0435\u043c <strong>UserMapper<\/strong>:<\/p>\n<pre><code class=\"java\">UserResponse toUserResponse(User user);<\/code><\/pre>\n<blockquote>\n<p><strong><em>Source <\/em><\/strong><em>\u043e\u0431\u044a\u0435\u043a\u0442 &#8212; \u044d\u0442\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a, <\/em><strong><em>\u041e\u0422\u041a\u0423\u0414\u0410 <\/em><\/strong><em>\u043c\u044b \u0431\u0435\u0440\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e <\/em><strong><em>User<\/em><\/strong><em>. <\/em><\/p>\n<p><strong><em>Target <\/em><\/strong><em>\u043e\u0431\u044a\u0435\u043a\u0442 &#8212; \u044d\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, <\/em><strong><em>\u041a\u0423\u0414\u0410 <\/em><\/strong><em>\u043c\u044b \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e <\/em><strong><em>UserResponse<\/em><\/strong><em>.<\/em><\/p>\n<\/blockquote>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e MapStruct \u0431\u0435\u0440\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 <strong>\u0418\u0417 <\/strong>User \u0438 \u0441\u0442\u0430\u0432\u0438\u0442 \u0438\u0445 <strong>\u0412<\/strong> UserResponse. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u043d \u0431\u0435\u0440\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 UserResponse, \u0430 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u044f password \u0443 UserResponse \u043d\u0435\u0442, \u0437\u043d\u0430\u0447\u0438\u0442 \u043e\u043d\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f!<\/p>\n<p><em>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b MapStruct \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/em><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/afd\/fa0\/732\/afdfa073277954572ab145785a852c04.png\" alt=\"\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f MapStrcut \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 toUserResponseList()\" title=\"\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f MapStrcut \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 toUserResponseList()\" width=\"1418\" height=\"776\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/afd\/fa0\/732\/afdfa073277954572ab145785a852c04.png\"\/><\/p>\n<div><figcaption>\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f MapStrcut \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 toUserResponseList()<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p><em>\u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, <\/em><strong><em>MapStruct <\/em><\/strong><em>\u0434\u0435\u043b\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e <\/em><strong><em>\u0445\u0438\u0442\u0440\u0443\u044e \u0432\u0435\u0449\u044c<\/em><\/strong><em>: \u043e\u043d \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 <\/em><strong><em>users <\/em><\/strong><em>\u0438 \u043f\u0440\u043e\u0441\u0442\u043e <\/em><strong><em>\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <\/em><\/strong><em>\u0443\u0436\u0435 <\/em><strong><em>\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <\/em><\/strong><em>\u0440\u0430\u043d\u0435\u0435 <\/em><strong><em>\u043c\u0435\u0442\u043e\u0434 toUserResponse()<\/em><\/strong><em>, \u0432\u043e\u0442 \u0438 \u0432\u0441\u0435!                                                                            <\/em><\/p>\n<p><em>\u0422\u043e \u0435\u0441\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c List&lt;UserResponse>, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 User &#8212;> UserResponse, \u0430 \u0434\u043b\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0442\u0430\u043a\u0438\u0445 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 MapStruct \u043f\u0440\u043e\u0439\u0434\u0435\u0442\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c, \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434.<\/em><\/p>\n<\/blockquote>\n<hr\/>\n<p>\u042f \u0443\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b 1 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0443, \u0447\u0435\u0440\u0435\u0437 POST \u043c\u0435\u0442\u043e\u0434 (\u0435\u0433\u043e \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0434\u0430\u043b\u044c\u0448\u0435, \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0433\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430):<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1cf\/0ab\/6b7\/1cf0ab6b7208478b0c15da61807e6171.png\" width=\"1733\" height=\"224\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1cf\/0ab\/6b7\/1cf0ab6b7208478b0c15da61807e6171.png\"\/><\/figure>\n<p>\u041d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0441\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 &#8212; ID, email, password, username. <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0434\u0435\u043b\u0430\u0435\u043c GET \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 <em>(\u043d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0411\u0415\u0417 \u043f\u043e\u043b\u044f <\/em><strong><em>password<\/em><\/strong><em>, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u043a\u0440\u044b\u043b\u0438 \u0435\u0433\u043e \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 DTO UserResponse)<\/em>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a78\/ed1\/1bc\/a78ed11bca944307e5013c1301e77718.png\" alt=\"\u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 ID = 1\" title=\"\u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 ID = 1\" width=\"1616\" height=\"722\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a78\/ed1\/1bc\/a78ed11bca944307e5013c1301e77718.png\"\/><\/p>\n<div><figcaption>\u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 ID = 1<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043c\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 <strong>password<\/strong>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0445\u043e\u0442\u0435\u043b\u0438 \u0441\u043a\u0440\u044b\u0442\u044c \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430<strong>. <\/strong>\u0412\u0441\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043a\u0430\u043a \u043d\u0430\u0434\u043e &#8212; \u0432 \u0411\u0414 \u0432\u0441\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u043e\u0441\u044c \u043a\u0430\u043a \u0438 \u0434\u043e\u043b\u0436\u043d\u043e, \u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u0435\u043b UserResponse. <\/p>\n<p>\u0427\u0442\u043e \u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c? \u041e\u0442\u0432\u0435\u0442 \u043f\u0440\u043e\u0441\u0442: \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c User, \u0441 \u043f\u0430\u0440\u043e\u043b\u0435\u043c \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044c\u0435\u043a\u0442 (DTO) UserResponse, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043a\u0440\u044b\u043b\u0438 \u043f\u043e\u043b\u0435 <strong>password<\/strong> <em>(\u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u043d\u0435\u0442)<\/em>.<\/p>\n<h2>\u0411\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043c\u0430\u043f\u043f\u0438\u043d\u0433<\/h2>\n<p>\u041c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043c\u0430\u043f\u043f\u0438\u043d\u0433 <em>(\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u044e)<\/em>, \u043d\u043e \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0443?<\/p>\n<blockquote>\n<p><em>\u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, <\/em><strong><em>\u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 User<\/em><\/strong><em>, \u043c\u044b \u0445\u043e\u0442\u0438\u043c<\/em><strong><em> \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u043f\u0430\u0440\u043e\u043b\u044c<\/em><\/strong><em> (\u043a\u0430\u043a \u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445: \u043f\u0430\u0440\u043e\u043b\u044c \u0448\u0438\u0444\u0440\u0443\u044e\u0442 \u043f\u043e \u0441\u043a\u0440\u044b\u0442\u043e\u043c\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443, \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442 \u0435\u0433\u043e \u0432 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435, \u0430 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0432\u0445\u043e\u0434\u0430 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0448\u0438\u0444\u0440\u0443\u044e\u0442 \u043f\u0430\u0440\u043e\u043b\u044c \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0448\u0435\u043b \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0442 \u0441 \u0443\u0436\u0435 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u043e\u043b\u0435\u043c \u0432 \u0411\u0430\u0437\u0435 \u0414\u0430\u043d\u043d\u044b\u0445). <\/em><\/p>\n<p><em>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c \u0437\u043d\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0430 \u0441\u0430\u043c\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0445\u0440\u0430\u043d\u0438\u0442 \u0435\u0433\u043e \u0443\u0436\u0435 \u0432 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435.<\/em><\/p>\n<\/blockquote>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 <strong>\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <\/strong>\u043d\u043e\u0432\u0443\u044e DTO &#8212; <strong>UserCreateDto<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0d0\/81a\/5d4\/0d081a5d4123f1964ebb44a4673deb32.png\" width=\"517\" height=\"516\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0d0\/81a\/5d4\/0d081a5d4123f1964ebb44a4673deb32.png\"\/><\/figure>\n<blockquote>\n<p><em>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b <\/em><strong><em>\u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c<\/em><\/strong><em> <\/em><strong><em>UserCreateDto<\/em><\/strong><em>, \u0442.\u043a \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0435 \u0436\u0435 \u043f\u043e\u043b\u044f, \u0447\u0442\u043e \u0438 <\/em><strong><em>User<\/em><\/strong><em>, \u043d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 <\/em><strong><em>User <\/em><\/strong><em>\u0438\u043c\u0435\u0435\u0442 \u0430\u0443\u0434\u0438\u0442-\u043f\u043e\u043b\u044f, (\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a createdAt, updatedAt, \u0438 \u0434\u0440.), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0441\u0442\u0430\u0442\u0443\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u0440\u0438\u043c: CREATED) , \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e DTO (\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043b\u043e\u0434\u0438\u0442\u044c \u043c\u043d\u043e\u0433\u043e DTO-\u0448\u0435\u043a, \u0441\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u0432\u0435\u0437\u0434\u0435 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0433\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0430).<\/em><\/p>\n<\/blockquote>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c <strong>UserCreateDto<\/strong>:<\/p>\n<pre><code class=\"java\">public record UserCreateDto(         String username,         String email,         String password) { } <\/code><\/pre>\n<p><strong>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0435\u0442\u043e\u0434<\/strong> \u0434\u043b\u044f <strong>\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f <\/strong>UserCreateDto \u0432 User:<\/p>\n<pre><code class=\"java\">User fromUserCreateDto(UserCreateDto userCreateDto);<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 <strong>\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u043c<\/strong> \u043d\u0430\u0448 <strong>UserController<\/strong>, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 <a href=\"https:\/\/www.baeldung.com\/cs\/api-endpoints\" rel=\"noopener noreferrer nofollow\">endpoint<\/a> \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:<\/p>\n<pre><code class=\"java\">@PostMapping public ResponseEntity&lt;UserResponse> createUser(@RequestBody UserCreateDto userCreateDto) {     User user = userMapper.fromUserCreateDto(userCreateDto);     User savedUser = userRepository.save(user);     UserResponse userResponse = userMapper.toUserResponse(savedUser);     return ResponseEntity.ok(userResponse); }<\/code><\/pre>\n<h2>@Mapping &#8212; \u043a\u0442\u043e \u0442\u044b, \u0432\u043e\u0438\u043d?<\/h2>\n<p>\u0417\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c, \u0414\u0436\u043e \u0411\u043b\u044d\u043a.. \u0428\u0443\u0447\u0443, <strong>@Mapping<\/strong>.<\/p>\n<blockquote>\n<p><strong><em>@Mapping<\/em><\/strong><em> &#8212; \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0442\u044b\u0441\u044f\u0447\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u0442.\u043a \u044d\u0442\u043e \u0437\u0430\u0439\u043c\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0438 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e.<\/em><\/p>\n<\/blockquote>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u044b \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u043f\u0440\u043e <strong>target <\/strong>\u0438 <strong>source<\/strong>: \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0447\u0442\u043e\u0431\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u043d\u0430\u043c \u0431\u0440\u0430\u0442\u044c \u0434\u043b\u044f \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430. <\/p>\n<h2>@Mapping(defaultValue)<\/h2>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"java\">@Mapping(target = \"password\", defaultValue = \"pass123\") User fromUserCreateDto(UserCreateDto userCreateDto);<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<p><em>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e MapStruct, \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0432 \u043f\u043e\u043b\u0435 <\/em><strong><em>password <\/em><\/strong><em>\u043d\u0430\u0448\u0435\u0433\u043e <\/em><strong><em>target <\/em><\/strong><em>\u043e\u0431\u044a\u0435\u043a\u0442\u0430 User<\/em><strong><em> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/em><\/strong><em> (&#171;pass123&#187;), \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0430\u0440\u043e\u043b\u044c \u0438\u0437 <\/em><strong><em>userCreateDto <\/em><\/strong><em>\u0431\u0443\u0434\u0435\u0442 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 fromUserCreateDto \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0430\u043c User \u0441 \u043f\u043e\u043b\u0435\u043c password = &#171;pass123&#187;<\/em><\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c <strong>\u0437\u0430\u043f\u0440\u043e\u0441<\/strong> <strong>\u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435<\/strong> \u043d\u0430\u0448\u0435\u0433\u043e <strong>User<\/strong> \u0441 \u043f\u0430\u0440\u043e\u043b\u0435\u043c &#171;our-custom-password-222&#187;:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b68\/be4\/724\/b68be4724911e0b4057a59f89d4912cb.png\" alt=\"\u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User\" title=\"\u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User\" width=\"1735\" height=\"1036\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b68\/be4\/724\/b68be4724911e0b4057a59f89d4912cb.png\"\/><\/p>\n<div><figcaption>\u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043f\u0430\u0440\u043e\u043b\u044c <em>(\u043c\u044b \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0443, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0430\u043d\u0435\u0435)<\/em>, \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0447\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u043e\u0441\u044c. \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8d0\/c96\/d21\/8d0c96d21cf7844946abd31425df1479.png\" alt=\"\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User\" title=\"\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User\" width=\"1750\" height=\"227\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8d0\/c96\/d21\/8d0c96d21cf7844946abd31425df1479.png\"\/><\/p>\n<div><figcaption>\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043c\u044b <strong>\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438<\/strong> <strong>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/strong> \u0441 \u043f\u0430\u0440\u043e\u043b\u0435\u043c &#171;our-custom-password-222&#187;, \u0430 \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0432 \u0431\u0430\u0437\u0443 <strong>\u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0441\u044c<\/strong> <strong>\u0441\u043e\u0432\u0441\u0435\u043c<\/strong> <strong>\u0434\u0440\u0443\u0433\u043e\u0435<\/strong> <strong>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong> \u043f\u043e\u043b\u044f password &#8212; &#171;test123&#187;.<\/p>\n<p><strong><em>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e:<\/em><\/strong><\/p>\n<ol>\n<li>\n<p>\u041c\u044b <strong>\u043f\u043e\u0441\u043b\u0430\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435<\/strong> <strong>User<\/strong> \u0441 \u043f\u043e\u043b\u044f\u043c\u0438 <em>(\u043f\u0435\u0440\u0432\u044b\u0439 POST-\u0437\u0430\u043f\u0440\u043e\u0441)<\/em> \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u044b\u0448\u0435<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <strong>\u0432\u044b\u0437\u0432\u0430\u043b\u0441\u044f \u043a\u043e\u0434<\/strong>:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"java\">User user = userMapper.fromUserCreateDto(userCreateDto); User savedUser = userRepository.save(user);<\/code><\/pre>\n<p>\u0412 \u0445\u043e\u0434\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b <strong>\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b\u0438 UserCreateDto \u0432 User<\/strong>, \u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043f\u043e\u043b\u0435 password  \u0441\u0430\u043c\u044b\u043c \u0432 User <strong>\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0441\u044f \u043f\u0430\u0440\u043e\u043b\u044c<\/strong> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c defaultValue = &#171;pass123&#187;, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @Mapping. <\/p>\n<blockquote>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c <strong>\u043c\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u0438<\/strong>, \u0447\u0442\u043e <strong>defaultValue<\/strong> <strong>\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442<\/strong> <strong>\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435<\/strong> <strong>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong> \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439, \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<\/blockquote>\n<h2>@Mapping(ignore)<\/h2>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0435\u043d<\/strong> &#8212; \u043e\u043d \u0433\u043e\u0432\u043e\u0440\u0438\u0442 <strong>MapStruct<\/strong>, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u043e\u0435 <strong>\u043f\u043e\u043b\u0435<\/strong> \u043c\u044b <strong>\u0434\u043e\u043b\u0436\u043d\u044b<\/strong> <strong>\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong>:<\/p>\n<pre><code class=\"java\">@Mapping(target = \"email\", ignore = true) UserResponse toUserResponse(User user);<\/code><\/pre>\n<blockquote>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>&#171;ignore&#187;<\/strong> \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c <strong>MapStruct<\/strong>: <strong>\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0439<\/strong> \u043f\u043e\u043b\u0435 <strong>email <\/strong>\u043f\u0440\u0438 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0435. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <strong>user.email<\/strong> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0438 \u0432 <strong>UserResponse <\/strong>\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<em> (\u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b MapStruct \u043d\u0435 \u0440\u0443\u0433\u0430\u043b\u0441\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u043d\u0435\u0442\u0443 \u0443 <\/em><strong><em>source<\/em><\/strong><em>-\u043e\u0431\u044a\u0435\u043a\u0442\u0430)<\/em> <\/p>\n<\/blockquote>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f <strong>User<\/strong> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2bc\/52e\/bb0\/2bc52ebb05137b7fcebfe01d2ce2d621.png\" alt=\"\u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u043f\u043e\u043b\u0435 &quot;email&quot; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u044b\u043c\" title=\"\u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u043f\u043e\u043b\u0435 &quot;email&quot; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u044b\u043c\" width=\"1599\" height=\"721\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2bc\/52e\/bb0\/2bc52ebb05137b7fcebfe01d2ce2d621.png\"\/><\/p>\n<div><figcaption>\u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u043f\u043e\u043b\u0435 &#171;email&#187; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u044b\u043c<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p><em>\u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u043c\u0435\u0435\u043c <\/em><strong><em>\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0439<\/em><\/strong><em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0435, \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c <\/em><strong><em>@Mapping(ignore = true)<\/em><\/strong><em> \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043e\u043b\u0433\u043e.<\/em><\/p>\n<\/blockquote>\n<p>\u0418 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0443 MapStruct <strong>\u0435\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/strong>: \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <strong>unmappedTargetPolicy <\/strong>\u0443 @Mapper<strong>, <\/strong>\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c MapStruct \u043d\u0430 \u0442\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 source:<\/p>\n<ul>\n<li>\n<p><strong><em>ERROR <\/em><\/strong><em>&#8212; \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442<\/em><\/p>\n<\/li>\n<li>\n<p><strong><em>WARN<\/em><\/strong><em> (default) &#8212; \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0435 \u043a\u0440\u0430\u0441\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435 \u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442<\/em><\/p>\n<\/li>\n<li>\n<p><strong><em>IGNORE <\/em><\/strong><em>&#8212; \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u043c\u0430\u043f\u043f\u0438\u0442\u044c (\u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u044d\u0444\u0444\u0435\u043a\u0442, \u043a\u0430\u043a \u043e\u0442 &#171;ignore = true&#187;)<\/em><\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p><em>\u0412 \u043a\u043e\u0434\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/em><\/p>\n<\/blockquote>\n<pre><code class=\"java\">@Mapper(componentModel = MappingConstants.ComponentModel.SPRING,         unmappedTargetPolicy = ReportingPolicy.IGNORE )<\/code><\/pre>\n<h2>@Mapping(expression)<\/h2>\n<p><strong>Expression <\/strong>&#8212; \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 Java \u043a\u043e\u0434. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u0430\u043a \u0432\u043d\u0443\u0442\u0440\u0438 UserMapper, \u0442\u0430\u043a \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438. <\/p>\n<p><em>\u041a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c <\/em><strong><em>\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f<\/em><\/strong><em> <\/em><strong><em>\u0432 <\/em><\/strong><em>\u043f\u043e\u043b\u0435 <\/em><strong><em>password <\/em><\/strong><em>\u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u043e\u043b\u044f:<\/em><\/p>\n<pre><code>@Mapping(target = \"password\", expression = \"java(LocalDate.now().toString())\") User fromUserCreateDto(UserCreateDto userCreateDto);<\/code><\/pre>\n<p><strong>\u0412\u0430\u0436\u043d\u043e!<\/strong> <\/p>\n<blockquote>\n<p><strong>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e<\/strong> <strong>\u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u043d\u0444\u0438\u0433<\/strong>, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0438\u043c\u043f\u043e\u0440\u0442\u044b LocalDate.class <em>(\u0438\u043d\u0430\u0447\u0435 MapStruct \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432 expression, \u0438 \u0432\u044b\u043a\u0438\u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c)<\/em><\/p>\n<\/blockquote>\n<p><em>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0447\u0435\u0440\u0435\u0437 <\/em><strong><em>POST<\/em><\/strong><em> \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, <\/em><strong><em>\u043a\u0430\u043a\u0438\u0435<\/em><\/strong><em> <\/em><strong><em>\u0434\u0430\u043d\u043d\u044b\u0435<\/em><\/strong><em> \u043b\u0435\u0436\u0430\u0442 <\/em><strong><em>\u0432<\/em><\/strong><em> <\/em><strong><em>\u0411\u0414<\/em><\/strong><em>:<\/em><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e40\/a96\/a8a\/e40a96a8a28a5d5d66c94f1cfa49c39f.png\" alt=\"\u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u043b\u0435 password \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0430\u0441\u044c \u0434\u0430\u0442\u0430\" title=\"\u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u043b\u0435 password \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0430\u0441\u044c \u0434\u0430\u0442\u0430\" width=\"1742\" height=\"224\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e40\/a96\/a8a\/e40a96a8a28a5d5d66c94f1cfa49c39f.png\"\/><\/p>\n<div><figcaption>\u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u043b\u0435 password \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0430\u0441\u044c \u0434\u0430\u0442\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0432 \u043f\u043e\u043b\u0435 <strong>password<\/strong> \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u043e\u0441\u044c <strong>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong> <strong>\u0442\u0435\u043a\u0443\u0449\u0435\u0439<\/strong> <strong>\u0434\u0430\u0442\u044b<\/strong>, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e <strong>\u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0441\u044f \u043f\u0430\u0440\u043e\u043b\u044c<\/strong>.<\/p>\n<h2>@Named \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/h2>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e <strong>expression <\/strong>\u043d\u0430\u043c <strong>\u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442<\/strong> &#8212; \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443<\/strong>. \u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @Named \u0438 <a href=\"https:\/\/javarush.com\/groups\/posts\/1984-defoltnihe-metodih-v-interfeysakh\" rel=\"noopener noreferrer nofollow\"><strong>\u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b<\/strong><\/a>.<\/p>\n<blockquote>\n<p><em>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 <\/em><strong><em>\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c<\/em><\/strong><em> <\/em><strong><em>default-\u043c\u0435\u0442\u043e\u0434<\/em><\/strong><em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 <\/em><strong><em>\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c<\/em><\/strong><em> <\/em><strong><em>\u043f\u0430\u0440\u043e\u043b\u044c<\/em><\/strong><em> \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0435: \u0431\u0440\u0430\u0442\u044c \u043d\u0435\u043a\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a \u043d\u0435\u0439 \u0441\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/em><\/p>\n<\/blockquote>\n<pre><code class=\"java\">default String getPasswordFromUsername(String username) {     return username + \" generatedPassword222\"; }<\/code><\/pre>\n<blockquote>\n<p><em>\u0422\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 <\/em><strong><em>@Mapping<\/em><\/strong><em> \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e <\/em><strong><em>\u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f<\/em><\/strong><em>:<\/em><\/p>\n<\/blockquote>\n<pre><code class=\"java\">@Mapping(target = \"password\", expression = \"java(getPasswordFromUsername(userCreateDto.username()))\") User fromUserCreateDto(UserCreateDto userCreateDto);<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0430\u0448\u0435\u0433\u043e <strong>UserMapper<\/strong>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <strong>get()-\u043c\u0435\u0442\u043e\u0434<\/strong> \u0443 <strong>userCreateDto<\/strong> <em>(\u0433\u0435\u0442\u0442\u0435\u0440\u044b \u0443 record-\u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438\u043c\u0435\u043d\u0443\u044e\u0442\u0441\u044f \u0431\u0435\u0437 get-\u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430)<\/em><\/p>\n<blockquote>\n<p><em>\u0414\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441, \u0438\u0438..<\/em><\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/db2\/44e\/7aa\/db244e7aa4600828bd1456013248019b.png\" alt=\"\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443\" title=\"\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443\" width=\"1591\" height=\"641\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/db2\/44e\/7aa\/db244e7aa4600828bd1456013248019b.png\"\/><\/p>\n<div><figcaption>\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443<\/figcaption><\/div>\n<\/figure>\n<p>\u0427\u0442\u043e \u0437\u0430 \u043f\u0440\u0438\u043a\u043e\u043b\u044b, \u0441\u043a\u0430\u0436\u0435\u0442\u0435 \u0432\u044b?<\/p>\n<p><strong>\u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e:<\/strong><\/p>\n<blockquote>\n<p><strong>MapStruct <\/strong>\u0441\u043a\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u044b, \u0438 \u0435\u0441\u043b\u0438 \u0432\u0438\u0434\u0438\u0442, \u0447\u0442\u043e <strong>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043c\u0435\u0442\u043e\u0434\u0430<\/strong> \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 &#8212; \u0441\u043c\u0435\u043b\u043e <strong>\u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u044d\u0442\u043e \u043a\u043e \u0432\u0441\u0435\u043c \u043f\u043e\u043b\u044f\u043c<\/strong>. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f String &#8212; \u0438 MapStruct \u0441\u043c\u0435\u043b\u043e \u043d\u0430\u043a\u0438\u0434\u0430\u043b \u043d\u0430\u043c \u043d\u0435\u043d\u0443\u0436\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<\/blockquote>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c! \u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0438\u0434\u0435\u0442 @Named &#8212; \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0438\u0445 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>qualifiedByName <\/strong>&#8212; \u043d\u043e \u043a \u043d\u0435\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435<\/p>\n<\/li>\n<\/ul>\n<p><strong><em>\u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434<\/em><\/strong><em>:<\/em><\/p>\n<pre><code class=\"java\">@Named(\"getPasswordFromUsername\") default String getPasswordFromUsername(String username) {     return username + \" generatedPassword222\"; }<\/code><\/pre>\n<p><strong><em>\u0418 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/em><\/strong><em>:<\/em><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c6a\/45a\/f17\/c6a45af176ec204b8849aab91be126c7.png\" alt=\"\u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User\" title=\"\u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User\" width=\"1988\" height=\"227\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c6a\/45a\/f17\/c6a45af176ec204b8849aab91be126c7.png\"\/><\/p>\n<div><figcaption>\u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User<\/figcaption><\/div>\n<\/figure>\n<h2>@Mapping(qualifiedByName)<\/h2>\n<blockquote>\n<p><em>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0438 <\/em><strong><em>default getPasswordFromUsername()<\/em><\/strong><em> \u043c\u0435\u0442\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 <\/em><strong><em>expression <\/em><\/strong><em>&#8212; <\/em><strong><em>\u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/em><\/strong><em>. \u0415\u0433\u043e \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434. \u0412 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <\/em><strong><em>qualifiedByName()<\/em><\/strong><\/p>\n<\/blockquote>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b <strong>\u043d\u0435<\/strong> <strong>\u0431\u0443\u0434\u0435\u043c<\/strong> <strong>\u043c\u0435\u043d\u044f\u0442\u044c<\/strong> <strong>\u043b\u043e\u0433\u0438\u043a\u0443<\/strong> \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u043e\u043b\u044f &#8212; \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0432\u0441\u0435 \u043a\u0430\u043a \u0435\u0441\u0442\u044c. \u042f \u043b\u0438\u0448\u044c \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <strong>qualifiedByName<\/strong><\/p>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448 <strong>UserMapper<\/strong>:<\/p>\n<pre><code class=\"java\">@Mapping(target = \"password\", qualifiedByName = \"getPasswordFromUsername\", source = \"username\") User fromUserCreateDto(UserCreateDto userCreateDto);  @Named(\"getPasswordFromUsername\") default String getPasswordFromUsername(String username) {     return username + \" generatedPassword222\"; }<\/code><\/pre>\n<p><em>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u043a\u0430\u043a\u0438\u0435 <\/em><strong><em>\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/em><\/strong><em> \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0438:<\/em><\/p>\n<ol>\n<li>\n<p>\u041c\u044b <strong>\u0443\u0431\u0440\u0430\u043b\u0438<\/strong> <strong>expression<\/strong>, \u0438 <strong>\u0443\u043a\u0430\u0437\u0430\u043b\u0438<\/strong> <strong>qualifiedByName = &#171;getPasswordFromUsername&#187;<\/strong>, \u0433\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u0442\u043e\u0438\u0442 \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @Named<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b <strong>\u0443\u043a\u0430\u0437\u0430\u043b\u0438 source = &#171;username&#187;<\/strong>, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u0434\u043b\u044f MapStruct \u0432\u0437\u044f\u0442\u044c <strong>username <\/strong>\u0438\u0437 userCreateDto, \u043a\u043e\u0433\u0434\u0430 \u0442\u043e\u0442 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <strong>getPasswordFromUsername(), <\/strong>\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430<\/p>\n<\/li>\n<\/ol>\n<blockquote>\n<p><em>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, <\/em><strong><em>qualifiedByName <\/em><\/strong><em>\u0441\u043b\u0443\u0436\u0438\u0442 \u043d\u0435\u043a\u0438\u043c \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 MapStruct, \u043a\u0430\u043a\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u0435\u0442\u043e\u0434 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0445 \u0432 <\/em><strong><em>source<\/em><\/strong><em>.<\/em><\/p>\n<\/blockquote>\n<h2>\u0412\u044b\u043d\u0435\u0441\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b<\/h2>\n<blockquote>\n<p><em>\u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u0430\u0442\u044c\u0438, \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d <\/em><strong><em>\u0441\u043f\u043e\u0441\u043e\u0431<\/em><\/strong><em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 <\/em><strong><em>\u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442<\/em><\/strong><em> <\/em><strong><em>\u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c<\/em><\/strong><em> <\/em><strong><em>\u0433\u043e\u043b\u043e\u0432\u043d\u043e\u0439<\/em><\/strong><em> <\/em><strong><em>\u0431\u043e\u043b\u0438<\/em><\/strong><em>, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u044f.<\/em><\/p>\n<\/blockquote>\n<p><strong>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c<\/strong>, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c <strong>\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/strong> \u0434\u043b\u044f UserMapper (\u0432 \u043d\u0435\u043c \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0431\u0440\u0430\u043d\u044b \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430, \u0430 \u0432\u0430\u0448 UserMapper \u0431\u0443\u0434\u0435\u0442 <strong>\u0447\u0438\u0441\u0442 \u043a\u0430\u043a \u043c\u043b\u0430\u0434\u0435\u043d\u0435\u0446<\/strong>, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e util-\u043a\u043b\u0430\u0441\u0441\u0430)<\/p>\n<p><strong><em>\u0422\u0430\u043a\u043e\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442:<\/em><\/strong><\/p>\n<ol>\n<li>\n<p>\u0423\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 <strong>UserMapper<\/strong>, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u043c\u0430\u043f\u043f\u044f\u0442\u0441\u044f, \u0438 \u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c <strong>\u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432 \u0447\u0438\u0441\u0442\u043e\u0442\u0443 \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0442\u0430\u043d\u0446\u0435\u0432 \u0441 \u0431\u0443\u0431\u043d\u043e\u043c<\/strong>, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0431\u0438\u043d\u044b \u0432 mapper. \u0412 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0438\u0431\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043b\u0438\u0431\u043e \u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u044f \u0435\u0449\u0435 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b <em>(\u043f\u043e\u0442\u043e\u043c\u0443 \u0434\u0435\u043b\u0430\u043b abstract class \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b \u0442\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u0431\u0438\u043d\u044b, \u043f\u043e\u043c\u0435\u0447\u0430\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 @Autowired)<\/em><\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c!<\/p>\n<\/li>\n<\/ol>\n<p><em>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c <\/em><strong><em>UserMapperUtil <\/em><\/strong><em>\u0432 \u043f\u0430\u043f\u043a\u0435 ustils.mapper, \u043a\u0443\u0434\u0430 \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430:<\/em><\/p>\n<pre><code class=\"java\">@Named(\"UserMapperUtil\") @Component @RequiredArgsConstructor public class UserMapperUtil {      private final Random randomGenerator;      @Named(\"getPasswordFromUsername\")     public String getPasswordFromUsername(String username) {         return username + randomGenerator.nextInt(5000) + 2222;     } }<\/code><\/pre>\n<p>\u041c\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 <strong>@Named \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430<\/strong>, \u0447\u0442\u043e\u0431\u044b \u0432 UserMapper <strong>\u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430<\/strong>. <\/p>\n<p>\u0411\u0438\u043d <strong>Random <\/strong>\u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0432 <strong>ApplicationConfig <\/strong>\u043a\u043b\u0430\u0441\u0441\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0442\u044c \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 &#8212; \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 Util \u043a\u043b\u0430\u0441\u0441\u044b, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c <strong>\u0432\u044b\u043d\u043e\u0441\u044f \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443<\/strong> \u0438\u0437 UserMapper \u0432 \u0443\u0442\u0438\u043b\u0438\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b.<\/p>\n<pre><code class=\"java\">@Configuration public class ApplicationConfig {      @Bean     public Random randomGenerator() {         return new Random(System.currentTimeMillis() \/ 72);     } }<\/code><\/pre>\n<p><em>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 &#8212; <\/em><strong><em>\u043f\u043e\u043c\u0435\u043d\u044f\u0435\u043c<\/em><\/strong><em> \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <\/em><strong><em>UserMapper<\/em><\/strong><em>:<\/em><\/p>\n<pre><code class=\"java\">@Mapper(componentModel = MappingConstants.ComponentModel.SPRING,         uses = {                 UserMapperUtil.class         },         imports = {                 LocalDate.class         }) public interface UserMapper {      UserResponse toUserResponse(User user); \/\/map User to UserResponse      List&lt;UserResponse> toUserResponseList(List&lt;User> users); \/\/map list of User to list of UserResponse      @Mapping(target = \"password\", qualifiedByName = {\"UserMapperUtil\", \"getPasswordFromUsername\"}, source = \"username\")     User fromUserCreateDto(UserCreateDto userCreateDto); }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b <strong>\u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 uses \u0432 @Mapper \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e<\/strong>, \u0447\u0442\u043e\u0431\u044b MapStruct \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u0438\u043b \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0432 \u0446\u0435\u043b\u044f\u0445 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430, \u0430 <strong>\u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435<\/strong> &#8212; \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438\u0441\u044c \u043a \u043c\u0435\u0442\u043e\u0434\u0443 \u0443\u0442\u0438\u043b\u0438\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0432 @Named \u0443 <strong>UserMapperUtil <\/strong>\u0432 qualifiedByName = {&#171;UserMapperUtil&#187;, &#171;getPasswordFromUsername&#187;}<\/p>\n<blockquote>\n<p><em>\u0422\u0435\u043f\u0435\u0440\u044c<\/em><strong><em> \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c<\/em><\/strong><em> \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u043d\u043e\u0432\u0430, \u0438 \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c <\/em><strong><em>User<\/em><\/strong><em>:<\/em><\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f2e\/b3d\/a09\/f2eb3da092da32ab33947e34eb18277d.png\" alt=\"\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e randomGenerator\" title=\"\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e randomGenerator\" width=\"1976\" height=\"186\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f2e\/b3d\/a09\/f2eb3da092da32ab33947e34eb18277d.png\"\/><\/p>\n<div><figcaption>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e randomGenerator<\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0432\u0441\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e! \u041d\u0430\u0448 <strong>randomGenerator <\/strong>\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043a username.<\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/h2>\n<p><em>E\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0442\u044f\u043d\u0443\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 &#8212; \u043f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u044f\u044e! <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0432\u0430\u043c \u0441\u0442\u0430\u043b\u043e \u0447\u0443\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u0438 \u043f\u0440\u043e\u0449\u0435, \u0430 \u0435\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0438\u0437\u0443\u0447\u0438\u0442\u044c <\/em><strong><em>MapStruct<\/em><\/strong><em> \u043f\u043e\u043b\u0443\u0447\u0448\u0435, \u043b\u0438\u0441\u0442\u0430\u0439\u0442\u0435 \u0432\u043d\u0438\u0437!<\/em><\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7ba\/76a\/179\/7ba76a179e14d032acfc19f46125945a.png\" width=\"900\" height=\"900\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ba\/76a\/179\/7ba76a179e14d032acfc19f46125945a.png\"\/><\/figure>\n<p>\u0421\u043f\u0438\u0441\u043e\u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0435\u043c\u0443 MapStruct \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/www.baeldung.com\/mapstruct\" rel=\"noopener noreferrer nofollow\"><strong>Baeldung: Quick Guide to MapStruct<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.baeldung.com\/java-mapstruct-mapping-collections\" rel=\"noopener noreferrer nofollow\"><strong>Baeldung: Mapping Collections<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.baeldung.com\/mapstruct-custom-mapper\" rel=\"noopener noreferrer nofollow\"><strong>Baeldung: Custom Mapper<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=aRxVnS1tm7w\" rel=\"noopener noreferrer nofollow\"><strong>Mapstruct Entity to DTO: \u0432\u0438\u0434\u0435\u043e \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=5yquJa2x3Ko\" rel=\"noopener noreferrer nofollow\"><strong>Amigoscode: DTO<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.youtube.com\/playlist?list=PLF5X0J2bZ_k42wt16-EWfOa2QEGFfPmMS\" rel=\"noopener noreferrer nofollow\"><strong>Youtube playlist<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.baeldung.com\/mapstruct-ignore-unmapped-properties\" rel=\"noopener noreferrer nofollow\"><strong>Baeldung: ignoring properties<\/strong><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/mapstruct.org\/documentation\/stable\/reference\/html\/\" rel=\"noopener noreferrer nofollow\"><strong>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/strong><\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/818489\/\"> https:\/\/habr.com\/ru\/articles\/818489\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/strong> <a href=\"https:\/\/github.com\/yayauheny\/javanotice-mapstruct\" rel=\"noopener noreferrer nofollow\">github<\/a><\/p>\n<blockquote>\n<p><em>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u044f\u043c\u0438 \u043a\u0430\u043a <\/em><strong><em>DTO<\/em><\/strong><em>, <\/em><strong><em>Mapping<\/em><\/strong><em>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f (\u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0434\u043e\u043f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u043f\u043e \u0442\u0435\u043c\u0435).<\/em><\/p>\n<\/blockquote>\n<figure class=\"full-width\">\n<div><figcaption>MapStruct<\/figcaption><\/div>\n<\/figure>\n<p>\u042f \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b \u043d\u0430 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0435\u043c\u0430\u043b\u043e \u043d\u0435\u0440\u0432\u043d\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a, \u0438 \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0443\u0437\u043d\u0430\u043b \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0438 \u043b\u0430\u0439\u0444\u0445\u0430\u043a\u0438, \u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0442\u0430\u0440\u0442\u0430 \u043d\u0435 \u0438\u0441\u043f\u044b\u0442\u044b\u0432\u0430\u043b\u0438 &#171;\u043d\u0435\u0436\u0434\u0430\u043d\u0447\u0438\u043a\u043e\u0432&#187; \u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043b\u0438 \u0441\u0432\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u0445 \u043d\u0430\u0439\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431.<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<p><strong><em>\u0421\u041f\u041e\u0419\u041b\u0415\u0420<\/em><\/strong><em>: \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u044f \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0441\u043b\u043e\u0439 <\/em><strong><em>service<\/em><\/strong><em>, \u0430 \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0441\u044c \u043a <\/em><strong><em>repository <\/em><\/strong><em>\u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0438 \u0442\u0430\u043a\u0436\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u0441\u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u0435\u043c\u0435.<\/em><\/p>\n<\/div>\n<\/details>\n<h2>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p><strong>\u0421\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e<\/strong>: \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u043b\u0435\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <strong>User<\/strong> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a: <strong>id, username, email, password<\/strong>.<\/p>\n<div class=\"floating-image\">\n<figure class=\"\">\n<div><figcaption>\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c User<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c <strong>\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435<\/strong>, \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/555760\/\" rel=\"noopener noreferrer nofollow\">\u0411\u0414 <\/a>(\u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445), \u0438 \u0437\u0430\u0442\u0435\u043c <strong>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong>, \u0430 \u0442\u0430\u043a\u0436\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA_%D0%BA%D0%BE%D0%B4%D0%BE%D0%B2_%D1%81%D0%BE%D1%81%D1%82%D0%BE%D1%8F%D0%BD%D0%B8%D1%8F_HTTP\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u0443\u0441<\/a>, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u0443\u0441\u043f\u0435\u0445 \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0443).<\/p>\n<p><strong><em>\u0412\u043e\u043f\u0440\u043e\u0441<\/em><\/strong><em>: \u043a\u0430\u043a \u0432\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u043e\u043b\u0435 <\/em><strong><em>password<\/em><\/strong><em> \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f? <\/em><\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<p><strong><em>\u0421\u043f\u043e\u0439\u043b\u0435\u0440<\/em><\/strong><em>: \u043d\u0435\u0442!<\/em><\/p>\n<\/div>\n<\/details>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e <strong>\u043e\u0431\u043d\u0443\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u0435 password,<\/strong> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0443 &#8212; \u043d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c <strong>\u0437\u0430\u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0431\u043d\u0443\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f<\/strong>, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 &#8212; \u0430 \u0442\u0430\u043c \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 <strong>\u043c\u043e\u0433\u0443\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c<\/strong> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0438\u0445 \u0446\u0435\u043b\u044f\u0445 <em>(\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440 &#8212; \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043d\u0430\u0448 API).<\/p>\n<p><\/em>\u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <strong>\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 UserResponse<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 <strong>\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f DTO<\/strong>, \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u043f\u043e\u043b\u0435 <strong>password<\/strong>, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"\">\n<div><figcaption>\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c UserResponse<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p><em>\u041c\u044b, \u043a\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435. \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b, \u043b\u0438\u0431\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0441\u043e\u0431\u0443\u044e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0435 <\/em><strong><em>password<\/em><\/strong><em> &#8212; \u043f\u0430\u0440\u043e\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f), \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u0445 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 (\u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0448 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441, \u043b\u0438\u0431\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440, \u043b\u0438\u0431\u043e \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443)<\/em><\/p>\n<\/blockquote>\n<p><em>\u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f: <\/em><a href=\"https:\/\/habr.com\/ru\/articles\/495698\/\" rel=\"noopener noreferrer nofollow\"><em>\u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430<\/em><\/a><em> \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0439, \u043a\u0442\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c. \u0410 \u0442\u043e\u0442, \u043a\u0442\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0445, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c. \u0422\u043e \u0435\u0441\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u0434\u0430\u0436\u0435 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<br \/><\/em><\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p><em>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e <\/em><strong><em>DTO (Data transfer object) &#8212; \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/em><\/strong><em>, \u0441\u043c\u044b\u0441\u043b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f <\/em><strong><em>\u0432 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/em><\/strong><em>. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c <\/em><strong><em>DTO<\/em><\/strong><em> \u043e\u0431\u044c\u0435\u043a\u0442 (\u0435\u0441\u043b\u0438 \u0442\u043e\u0433\u043e  \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0430), \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <\/em><strong><em>id<\/em><\/strong><em>, <\/em><strong><em>username<\/em><\/strong><em>, <\/em><strong><em>email<\/em><\/strong><em>).<\/em><\/p>\n<\/blockquote>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, <strong>DTO <\/strong>&#8212; \u044d\u0442\u043e <strong>\u043e\u0431\u044b\u0447\u043d\u044b\u0439 Java \u043e\u0431\u044a\u0435\u043a\u0442<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u0438\u0437\u043d\u0435\u0441 \u043c\u043e\u0434\u0435\u043b\u0438 <em>(\u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u043d\u0430\u0448 User &#8212; \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445)<\/em>, \u043d\u043e \u0441\u043b\u0443\u0436\u0438\u0442 \u043d\u0435\u043a\u0438\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c <em>(\u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 &#8212; \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445).<\/em><\/p>\n<h2>Mapping: \u0447\u0442\u043e \u0442\u044b, \u0447\u0435\u0440\u0442 \u0432\u043e\u0437\u044c\u043c\u0438, \u0442\u0430\u043a\u043e\u0435?<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443: <strong>\u043a\u0430\u043a<\/strong> \u043d\u0430\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e <strong>\u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438<\/strong> <strong>\u043e\u0431\u044a\u0435\u043a\u0442 User \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443 UserResponse? <\/p>\n<p><\/strong>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0432 \u0438\u0433\u0440\u0443 \u0432\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 <strong>\u043c\u0430\u043f\u043f\u0438\u043d\u0433 <\/strong><em>(eng: mapping), <\/em>\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 X \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 Y, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>User &#8212;> UserResponse. <br \/><\/strong><\/p>\n<blockquote>\n<p><em>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438: \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u043d\u0443\u0436\u0435\u043d \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043f\u043e\u043b\u044f \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c.<\/em><\/p>\n<\/blockquote>\n<h2>MapStruct: \u0441\u043c\u0430\u043f\u043f\u044c \u043c\u0435\u043d\u044f, \u0435\u0441\u043b\u0438 \u0441\u043c\u043e\u0436\u0435\u0448\u044c<\/h2>\n<p><a href=\"https:\/\/mapstruct.org\/documentation\/stable\/reference\/html\/\" rel=\"noopener noreferrer nofollow\"><strong>MapStruct<\/strong> <\/a>&#8212; \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e \u0441\u0443\u0442\u0438 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043f\u043f\u0435\u0440\u043e\u043c. \u041c\u0430\u043f\u043f\u0435\u0440\u043e\u0432 \u0431\u044b\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e, \u043d\u043e <strong>\u0441\u0430\u043c\u044b\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0439<\/strong> &#8212; MapStruct.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u043f\u043f\u0435\u0440\u0430 \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0440\u0443\u043a\u0430\u043c\u0438 <em>(\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043b\u0430\u0441\u0442\u044c \u0442\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0430\u0448 DTO)<\/em>, \u0432\u0441\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043d\u0443 \u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0438..<\/p>\n<p><strong><em>\u0417\u0430\u0447\u0435\u043c \u043d\u0430\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0443\u0436\u0435\u043d \u043c\u0430\u043f\u043f\u0435\u0440, \u043a \u0447\u0435\u043c\u0443 \u043b\u0438\u0448\u043d\u0438\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438?<\/em><\/strong><em> <br \/><\/em><\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<p><em>\u0425\u043e\u0440\u043e\u0448\u0438\u0439 \u0432\u043e\u043f\u0440\u043e\u0441. \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438, \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 (\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f, \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \/ enum-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 (\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u043e\u043b\u044c, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0438\u043a\u043d\u0435\u0439\u043c), \u0438 \u0442.\u043f).<\/p>\n<p>\u041f\u0440\u043e\u0449\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u0432\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f, \u043d\u0435\u0440\u0432\u044b, \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439.<\/em><\/p>\n<\/div>\n<\/details>\n<h2>\u0422\u0435\u043e\u0440\u0438\u044f &#8212; \u0445\u043e\u0440\u043e\u0448\u043e, \u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 &#8212; \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435!<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e <strong>\u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0431\u043e\u0440\u043a\u0438<\/strong> \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <em>(\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e <\/em><strong><em>Gradle<\/em><\/strong><em>, \u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f <\/em><strong><em>Maven<\/em><\/strong><em> \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435)<\/em>.<\/p>\n<p><a href=\"https:\/\/mapstruct.org\/documentation\/installation\/#gradle\" rel=\"noopener noreferrer nofollow\"><strong><em>Gradle<\/em><\/strong><\/a><strong><em>:<\/em><\/strong><\/p>\n<pre><code class=\"java\">dependencies {     \/\/...      \/\/ MapStruct     implementation 'org.mapstruct:mapstruct:1.5.5.Final'     annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' }<\/code><\/pre>\n<p><a href=\"https:\/\/mapstruct.org\/documentation\/installation\/#apache-maven\" rel=\"noopener noreferrer nofollow\"><strong><em>Maven<\/em><\/strong><\/a><strong><em>:<\/em><\/strong><\/p>\n<pre><code class=\"java\">&lt;properties>     &lt;org.mapstruct.version>1.5.5.Final&lt;\/org.mapstruct.version> &lt;\/properties> ... &lt;dependencies>     &lt;dependency>         &lt;groupId>org.mapstruct&lt;\/groupId>         &lt;artifactId>mapstruct&lt;\/artifactId>         &lt;version>${org.mapstruct.version}&lt;\/version>     &lt;\/dependency> &lt;\/dependencies> ... &lt;build>     &lt;plugins>         &lt;plugin>             &lt;groupId>org.apache.maven.plugins&lt;\/groupId>             &lt;artifactId>maven-compiler-plugin&lt;\/artifactId>             &lt;version>3.8.1&lt;\/version>             &lt;configuration>                 &lt;source>1.8&lt;\/source>                 &lt;target>1.8&lt;\/target>                 &lt;annotationProcessorPaths>                     &lt;path>                         &lt;groupId>org.mapstruct&lt;\/groupId>                         &lt;artifactId>mapstruct-processor&lt;\/artifactId>                         &lt;version>${org.mapstruct.version}&lt;\/version>                     &lt;\/path>                 &lt;\/annotationProcessorPaths>             &lt;\/configuration>         &lt;\/plugin>     &lt;\/plugins> &lt;\/build><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <strong>User<\/strong>:<\/p>\n<pre><code class=\"java\">@Data @Entity @NoArgsConstructor @AllArgsConstructor @Table(name = \"users\") public class User {      @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     private Long id;     private String username;     private String email;     private String password; }<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 <strong>UserResponse <\/strong>(dto) \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0443:<\/p>\n<pre><code class=\"java\">public record UserResponse(         Long id,         String username,         String email) { }<\/code><\/pre>\n<blockquote>\n<p><em>\u041d\u0435 \u043f\u0443\u0433\u0430\u0439\u0442\u0435\u0441\u044c, \u0435\u0441\u043b\u0438 \u0443\u0432\u0438\u0434\u0435\u043b\u0438 <\/em><a href=\"https:\/\/habr.com\/ru\/articles\/487308\/\" rel=\"noopener noreferrer nofollow\"><strong><em>record <\/em><\/strong><\/a><em>\u0432\u043f\u0435\u0440\u0432\u044b\u0435: \u044d\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0432 Java, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 final \u043f\u043e\u043b\u044f\u043c\u0438 (\u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u044f \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 hashcode()&amp;equals() + toString() + get() \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438.<\/em><\/p>\n<\/blockquote>\n<h2>UserMapper &#8212; \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0430\u043f\u043f\u0435\u0440<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <strong>interface UserMapper<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u0430\u043a\u0438 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <strong>\u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438<\/strong> (\u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430) \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 DTO:<\/p>\n<pre><code class=\"java\">@Mapper(componentModel = MappingConstants.ComponentModel.SPRING) public interface UserMapper {      UserResponse toUserResponse(User user); \/\/map User to UserResponse  List&lt;UserResponse> toUserResponseList(List&lt;User> users); \/\/map list of User to list of UserResponse }<\/code><\/pre>\n<p><strong><em>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e: <\/em><\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <\/strong>(\u0438\u043b\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441) \u0441 \u0438\u043c\u0435\u043d\u0435\u043c &#8216;Mapper&#8217; \u0432 \u043a\u043e\u043d\u0446\u0435 (\u044d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0442\u043e\u043d\u0430, \u043d\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 mapper (\u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u043e \u0437\u043e\u043d\u0430\u043c \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438)<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e<\/strong> @Mapper (org.mapstruct.Mapper), \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 <strong>MapStruct <\/strong>\u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e (\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c MapStruct \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u0434\u0430\u043d\u043d\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439, \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\/\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c), \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c componentModel (\u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Spring-framework \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435)<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b<\/strong> \u0432 \u043d\u0430\u0448 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u043e\u0437\u044c\u043c\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f <strong>MapStruct<\/strong><\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u0411\u0435\u0437 Spring:<\/p>\n<\/blockquote>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Spring, \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>INSTANCE <\/strong>\u0432\u043d\u0443\u0442\u0440\u0438 <strong>UserMapper <\/strong>interface, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<pre><code class=\"java\">@Mapper public interface UserMapper {      UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); \/\/add instance to call mapper      UserResponse toUserResponse(User user); \/\/map User to UserResponse      List&lt;UserResponse> toUserResponseList(List&lt;User> users); \/\/map list of User to list of UserResponse }<\/code><\/pre>\n<h2>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <strong>UserController<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"java\">@RestController @RequestMapping(\"\/api\/users\") @RequiredArgsConstructor public class UserController {      private final UserRepository userRepository;     private final UserMapper userMapper;      @GetMapping     public ResponseEntity&lt;List&lt;UserResponse>> findAll() {         List&lt;User> users = userRepository.findAll();         List&lt;UserResponse> userResponseList = userMapper.toUserResponseList(users);         return ResponseEntity.ok(userResponseList);     }      @GetMapping(\"\/{id}\")     public ResponseEntity&lt;UserResponse> findById(@PathVariable Long id) {         Optional&lt;User> user = userRepository.findById(id);         return user.isPresent()                 ? ResponseEntity.ok(userMapper.toUserResponse(user.get()))                 : ResponseEntity.notFound().build();     } }<\/code><\/pre>\n<blockquote>\n<p><em>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b <\/em><strong><em>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Spring<\/em><\/strong><em>, \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @RequiredArgsConstructor \u043e\u0442 <\/em><a href=\"https:\/\/habr.com\/ru\/companies\/piter\/articles\/676394\/\" rel=\"noopener noreferrer nofollow\"><em>Lombok<\/em><\/a><em>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 final \u043f\u043e\u043b\u0435\u0439 &#8212; \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043e\u0431\u044c\u0435\u043a\u0442\u044b UserRepository, UserMapper (Spring \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442 \u043d\u0430\u043c \u044d\u0442\u0438 \u043e\u0431\u044c\u0435\u043a\u0442\u044b \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 <\/em><a href=\"https:\/\/docs.spring.io\/spring-framework\/reference\/core\/beans\/dependencies\/factory-collaborators.html\" rel=\"noopener noreferrer nofollow\"><em>DI<\/em><\/a><em>)<\/em><\/p>\n<\/blockquote>\n<blockquote>\n<p><em>\u0411\u0435\u0437 Spring:<\/em><\/p>\n<\/blockquote>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b <strong>\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Spring<\/strong> &#8212; \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <strong>UserMapper<\/strong> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432 \u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435, \u0433\u0434\u0435 \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440:<\/p>\n<pre><code class=\"java\">private final UserMapper mapper = UserMapper.INSTANCE;<\/code><\/pre>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <strong>MapStruct<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d, \u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u043a\u0430\u043a @Mapper, \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u043d\u0430\u0448\u0435\u043c \u043c\u0430\u043f\u043f\u0435\u0440\u0435.<\/p>\n<blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u043e\u0439 <strong>\u043a\u043e\u0434 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b <\/strong>\u043d\u0430\u043c <strong>MapStruct<em> <\/em><\/strong><em>(\u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0436\u043c\u0435\u043c shift + shift \u0432 IntelijIdea  \u0438 \u0432\u0432\u0435\u0434\u0435\u043c \u0438\u043c\u044f UserMapperImpl \u0432 \u043f\u043e\u0438\u0441\u043a\u0435 Classes)<\/em><\/p>\n<\/blockquote>\n<figure class=\"full-width\">\n<div><figcaption>\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-377587","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/377587","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=377587"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/377587\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}