Spring Boot Thymelaf:需要正确的thymeleaf语法来使用一个?B:c逻辑

siotufzp  于 2023-05-17  发布在  Spring
关注(0)|答案(1)|浏览(123)

我有一个日期选择器,允许用户选择日期。datepicker代码如下:

<form  id="formBean" th:action="@{/dailyStatistics}"  th:object=${dataFormBean} >
                        
                                    <!--<h1 class="card-title m-0"  >Select Range Date </h1>-->Select Range Date
                                        <button type="button" class="btn btn-primary btn-sm daterange" title="Date range">
                                       <i class="far fa-calendar-alt"></i>
                                   </button>
                                   
                                  From:  <input type="text" readonly="readonly"   id="selectSdateInput"  th:field="*{selectSDate}" >
                                  To:  <input type="text" readonly="readonly" id="selectEdateInput"  th:field="*{selectEDate}" >
                                    
                           </form>

我有两个thymeleaf片段:1.fragments/dailyStatisticsFragments::dailyStatisticsFragmentsToday代码:

<div id="fragments-container" th:replace="fragments/dailyStatisticsFragments :: dailyStatisticsFragmentsToday"></div>

2.fragments/dailyStatisticsFragments::dailyStatisticsFragmentsAll代码:

<div id="fragments-container" th:replace="fragments/dailyStatisticsFragments :: dailyStatisticsFragmentsAll"></div>

我想实现一个?B:c概念,用于百里香叶中的以下要求:如果用户不选择任何日期。系统必须选择

fragments/dailyStatisticsFragments :: dailyStatisticsFragmentsToday

否则,如果用户正在挑选任何日期。系统必须选择

fragments/dailyStatisticsFragments :: dailyStatisticsFragmentsAll
sdnqo3pr

sdnqo3pr1#

好吧,我可以通过使用这个synatx解决上面的问题。

<div id="fragments-container">
    <div th:replace="fragments/dailyStatisticsFragments :: ${dataFormBean.selectSDate == null and dataFormBean.selectEDate == null} ? 'dailyStatisticsFragmentsToday' : 'dailyStatisticsFragmentsAll' "></div>
</div>

相关问题