{"id":225085,"date":"2014-06-03T15:48:03","date_gmt":"2014-06-03T11:48:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=225085"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=225085","title":{"rendered":"<span class=\"post_title\">\u0414\u0432\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0432 \u0421\u0423\u0411\u0414<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" align=\"left\" width=\"300\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/665\/824\/9db\/6658249db48eff0fb7a8c5d443ac8ba3.jpg\"\/>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0435\u0431-\u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0444\u0430\u0439\u043b\u043e\u0432. \u041d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0443 \u043d\u0435\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c 2 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f: \u043f\u0435\u0440\u0432\u044b\u0439 \u2014 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 blob \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 Java, Spring MVC, Hibernate, MySQL \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 (\u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435\u043c \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u043a\u0443\u0441\u043e\u0447\u043a\u0438) \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 groovy, grails, hibernate, PostgreSQL.<\/p>\n<p>  \u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d \u044d\u0442\u043e\u0442 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434? \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0444\u0430\u0439\u043b\u044b \u0438 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443 \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0442\u0443\u0434\u0430 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0421\u0423\u0411\u0414, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u043e JDBC \u0441 \u0434\u0440\u0443\u0433\u0438\u0445 \u0445\u043e\u0441\u0442\u043e\u0432, \u0438 \u0435\u0441\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0431\u0430\u0437\u0443 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043d\u043e\u0434\u0430\u043c\u0438, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1 \u2014 \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 blob<\/h4>\n<p>  \u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c Spring MVC. \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0431\u0438\u043d \u0441 persistence \u0441\u043b\u043e\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043b\u043e\u0436\u0435\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u201c\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u201d, \u0445\u0440\u0430\u043d\u0438\u043c\u043e\u0433\u043e \u0432 \u0431\u0430\u0437\u0435<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">DataObject.java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.cpro.uchteno.domain.attach;  import java.sql.Blob;  import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.Table;  import org.hibernate.annotations.Type;  @Entity @Table(name = &quot;data_object&quot;) public class DataObject {          @Id @GeneratedValue(strategy=GenerationType.IDENTITY)     @Column(name=&quot;id&quot;)     private Integer id;          @Column(name=&quot;data_name&quot;)     private String name;          @Column(name=&quot;data_data&quot;, columnDefinition=&quot;longblob&quot;, length=2*1024*1024*1024)     @Lob()     private Blob data;          @Column(name=&quot;contype&quot;)     private String contentType;          @Column(name=&quot;surname&quot;)     private String surname;          @Column(name=&quot;access_count&quot;)     private Integer accessCount;      public Integer getId() {         return id;     }      public void setId(Integer id) {         this.id = id;     }      public String getName() {         return name;     }      public void setName(String name) {         this.name = name;     }      public Blob getData() {         return data;     }      public void setData(Blob data) {         this.data = data;     }      public String getContentType() {         return contentType;     }      public void setContentType(String contentType) {         this.contentType = contentType;     }      public String getSurname() {         return surname;     }      public void setSurname(String surname) {         this.surname = surname;     }      public Integer getAccessCount() {         return accessCount;     }      public void setAccessCount(Integer accessCount) {         this.accessCount = accessCount;     }      } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  private Integer id \u2014 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430;<br \/>  private String name \u2014 \u0438\u043c\u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430;<br \/>  private Blob data \u2014 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430;<br \/>  private String contentType \u2014 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430;<br \/>  private String surname \u2014 \u0432\u0438\u0434\u0438\u043c\u043e\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438\u043c\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430;<br \/>  private Integer accessCount \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0439;<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0448\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u0430\u043e \u0441\u043b\u043e\u044f \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">AttachmentDAO.java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.cpro.uchteno.dao.attach;  import java.util.List;  import ru.cpro.uchteno.domain.attach.DataObject;  public interface AttachmentDAO {     \/\/\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a\u0443.     public DataObject getObjectByID(Integer id);     \/\/\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442.     public void saveOrUpdate(DataObject dao);     \/\/\u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442.     public void deleteDataObject(DataObject dao);     \/\/\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.     public List&lt;DataObject&gt; listObjects();     \/\/\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e \u201c\u0444\u0430\u043c\u0438\u043b\u0438\u0438\u201d, \u0432\u0438\u0434\u0438\u043c\u043e\u043c\u0443 \u0443\u0437\u0435\u0440\u0443 \u0438\u043c\u0435\u043d\u0438.     public DataObject getObjectBySurname(String surname);     \/\/\u041f\u043e\u0438\u0441\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0431\u0430\u0437\u0435 \u043f\u043e \u0438\u043c\u0435\u043d\u0438.     public List&lt;DataObject&gt; searchObjectsByName(String query); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0435\u043b\u0430\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">AttachmentDAOImpl.java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.cpro.uchteno.dao.attach;  import java.util.ArrayList; import java.util.List;  import org.hibernate.SQLQuery; import org.hibernate.Session; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.stereotype.Repository;  import ru.cpro.uchteno.domain.attach.DataObject;  @Repository public class AttachmentDAOImpl implements AttachmentDAO { \t\/\/\u0412\u043d\u0435\u0434\u0440\u044f\u0435\u043c hibernateTemplate \t@Autowired \tprivate HibernateTemplate attachHibernateTemplate;  \t@Override \tpublic List&lt;DataObject&gt; listObjects() { \t\treturn attachHibernateTemplate.find(&quot;from DataObject&quot;); \t}  \t@Override \tpublic DataObject getObjectByID(Integer id) { \t\tList&lt;DataObject&gt; doList = attachHibernateTemplate.find( \t\t\t\t&quot;from DataObject where id = ?&quot;, id); \t\tif (doList == null || doList.size() &lt;= 0) \t\t\treturn null; \t\treturn doList.get(0); \t}  \t@Override \tpublic void saveOrUpdate(DataObject dao) { \t\tattachHibernateTemplate.saveOrUpdate(dao); \t}  \t@Override \tpublic void deleteDataObject(DataObject dao) { \t\tattachHibernateTemplate.delete(dao); \t}  \t@Override \tpublic DataObject getObjectBySurname(String surname) { \t\tList&lt;DataObject&gt; doList = attachHibernateTemplate.find( \t\t\t\t&quot;from DataObject where surname = ?&quot;, surname); \t\tif (doList == null || doList.size() &lt;= 0) \t\t\treturn null; \t\treturn doList.get(0); \t}  \t@Override \tpublic List&lt;DataObject&gt; searchObjectsByName(String query) { \t\tif (query == null || query.trim().equals(&quot;&quot;)) \t\t\treturn attachHibernateTemplate \t\t\t\t\t.find(&quot;from DataObject order by id desc limit 20&quot;); \t\treturn attachHibernateTemplate.find( \t\t\t\t&quot;from DataObject where name like ?&quot;, &quot;%&quot; + query + &quot;%&quot;); \t}  } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 \u0434\u0430\u043e<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">AttachmentService.java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.cpro.uchteno.service.attach;  import java.util.List;  import ru.cpro.uchteno.domain.attach.DataObject;  public interface AttachmentService {      public DataObject getObjectByID(Integer id);          public void saveOrUpdate(DataObject dao);          public void deleteDataObject(DataObject dao);      public List&lt;DataObject&gt; listObjects();      public DataObject getObjectBySurname(String surname);          public List&lt;DataObject&gt; searchObjectsByName(String query);      } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">AttachmentServiceImpl.java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.cpro.uchteno.service.attach;  import java.util.List;  import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;  import ru.cpro.uchteno.dao.attach.AttachmentDAO; import ru.cpro.uchteno.domain.attach.DataObject;  @Service public class AttachmentServiceImpl implements AttachmentService {          @Autowired     private AttachmentDAO attachmentDAO;          @Override     public List&lt;DataObject&gt; listObjects() { \treturn attachmentDAO.listObjects();     }      @Override     public DataObject getObjectByID(Integer id) { \treturn attachmentDAO.getObjectByID(id);     }      @Override     public void saveOrUpdate(DataObject dao) { \tattachmentDAO.saveOrUpdate(dao);     }      @Override     public void deleteDataObject(DataObject dao) { \tattachmentDAO.deleteDataObject(dao);     }          @Override     public DataObject getObjectBySurname(String surname) { \treturn attachmentDAO.getObjectBySurname(surname);     }      @Override     public List&lt;DataObject&gt; searchObjectsByName(String query) { \treturn attachmentDAO.searchObjectsByName(query);     }  } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u0441\u0451, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">AttachmentController.java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.cpro.uchteno.web.attachment;  import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.sql.Blob; import java.sql.SQLException; import java.util.HashMap; import java.util.List;  import javax.servlet.http.HttpServletResponse;  import org.hibernate.Hibernate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile;  import ru.cpro.uchteno.domain.attach.DataObject; import ru.cpro.uchteno.service.attach.AttachmentService;  @Controller() @RequestMapping(&quot;\/&quot;) public class AttachmentController { \t\/\/\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043d\u0430\u0448 \u0441\u0435\u0440\u0432\u0438\u0441 \t@Autowired \tprivate AttachmentService attachmentService; \t\/\/\u0412\u044b\u0432\u043e\u0434 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432\u0441\u0435\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0431\u0430\u0437\u0435 \t@RequestMapping(&quot;\/admin\/dataObjects\/private&quot;) \tpublic String index(HashMap&lt;String, Object&gt; map) { \t\tList&lt;DataObject&gt; doList = attachmentService.listObjects(); \/\/\u0441\u043f\u0438\u0441\u043e\u043a \u0444\u0430\u0439\u043b\u043e\u0432 \t\tmap.put(&quot;dlist&quot;, doList);\/\/ \u0437\u0430\u0442\u0430\u043b\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043a\u043e\u0434\u0435\u043b\u044c \u0444\u0442\u0440\u0430\u043d\u0438\u0446\u044b \t\treturn &quot;admin\/attach\/attach&quot;;\/\/ \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0432\u044c\u044e\u0445\u0435 \t}  \t\/\/\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \t@RequestMapping(&quot;\/admin\/dataObjects\/private\/add&quot;) \tpublic String add( \t\t\tHashMap&lt;String, Object&gt; map, \t\t\t@RequestParam(value = &quot;addName&quot;, required = true) String name, \t\t\t@RequestParam(value = &quot;addFile&quot;, required = true) MultipartFile file, \t\t\t@RequestParam(value = &quot;addSurname&quot;, required = true) String surname) { \t\ttry { \t\t\tDataObject dob = new DataObject();\/\/\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \t\t\tif (name == null || name.trim().equals(&quot;&quot;)) \/\/\u0415\u0441\u043b\u0438 \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u043f\u0443\u0441\u0442\u043e\u0435 \t\t\t\tdob.setName(file.getOriginalFilename()); \/\/ \u0412\u0437\u044f\u0442\u044c \u0438\u043c\u044f \u0438\u0437  \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \t\t\telse \t\t\t\tdob.setName(name); \/\/ \u0438\u043d\u0430\u0447\u0435 \u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u0443 \u043d\u043e\u0432\u043e\u0435 \u0438\u043c\u044f \t\t\tBlob blob = Hibernate.createBlob(file.getInputStream()); \/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u043b\u043e\u0431 \u043f\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443 \t\t\tdob.setData(blob); \t\t\tdob.setContentType(file.getContentType()); \/\/ \u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u0442\u0430\u0439\u043f \t\t\tdob.setSurname(surname); \/\/ \u0437\u0430\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u0443 \u201c\u0444\u0430\u043c\u0438\u043b\u0438\u044e\u201d \t\t\tattachmentService.saveOrUpdate(dob); \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0444\u0430\u0439\u043b \t\t} catch (IOException e) { \t\t\tSystem.out.println(&quot;\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0430\u0437\u0443&quot;); \t\t\treturn &quot;redirect:\/admin\/attach\/dataObjects\/private\/&quot;; \t\t} \t\treturn &quot;redirect:\/admin\/dataObjects\/private\/&quot;; \t}         \/\/\u0413\u043b\u0443\u0448\u0438\u043c \u0444\u0430\u0439\u043b\u044b \u043f\u043e \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a\u0443 \t@RequestMapping(&quot;\/admin\/dataObjects\/private\/del&quot;) \tpublic @ResponseBody \tString del(@RequestParam(value = &quot;id&quot;, required = true) Integer id) { \t\ttry { \t\t\tDataObject dao = attachmentService.getObjectByID(id); \t\t\tattachmentService.deleteDataObject(dao); \t\t} catch (Exception ex) { \t\t\treturn &quot;FAIL&quot;; \t\t} \t\treturn &quot;SUCCESS&quot;; \t}  \/\/\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u043f\u043e \u0444\u0430\u043c\u0438\u043b\u0438\u0438. \u041f\u0443\u0431\u043b\u0438\u0447\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c. \t@RequestMapping(&quot;\/public\/dataObjects\/getObject&quot;) \tpublic void getObject( \t\t\t@RequestParam(value = &quot;s&quot;, required = false) String surname, \t\t\tHttpServletResponse resp) { \t\tif (surname == null || surname.trim().equals(&quot;&quot;)) { \t\t\ttry { \t\t\t\tresp.getOutputStream().close(); \t\t\t\treturn; \t\t\t} catch (IOException e) { \t\t\t\te.printStackTrace(); \t\t\t} \t\t} \t\tDataObject dao = attachmentService.getObjectBySurname(surname); \/\/ \u0418\u0449\u0435\u043c \u0444\u0430\u0439\u043b \u043f\u043e \u0444\u0430\u043c\u0438\u043b\u0438\u0438 \t\tif (dao == null) { \t\t\ttry { \t\t\t\tresp.getOutputStream().close(); \t\t\t} catch (Exception ex) { \t\t\t} \t\t\treturn; \t\t} \t\t\/\/ \u043d\u0430\u0440\u0430\u0449\u0438\u0432\u0430\u0435\u043c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0439 \t\tif (dao.getAccessCount() == null) \t\t\tdao.setAccessCount(1);  \t\telse \t\t\tdao.setAccessCount(dao.getAccessCount() + 1); \t\tattachmentService.saveOrUpdate(dao);  \t\t\/\/\u041e\u0442\u0434\u0430\u0435\u043c \u044e\u0437\u0435\u0440\u0443 \u0444\u0430\u0439\u043b \t\tBlob blob = dao.getData(); \t\ttry { \t\t\tInputStream is = blob.getBinaryStream(); \t\t\tOutputStream os = resp.getOutputStream(); \t\t\tresp.setContentType(dao.getContentType()); \t\t\tint n = 0; \t\t\tbyte buff[] = new byte[1024]; \t\t\twhile (n &gt;= 0) { \t\t\t\tn = is.read(buff); \t\t\t\tif (n &gt; 0) \t\t\t\t\tos.write(buff, 0, n); \t\t\t} \t\t\tis.close(); \t\t\tos.close(); \t\t} catch (Exception e) { \t\t\te.printStackTrace(); \t\t} \t}  } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2 \u2014 \u0424\u0430\u0439\u043b\u043e\u0432\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439<\/h4>\n<p>  \u042f \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c grails. \u041d\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u0438\u0448\u0435\u043c \u043d\u0430 groovy, Blob \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0437\u043e\u0431\u044c\u0435\u043c \u043d\u0430\u0448 \u0444\u0430\u0439\u043b \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u043f\u043e-\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0442\u0443\u0442 \u0432\u0441\u0451 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e <a href=\"https:\/\/bitbucket.org\/asdnf\/gapp\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043c\u043e\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u044b. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/225085\/\"> http:\/\/habrahabr.ru\/post\/225085\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" align=\"left\" width=\"300\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/665\/824\/9db\/6658249db48eff0fb7a8c5d443ac8ba3.jpg\"\/>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0435\u0431-\u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0444\u0430\u0439\u043b\u043e\u0432. \u041d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0443 \u043d\u0435\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c 2 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f: \u043f\u0435\u0440\u0432\u044b\u0439 \u2014 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 blob \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 Java, Spring MVC, Hibernate, MySQL \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 (\u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435\u043c \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u043a\u0443\u0441\u043e\u0447\u043a\u0438) \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 groovy, grails, hibernate, PostgreSQL.<\/p>\n<p>  \u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d \u044d\u0442\u043e\u0442 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434? \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0444\u0430\u0439\u043b\u044b \u0438 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443 \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0442\u0443\u0434\u0430 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0421\u0423\u0411\u0414, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u043e JDBC \u0441 \u0434\u0440\u0443\u0433\u0438\u0445 \u0445\u043e\u0441\u0442\u043e\u0432, \u0438 \u0435\u0441\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0431\u0430\u0437\u0443 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043d\u043e\u0434\u0430\u043c\u0438, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435.  <\/p>\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-225085","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/225085","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=225085"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/225085\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=225085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=225085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}