title: Thymeleaf & Spring images generation from DB - will run into a strange behaviour
body: <p>I am working on a project &amp; I am using Thymeleaf with Spring to create web pages, but I can not seem to get images generation working properly. </p>
  
  <p>I have them in my database, so they are generated fine (to the "generated" - folder). </p>
  
  <p><a href="https://i.stack.imgur.com/tV0qL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tV0qL.png" alt="enter image description here"></a></p>
  
  <p>So by accessing the Projects page the images should be there - but they are not showed on Frontend until I am not switching the Intellij and the go back to the Browser and click refresh again. I have never seen such strange behaviour. Maybe I am missing something in Thymeleaf? Cause I am using it for the first time.</p>
  
  <p><code>FILE_UPLOAD_ROOT</code> - is read from <strong>application.properties</strong> and it is <em>src/main/resources/generated/</em></p>
  
  <p>Then my controller is passing a list of projects to this method:</p>
  
  <pre><code>/**
   * Each entity that will extend {@link MediaModel} can use this method as a helper. In other words,
   * we should have these three fields added to the table that we're going to use:
   * pic(LONGBLOB), pic_name(VARCHAR), pic_type(VARCHAR)
   *
   * @param itemsList - database results for that we are going to generate images
   */
   public static void generateImages(Iterable&lt;? extends MediaModel&gt; itemsList) {
  
      itemsList.forEach(item -&gt; {
          try {
              if (item.getPicName() == null) {
                  return;
              } else {
                  Files.write(Paths.get(FILE_UPLOAD_ROOT + item.getPicName() + "." + item.getPicType()), item.getPic());
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
      });
  }
  </code></pre>
  
  <p>in Thymeleaf I have:
  <em>I am not really sure why, but the pictures are not taken directly from <strong>generated</strong> folder, I should specify only the root, anyway Thymeleaf will not be capable to show them at all.</em></p>
  
  <p><code>&lt;img th:src="@{/{picName}.{picType}(picName=${project.picName},picType=${project.picType})}"/&gt;</code></p>
  
  <p>MySQL schema that is holding the projects images</p>
  
  <pre><code>create table projects
  (
      id          bigint       not null
          primary key,
      created_at  datetime(6)  not null,
      updated_at  datetime(6)  not null,
      pic         longblob     null,
      pic_name    varchar(255) null,
      pic_type    varchar(255) null,
      category_id bigint       not null,
      constraint FKmagkis2tpqxxx8hq100rjo92v
          foreign key (category_id) references projects_categories (id)
              on delete cascade
  );
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Efsir.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Efsir.png" alt="enter image description here"></a></p>
  
  <p>And when I try to access the page there is this, until I will not switch back to Intellij:</p>
  
  <p><a href="https://i.stack.imgur.com/TxDDf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TxDDf.png" alt="enter image description here"></a></p>
  
  <p><strong>P.S. Yes I tried to deploy it to a remote server, cannot see them at all, but I took a look into the target folder and the images are there.</strong></p>