title: Embedding youtube video with exact time using Spring and Thymeleaf
body: <p>I have an issue when I try to embed a youtube video with exact time in a Java Project with Spring and Thymeleaf.</p>
  
  <p><strong>1/ Working scenario:</strong>
  When I try to embed a normal youtube video it works:<br>
  In the Controller I have this:
  <em>article.setVideo(video);</em>
  Where video is the end String of the youtube video:</p>
  
  <p>Example video link: <code>https://www.youtube.com/embed/s39mNwFuQDQ</code>
  Here the value of <strong>video</strong> will be:  <strong>s39mNwFuQDQ</strong></p>
  
  <p>Now in the html Thymeleaf view I have:
  <a href="https://i.stack.imgur.com/Xdx7z.jpg" rel="nofollow noreferrer">html Thymeleaf view</a></p>
  
  <pre><code>&lt;iframe width="560" height="315" th:src="@{https://www.youtube.com/embed/{url} (url=${article.video})}"   frameborder="0" alt="no video attached" allowfullscreen="1"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>It takes the saved video String, concatenates it to <code>https://www.youtube.com/embed/</code> and it is working just fine.</p>
  
  <p><strong>2/ Non-working scenario:</strong>
  When I try to do the same, but with youtube video with exact time – it is not working:</p>
  
  <p>In the Controller I have this:</p>
  
  <p><em>article.setVideo(video + "?start=" + extOptions);</em></p>
  
  <p>Where:</p>
  
  <p><em>video</em> - is a String;
  <em>extOptions</em> is a String.</p>
  
  <p>As a result I get a String</p>
  
  <p>Example: <code>https://www.youtube.com /embed/s39mNwFuQDQ?start=212</code> 
  <strong>video</strong> is - <strong>s39mNwFuQDQ</strong>
  <strong>extOptions</strong> is - <strong>212</strong></p>
  
  <p>Now in article.getVideo() I have : <strong>s39mNwFuQDQ?start=212</strong>  - this is saved in Database just fine.</p>
  
  <p>In the Thymeleaf html view I still have the same code.
  Unfortunately my video is not displayed at all this time in the Browser (tried different browsers).</p>
  
  <p>When I try an exact display of the video like this:</p>
  
  <pre><code>&lt;iframe width="560" height="315" th:src="@{https://www.youtube.com/embed/s39mNwFuQDQ?start=212}" frameborder="0" alt="no video attached" allowfullscreen="1"&gt;
  </code></pre>
  
  <p>It is working and video is displayed and starts from 212 second.</p>
  
  <p>What could be the problem here ? </p>
  
  <p>I tried some escaping for the ? mark, some pattern quote(regex escape) – but this does not help, these only fill the String with unwanted characters.</p>
  
  <p>Any ideas how to solve the issue ?</p>