2017-06-06 101 views
0

フォーマットマスクを使用する必要がありますが、日付型 'dd-MMM-yyyy'しか使用できませんが、時間フォーマット 'HH:mm'が必要です。Thymeleaf "HH:mm"での日付時刻の書式設定

//ENTITY DateTimeFormat annotation on the method that's calling the DB to get date-time. 
@Entity 
@Table(name="horario") 
public class Horario implements Serializable {} .... 

@NotNull 
@Column(name = "duracao") 
@Temporal(TemporalType.TIME) 
@DateTimeFormat(pattern ="HH:mm") 
private Date duracao; 


@NotNull 
@Column(name ="hora_inicial") 
@Temporal(TemporalType.TIME) 
@DateTimeFormat(pattern = "HH:mm") 
private Date horaInicial; 

@NotNull 
@Column(name ="hora_final") 
@Temporal(value = TemporalType.TIME) 
@DateTimeFormat(pattern = "HH:mm") 
private Date horaFinal; 

そしてthymeleaf

で動的に私はthymeleafジャバスクリプト等角度

//HTML 
<div class="form-group" th:each="horarios, rowStat : *{horarios}" th:if="${rowStat.index} &lt; 5"> 
           <div class="col-sm-4 col-md-4 col-4"> 
            <div class="form-group" 
             th:classappend="${#fields.hasErrors('horarios[__${rowStat.index}__].duracao')} ? has-error"> 
             <label class="control-label required" th:text="#{mensagem.duracao}">Duração</label> 
             <div class="input-group"> 
              <span class="input-group-addon"> 
               <i class="fa fa-clock-o"></i> 
              </span> 
              <input type="text" class="form-control" th:id="duracao+${rowStat.index}" th:field="*{{horarios[__${rowStat.index}__].duracao}}" 
    I'm starting with this div, 
once it's resolved, I've moved on to the others-------------> th:value="${#dates.format(horarios.duracao, 'HH:mm')}" /> 
             </div> 
             <label class="error" th:if="${#fields.hasErrors('horarios[__${rowStat.index}__].duracao')}" 
               th:errors="*{horarios[__${rowStat.index}__].duracao}"></label> 
            </div> 
           </div> 

           <div class="col-sm-4 col-md-4 col-4"> 
            <div class="form-group" 
             th:classappend="${#fields.hasErrors('horarios[__${rowStat.index}__].horaInicial')} ? has-error"> 
             <label class="control-label required" 
               th:text="#{mensagem.horaInicial}">horaInicial</label> 
             <div class="input-group"> 
              <span class="input-group-addon"> 
                <i class="fa fa-clock-o"></i> 
               </span> 
              <input type="text" class="form-control" th:id="horaInicial+${rowStat.index}" 
                th:field="*{horarios[__${rowStat.index}__].horaInicial}" 
                /> 
             </div> 
             <label class="error" th:if="${#fields.hasErrors('horarios[__${rowStat.index}__].horaInicial')}" 
               th:errors="*{horarios[__${rowStat.index}__].horaInicial}"></label> 
            </div> 
           </div> 

           <div class="col-sm-3 col-md-3 col-3"> 
            <div class="form-group" 
             th:classappend="${#fields.hasErrors('horarios[__${rowStat.index}__].horaFinal')} ? has-error"> 
             <label class="control-label required" 
               th:text="#{mensagem.horaFinal}">horaFinal</label> 
             <div class="input-group"> 
              <span class="input-group-addon"> 
               <i class="fa fa-clock-o"></i> 
              </span> 
               <input type="text" class="form-control" th:id="horaFinal" 
                 th:field="*{horarios[__${rowStat.index}__].horaFinal}" readonly="readonly"/> 
             </div> 
             <label class="error" th:if="${#fields.hasErrors('horarios[__${rowStat.index}__].horaFinal')}" 
               th:errors="*{horarios[__${rowStat.index}__].horaFinal}"></label> 
            </div> 
           </div> 
           <div clas="col-sm-1"> 
            <button class="btn btn-danger padding-buttons" type="submit" name="removeRow" th:value="${rowStat.index}" th:if="${rowStat.index} ge 0 and ${#lists.size(horarioAula.horarios) ne 1}"> 
             <i class="fa fa-minus" style="color:white;"></i> 
            </button> 

           </div> 
         </div> 

とうまく相互作用しないと思う私のリターンは、使用@DateTimeFormat注釈を作成するには、この enter image description here

答えて

0

です二重括弧の構文を使用してみてください:

th:value="${{horarios.duracao}}" 

また、th:field属性を使用すると、この変換が自動的に行われます。

関連するドキュメント:http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html#double-brace-syntax

+0

ありがとうございます。今私は03:00を入力する必要がないようにユーザーを助けるためのスクリプトを作成します.3回だけ入力すると自動的に03:00の形式になります。 –

関連する問題