Authored by mali

热搜词列表接口

package com.yohoufo.dal.product;
import com.yohoufo.dal.product.model.SearchWord;
import java.util.List;
/**
* Created by li.ma on 2018/9/27.
*/
public interface SearchWordMapper {
List<SearchWord> selectAll();
}
... ...
package com.yohoufo.dal.product.model;
/**
* Created by li.ma on 2018/9/27.
*/
public class SearchWord {
private Integer id;
private String searchWord;
private Integer orderBy;
private Integer createTime;
private Integer updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public String getSearchWord() {
return searchWord;
}
public void setSearchWord(String searchWord) {
this.searchWord = searchWord;
}
public Integer getOrderBy() {
return orderBy;
}
public void setOrderBy(Integer orderBy) {
this.orderBy = orderBy;
}
}
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yohoufo.dal.product.SearchWordMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.product.model.SearchWord">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="search_word" jdbcType="VARCHAR" property="searchWord" />
<result column="order_by" jdbcType="INTEGER" property="orderBy" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
</resultMap>
<select id="selectAll" resultMap="BaseResultMap">
select id, search_word, order_by, create_time, update_time from hot_search_word order by order_by DESC
</select>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.product.controller;
import com.yoho.tools.docs.ApiOperation;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.product.response.SearchWordResp;
import com.yohoufo.product.service.impl.HotSearchWordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Created by li.ma on 2018/9/27.
*/
@RestController
public class HotSearchWordController {
private final Logger LOG = LoggerFactory.getLogger(HotSearchWordController.class);
@Autowired
private HotSearchWordService hotSearchWordService;
@ApiOperation(name = "ufo.product.searchWord", desc="热搜词列表")
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.searchWord")
@Cachable(expire = 300)
public ApiResponse querySearchWord() {
LOG.info("in method=ufo.product.searchWord");
List<SearchWordResp> resp = hotSearchWordService.querySearchWord();
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("热搜词列表").build();
}
}
... ...
package com.yohoufo.product.response;
/**
* Created by li.ma on 2018/9/27.
*/
public class SearchWordResp {
private String searchWord;
private Integer orderBy;
public SearchWordResp() {
}
public SearchWordResp(String searchWord, Integer orderBy) {
this.searchWord = searchWord;
this.orderBy = orderBy;
}
public String getSearchWord() {
return searchWord;
}
public void setSearchWord(String searchWord) {
this.searchWord = searchWord;
}
public Integer getOrderBy() {
return orderBy;
}
public void setOrderBy(Integer orderBy) {
this.orderBy = orderBy;
}
}
... ...
package com.yohoufo.product.service.impl;
import com.yohoufo.dal.product.SearchWordMapper;
import com.yohoufo.dal.product.model.SearchWord;
import com.yohoufo.product.response.SearchWordResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* Created by li.ma on 2018/9/27.
*/
@Service
public class HotSearchWordService {
@Autowired
private SearchWordMapper searchWordMapper;
public List<SearchWordResp> querySearchWord() {
List<SearchWord> searchWords = searchWordMapper.selectAll();
List<SearchWordResp> result = new ArrayList<>();
searchWords.stream().forEach(item ->{
result.add(new SearchWordResp(item.getSearchWord(), item.getOrderBy()));
});
return result;
}
}
... ...