Antiloveg лет назад: 8
Родитель
Сommit
d9899e1476

+ 1 - 1
src/main/java/com/goafanti/common/mapper/NewsMapper.xml

@@ -284,7 +284,7 @@
 			summary
 		from news
 		where 1 =1
-		<if test=" type != null">
+		<if test="type != null and type != 0" >
 			and type = #{type,jdbcType=INTEGER}
 		</if>
 		order by create_time desc

+ 18 - 3
src/main/java/com/goafanti/news/controller/NewsController.java

@@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
 
-import com.alibaba.druid.util.StringUtils;
+import com.goafanti.common.utils.StringUtils;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseController;
@@ -60,9 +60,24 @@ public class NewsController extends BaseController {
 	public Result portalNewsList(Integer type, String pageSize, String pageNo, String noCache){
 		Result res  = new Result();
 		if (StringUtils.equals(noCache, "clear")) {
-			newsService.cleanList();
+			newsService.cleanPortalList();
+		}
+		Integer pSize = null;
+		Integer pNo = null;
+		if (StringUtils.isNumeric(pageSize)) {
+			pSize = Integer.parseInt(pageSize);
+		}
+		if (StringUtils.isNumeric(pageNo)) {
+			pNo = Integer.parseInt(pageNo);
+		}
+		if (pNo == null || pNo < 0) {
+			pNo = 0;
+		}
+
+		if (pSize == null || pSize < 0 || pSize > 5) {
+			pSize = 5;
 		}
-		res.setData(newsService.findPortalList(pageSize, pageNo, type));
+		res.setData(newsService.findPortalList(pSize, pNo, type));
 		return res;
 	}
 	

+ 10 - 17
src/main/java/com/goafanti/news/service/NewsService.java

@@ -124,29 +124,22 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
 	public int batchDeleteByPrimaryKey(List<String> id) {
 		return newsMapper.batchDeleteByPrimaryKey(id);
 	}
-
-	public List<NewsSummary> findPortalList(String pageSize, String pageNo, Integer type) {
+	
+	@Cacheable(value = "NewsPortalListCache", key = "'NewsPortalList:Page:'+#pageNo+'Type:'+#type+'Size:'+#pageSize")
+	public List<NewsSummary> findPortalList(Integer pSize, Integer pNo, Integer type) {
 		Map<String, Object> params = new HashMap<String, Object>();
 		params.put("type", type);
-		Integer pSize = null;
-		Integer pNo = null;
-		if (StringUtils.isNumeric(pageSize)) {
-			pSize = Integer.parseInt(pageSize);
-		}
-		if (StringUtils.isNumeric(pageNo)) {
-			pNo = Integer.parseInt(pageNo);
-		}
-		if (pNo == null || pNo < 0) {
-			pNo = 0;
-		}
-
-		if (pSize == null || pSize < 0 || pSize > 5) {
-			pSize = 5;
-		}
+		
 		params.put("pageSize", pSize);
 		params.put("pageNo", pNo);
 		return newsMapper.findPortalList(params);
 	}
+	
+	@CacheEvict(value = "NewsPortalListCache", allEntries = true)
+	public void cleanPortalList() {
+		LoggerUtils.debug(logger, "清除门户端新闻列表缓存:[%s]");
+		
+	}