albertshaw %!s(int64=8) %!d(string=hai) anos
pai
achega
6d7042e4fd

+ 5 - 1
src/main/java/com/goafanti/fragment/controller/FragmentController.java

@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.utils.StringUtils;
 import com.goafanti.fragment.service.FragmentService;
 
 @RestController
@@ -17,7 +18,10 @@ public class FragmentController extends BaseApiController {
 	FragmentService fragmentService;
 
 	@RequestMapping(value = "/get/{id}", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
-	public String get(@PathVariable String id) {
+	public String get(@PathVariable String id, String noCache) {
+		if (StringUtils.isNotBlank(noCache)) {
+			fragmentService.clean(id);
+		}
 		return fragmentService.selectById(id);
 	}
 

+ 11 - 0
src/main/java/com/goafanti/fragment/service/FragmentService.java

@@ -1,6 +1,9 @@
 package com.goafanti.fragment.service;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
@@ -8,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import com.goafanti.common.dao.HtmlFragmentMapper;
 import com.goafanti.common.model.HtmlFragment;
+import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 
 @Service
@@ -15,12 +19,19 @@ import com.goafanti.core.mybatis.BaseMybatisDao;
 public class FragmentService extends BaseMybatisDao<HtmlFragmentMapper> {
 	@Autowired
 	HtmlFragmentMapper htmlFragmentMapper;
+	
+	private static final Logger	logger	= LoggerFactory.getLogger(FragmentService.class);
 
 	@Cacheable(value = "HtmlFragmentCache", key = "'HtmlFragment:'+#id")
 	public String selectById(String id) {
 		HtmlFragment hf = htmlFragmentMapper.selectByPrimaryKey(id);
 		return hf == null ? "" : hf.getContent();
 	}
+	
+	@CacheEvict(value = "HtmlFragmentCache", key = "'HtmlFragment:'+#id")
+	public void clean(String id) {
+		LoggerUtils.debug(logger, "清除页面缓存:[%s]", id);
+	}
 
 	@CachePut(value = "HtmlFragmentCache", key = "'HtmlFragment:'+#id")
 	public String save(String id, String content) {

+ 3 - 1
src/main/java/com/goafanti/user/controller/UserLoginController.java

@@ -4,6 +4,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.web.util.WebUtils;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -59,7 +60,8 @@ public class UserLoginController extends BaseController {
 	@ResponseBody
 	public Result signin(User user,Boolean remember, HttpServletRequest request) {
 		Result res = new Result();
-		res.setData(TokenManager.login(user, remember));
+		TokenManager.login(user, remember);
+		res.setData(WebUtils.getAndClearSavedRequest(request));
 		return res;
 	}