Requirement Description: Picture element background picture loading: If the URL from the background is empty, the default picture URL is displayed.
That's what I do:
1 <Divclass= "Swiper-container">2 <Divclass= "Swiper-wrapper">3 <Divclass= "Swiper-slide"th:unless= "${#lists. IsEmpty (hotList)}"
Th:each= "element: ${hotList}"
Th:style= "${#strings. Prepend ((Element.imgurl! = null)? ( Accesspath+element.imgurl):(accesspath+ ' img_default_2.png '), ' Background-image:url (')} + ') ' ">
</Div>5 </Div>6 <!--ADD Arrows -7 <Divclass= "Swiper-pagination"></Div>8 </Div>
The pits encountered:
Because to determine whether to load the default picture or pass over the picture, so with three mesh operation.
Add the String ' Background-image:url (') before the three mesh operation
<class= "Swiper-slide" th:unless= "${#lists. IsEmpty (hotList) } " th:each=" element: ${hotlist} " th:style=" ' Background-image:url (' + (${ Element.imgurl}! = null)? (${accesspath+element.imgurl}):(${accesspath} + ' img_default_2.png ') + ' "></Div >
Found completely ineffective: the entire background-image attribute is gone.
Later, the test found in the three mesh operation in front of the string, the parsed content is to get rid of the string, dizzy death, what reason is not empty to study.
Later in the document, ${#strings. prepend (Str,prefix)} This tool method allows you to prefix a variable with a string.
So, I just used the three budget to replace the first parameter, finally can be done.
It seems that I have not seen such a wonderful way of writing, maybe it is the wrong idea to solve this problem.
Springboot use: thymeleaf three mesh operation problem