2017-09-15 6 views
0

일부 html 텍스트가 있습니다. 그 안에는 데이터베이스에서 가져온 여러 값을 인쇄하려고합니다. 이것은 내가 만든 html 형식입니다.Thymeleaf : html 텍스트에서 데이터베이스에서 가져온 값을 인쇄하는 방법은 무엇입니까?

<form id="deal-form" 
th:object="${deal}" method="post"> 

    <div class="border-t p-y-10"> 
     <i class="fa fa-calendar" aria-hidden="true"></i> Duration<br/> 
     Ads between <span th:value = "${hotDealDetail}" th:utext="${duration}">time</span> 

    </div> 

</form> 

기간 값은 데이터베이스에서 가져 와서 Thymeleaf를 사용하여 html 텍스트에 포함됩니다. 이것은 컨트롤러 방법입니다.

@ModelAttribute("hotDealDetail") 
    public String hotDealDetail(ModelMap model) { 
     model.addAttribute("deal", new Deal()); 
    return "hot-deal-detail"; 
} 

오류가 없습니다. 그러나 데이터베이스에서 가져온 값은 인쇄되지 않습니다. 내가 뭘 놓치고 있니?

편집 : 거래 클래스

당신이 달성 할 수있는 여러 가지 방법이 있습니다
@Entity 
@Table(name = "deal") 
public class Deal { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id; 

    private String name; 

    //in seconds 
    private double duration; 

    @OneToMany(mappedBy = "deal") 
    private List<DealEntry> dealEntries; 

    @Transient 
    private DealEntry newDealEntry; 


    public Deal() { 
     value = new BigDecimal(00.00); 
    } 

    public Long getId() { 
     return id; 
    } 

    public void setId(Long id) { 
     this.id = id; 
    } 


    } 
    public double getDuration() { 
     return duration; 
    } 

    public void setDuration(double duration) { 
     this.duration = duration; 
    } 

답변

1

.

접근 한

시도 컨트롤러 메소드에 요청 매핑을 만드는

@RequestMapping(value = "message", method = RequestMethod.GET) public ModelAndView hotDealDetail() { 
     ModelAndView mav = new ModelAndView(); 
     mav .addAttribute("deal", new Deal()); 
     return mav; 
    } 

접근법 2

> 
> @ModelAttribute("hotDealDetail") 
>  public String hotDealDetail() { 
>   return "some string without creating model"; 
>  } 

접근 3

> @RequestMapping(value = "hotDealDetail", method = RequestMethod.GET) 
>  public String messages(Model model) { 
>   model.addAttribute("hotDealDetail", new Deal()); 
>   return "hotDealDetail"; 
>  } 

참고 링크 : 다음의 http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html

+0

없음 – sndu

+0

작동되지 않는 것은 당신이 당신은 내가하지 않았다 – Pradeep

+0

유감을 설정 한 어떤 모델 속성을 들끓다 할 수있는 코드를 디버깅했다. 나는 지금 또 다른 질문을 가지고있다. 관련 이드도이 기간을 갖기를 원합니다 – sndu

관련 문제