Преглед изворни кода

请求的用户验证使用缓存

zhuth пре 7 година
родитељ
комит
f7509b7552

+ 5 - 0
pom.xml

@@ -94,6 +94,11 @@
 		    <version>2.1</version>
 		</dependency>
 		
+		<dependency>
+		    <groupId>org.springframework.boot</groupId>
+		    <artifactId>spring-boot-starter-cache</artifactId>
+		</dependency>
+		
 	</dependencies>
 
 	<build>

+ 2 - 0
src/main/java/com/uas/eis/UasEisApplication.java

@@ -2,11 +2,13 @@ package com.uas.eis;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.context.annotation.Import;
 
 import com.uas.eis.core.config.DynamicDataSourceRegister;
 
 @SpringBootApplication
+@EnableCaching
 @Import({DynamicDataSourceRegister.class})
 public class UasEisApplication {
 

+ 7 - 0
src/main/java/com/uas/eis/serviceImpl/UserServiceImpl.java

@@ -4,6 +4,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import com.uas.eis.core.support.TokenHandler;
@@ -24,18 +25,24 @@ public class UserServiceImpl implements UserService {
 	}
 	
 	@Override
+	@Cacheable(value="userCache")
 	public Map<String, Object> getUser(String username){
 		//SpObserver.putSp("UAS_TEST");
+		System.out.println("uuuu...........");
 		return baseDao.getJdbcTemplate().queryForMap("select em_auditman from employee where em_name = ?",username);
 	}
 	
 	@Override
+	@Cacheable(value="userEnableCache")
 	public boolean checkUser(String username, String password) {
+		System.out.println("query user enable cache.....");
 		return baseDao.checkIf("EIS_USER", "eu_enable=-1 and " + "eu_name='" + username + "' and eu_password='" + password + "'");
 	}
 
 	@Override
+	@Cacheable(value="userActionEnableCache")
 	public boolean checkAction(String username, String action) {
+		System.out.println("query user action enable.....");
 		boolean flag = false;
 		String roles = baseDao.queryForObject("select eu_role from eis_user where eu_name='" + username + "'", String.class);
 		String[] fields = {"er_reg","er_action"};