SpringCloudAlibaba云商场-商品详情页实现(二)

85 阅读2分钟

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第31天,点击查看活动详情

每日英语:

A person who never made a mistake never tried anything new.

翻译:一个人从不犯错,只是因为他不曾尝试过任何新鲜事物。 ——阿尔伯塔·爱因斯坦

1.对搜索数据进行渲染

搜索数据渲染我们需要在mall-search-web中调用mall-search-service,因此需要在mall-search-web引入mall-search-api依赖,并且在com.xz.mall.search.feign.SkuSearchFeign添加搜索调用方法,代码如下:

/**
 * 商品搜索
 */
@GetMapping
RespResult<Map<String, Object>> search(@RequestParam(required = false) Map<String, Object> searchMap);

mall-search-web依赖引入:

<dependencies>
    <dependency>
        <groupId>com.xz</groupId>
        <artifactId>mall-search-api</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

在启动类上com.xz.mall.WebSearchApplication上添加@EnableFeignClients注解,代码如下:

@SpringBootApplication
@EnableFeignClients(basePackages = "com.xz.mall.search.feign")
public class WebSearchApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebSearchApplication.class, args);
    }

}

1.1 对列表数据进行加载

Thymeleaf语法库:

th:abbrth:acceptth:accept-charset
th:accesskeyth:actionth:align
th:altth:archiveth:audio
th:autocompleteth:axisth:background
th:bgcolorth:borderth:cellpadding
th:cellspacingth:challengeth:charset
th:citeth:classth:classid
th:codebaseth:codetypeth:cols
th:colspanth:compactth:content
th:contenteditableth:contextmenuth:data
th:datetimeth:dirth:draggable
th:dropzoneth:enctypeth:for
th:formth:formactionth:formenctype
th:formmethodth:formtargetth:fragment
th:frameth:frameborderth:headers
th:heightth:highth:href
th:hreflangth:hspaceth:http-equiv
th:iconth:idth:inline
th:keytypeth:kindth:label
th:langth:listth:longdesc
th:lowth:manifestth:marginheight
th:marginwidthth:maxth:maxlength
th:mediath:methodth:min
th:nameth:onabortth:onafterprint
th:onbeforeprintth:onbeforeunloadth:onblur
th:oncanplayth:oncanplaythroughth:onchange
th:onclickth:oncontextmenuth:ondblclick
th:ondragth:ondragendth:ondragenter
th:ondragleaveth:ondragoverth:ondragstart
th:ondropth:ondurationchangeth:onemptied
th:onendedth:onerrorth:onfocus
th:onformchangeth:onforminputth:onhashchange
th:oninputth:oninvalidth:onkeydown
th:onkeypressth:onkeyupth:onload
th:onloadeddatath:onloadedmetadatath:onloadstart
th:onmessageth:onmousedownth:onmousemove
th:onmouseoutth:onmouseoverth:onmouseup
th:onmousewheelth:onofflineth:ononline
th:onpauseth:onplayth:onplaying
th:onpopstateth:onprogressth:onratechange
th:onreadystatechangeth:onredoth:onreset
th:onresizeth:onscrollth:onseeked
th:onseekingth:onselectth:onshow
th:onstalledth:onstorageth:onsubmit
th:onsuspendth:ontimeupdateth:onundo
th:onunloadth:onvolumechangeth:onwaiting
th:optimumth:patternth:placeholder
th:posterth:preloadth:radiogroup
th:relth:revth:rows
th:rowspanth:rulesth:sandbox
th:schemeth:scopeth:scrolling
th:sizeth:sizesth:span
th:spellcheckth:srcth:srclang
th:standbyth:startth:step
th:styleth:summaryth:tabindex
th:targetth:titleth:type
th:usemapth:valueth:valuetype
th:vspaceth:widthth:wrap
th:xmlbaseth:xmllangth:xmlspace

1.1.1 语法说明

数据结果集循环语法:www.thymeleaf.org/doc/tutoria…

th:each对象遍历,功能类似jstl中的<c:forEach>标签。

<tr th:each="user,userStat:${users}">
    <td>
    	下标:<span th:text="${userStat.index}"></span>,
    </td>
    <td th:text="${user.id}"></td>
    <td th:text="${user.name}"></td>
    <td th:text="${user.address}"></td>
</tr>

th:text:输出指定数据,例如th:text="${user.address}"表示输出user对象中的address属性。

th:src:加载指定图片

总结:

本篇主要介绍了一下对搜索数据渲染前的初步操作,以及介绍了一下Thymeleaf语法库,简单介绍了一下数据结果集循环语法。下一篇会介绍一下其他语法的使用说明。