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

友情链接与热门城市开发

anderx пре 4 година
родитељ
комит
e81db471ed

+ 0 - 183
src/main/java/com/kede/common/utils/RedisUtil.java

@@ -1,183 +0,0 @@
-package com.kede.common.utils;
-
-
-import com.alibaba.fastjson.JSON;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-import redis.clients.jedis.Jedis;
-import redis.clients.jedis.JedisPool;
-
-import java.io.*;
-import java.util.List;
-
-/**
- * redis辅助类
- * @author 
- *
- */
-public class RedisUtil {
-	@Value(value = "${jedis.host}")
-	private  String host;
-	@Value(value = "${jedis.password}")
-	private  String pwd;
-	@Autowired
-	private  JedisPool pool;//创建代理对象
-	
-	
-	
-//	 /**
-//     * 初始化Redis连接池
-//     */
-//    public RedisUtil() {
-//    	if (pool==null) {
-//    		try {
-//    			JedisPoolConfig config = new JedisPoolConfig();
-//    			config.setBlockWhenExhausted(false);
-//    			config.setEvictionPolicyClassName("org.apache.commons.pool2.impl.DefaultEvictionPolicy"); 
-//    			config.setJmxEnabled(true);
-//    			config.setJmxNamePrefix("pool");
-//    			config.setLifo(true);
-//    			config.setMaxIdle(8);
-//    			config.setMaxTotal(8);
-//    			config.setMaxWaitMillis(-1);
-//    			config.setMinEvictableIdleTimeMillis(1800000L);
-//    			config.setMinIdle(0);
-//    			config.setNumTestsPerEvictionRun(3);
-//    			config.setSoftMinEvictableIdleTimeMillis(1800000L);
-//    			config.setTestOnBorrow(false);
-//    			config.setTestWhileIdle(false);
-//    			config.setTimeBetweenEvictionRunsMillis(-1);
-//    			pool = new JedisPool(config, host, 6379, 10000, pwd);
-//    		} catch (Exception e) {
-//    			e.printStackTrace();
-//    		}
-//		}
-//    }
-
-	
-	
-	public boolean presence(String key){
-		Jedis jedis = pool.getResource();
-		boolean bool=true;
-		try {
-			bool =jedis.exists(key);//进行判断
-		}catch(Exception e){
-			e.printStackTrace();//输出错误信息
-		}finally {
-			jedis.close();//释放资源
-		}
-		return bool;
-	}
-	/**
-	 * 将缓存中数据进行反序列化
-	 * @param key
-	 * @param clazz
-	 * @return
-	 */
-	@SuppressWarnings("unchecked")
-	public <T>List<T> getObject(String key,Class<T> clazz){
-		Jedis jedis = pool.getResource();
-		ByteArrayInputStream is=null;
-		ObjectInputStream ois=null;
-		try {
-			//将缓存中数据存入byte数组中
-			byte[] b = jedis.get(key.getBytes());
-			is= new ByteArrayInputStream(b);
-			ois = new ObjectInputStream(is);
-			return(List<T>)ois.readObject();
-		} catch (Exception e) {
-			e.printStackTrace();
-		}finally{
-			try {
-				is.close();
-				ois.close();
-			} catch (IOException e) {
-				e.printStackTrace();
-			}
-			jedis.close();
-		}
-		return null;
-	}
-	/**
-	 * 将对象进行序列化存入redis中
-	 * @param object
-	 * @param key
-	 */
-	public void saveObject(Object object,String key){
-		Jedis jedis=pool.getResource();
-		ByteArrayOutputStream os=null;
-		ObjectOutputStream oos=null;
-		try {
-			os=new ByteArrayOutputStream();
-			oos =new ObjectOutputStream(os);
-			byte[] b=os.toByteArray();
-			JSON.toJSONString(b);
-			jedis.set(key.getBytes(), b);
-		} catch (Exception e) {
-			e.printStackTrace();
-		}finally{
-			try {
-				os.close();
-				oos.close();
-			} catch (Exception e2) {
-				e2.printStackTrace();
-			}
-			jedis.close();
-		}
-	}
-	// 把List集合对象转换成json格式保存到指定的键中
-	public void saveJsonArray(Object object, String key) {
-		Jedis jedis = pool.getResource();
-		try {
-			// 格式化成Json字符串
-			String array = JSON.toJSONString(object);
-			jedis.set(key, array.toString()); // 存入缓存
-		} finally {
-			jedis.close();
-		}
-	}
-	
-		public void setString(String key, String value) {
-			Jedis jedis = pool.getResource();
-			try {
-				jedis.set(key,value); // 存入缓存
-			} finally {
-				jedis.close();
-			}
-		}
-		
-		public void deleteString(String key) {
-			Jedis jedis = pool.getResource();
-			try {
-				jedis.del(key);
-			} finally {
-				jedis.close();
-			}
-		}
-		
-		public String getString(String key) {
-			Jedis jedis = pool.getResource();
-			String str=new String();
-			try {
-				str=jedis.get(key);
-			} finally {
-				jedis.close();
-			}
-			return str;
-		}
-
-	// 通过键取出Json字符串并转换成 <T>这个T所指定的类型
-	public  <T> T getJsonArray(String key, Class<T> clazz) {
-		Jedis jedis = pool.getResource();
-		try {
-			String str = jedis.get(key);
-			// 把字符串转换回集合对象 clazz是指定的类型
-			return JSON.parseObject(str, clazz);
-		} finally {
-			jedis.close();
-		}
-	}
-}
-
-

+ 1 - 1
src/main/java/com/kede/linksAndHot/controller/AdminLinksApiController.java

@@ -39,7 +39,7 @@ public class AdminLinksApiController extends BaseApiController {
 	}
 
 	@RequestMapping(value = "/update", method = RequestMethod.POST)
-	public Result update(Links in) {
+	public Result update(InputLinks in) {
 		Result res =new Result();
 		if (in.getId()==null){
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","编号"));

+ 1 - 1
src/main/java/com/kede/linksAndHot/service/LinkesService.java

@@ -11,7 +11,7 @@ import java.util.List;
 public interface LinkesService {
     int add(InputLinks in);
 
-    int update(Links in);
+    int update(InputLinks in);
 
     Object list(InputLinksList in);
 

+ 5 - 5
src/main/java/com/kede/linksAndHot/service/impl/LinkesServiceImpl.java

@@ -2,11 +2,9 @@ package com.kede.linksAndHot.service.impl;
 
 import com.kede.common.dao.LinksMapper;
 import com.kede.common.model.Links;
-import com.kede.common.utils.RedisUtil;
 import com.kede.core.mybatis.BaseMybatisDao;
 import com.kede.linksAndHot.bo.InputLinks;
 import com.kede.linksAndHot.bo.InputLinksList;
-import com.kede.linksAndHot.bo.outLinksList;
 import com.kede.linksAndHot.bo.publicLinks;
 import com.kede.linksAndHot.service.LinkesService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,8 +20,7 @@ import java.util.Map;
 public class LinkesServiceImpl extends BaseMybatisDao<LinksMapper> implements LinkesService {
     @Autowired
     private LinksMapper linksMapper;
-    @Autowired
-    private RedisUtil redisUtil;
+
 
     @Override
     public int add(InputLinks in) {
@@ -31,7 +28,7 @@ public class LinkesServiceImpl extends BaseMybatisDao<LinksMapper> implements Li
     }
 
     @Override
-    public int update(Links in) {
+    public int update(InputLinks in) {
         return linksMapper.updateByPrimaryKeySelective(in);
     }
 
@@ -46,6 +43,7 @@ public class LinkesServiceImpl extends BaseMybatisDao<LinksMapper> implements Li
     }
 
     @Override
+//    @Cacheable(value="getAllLinks", key = "links")
     public List<publicLinks> getAllLinks() {
         List<publicLinks> list=new ArrayList<>();
         if (list.isEmpty()){
@@ -55,4 +53,6 @@ public class LinkesServiceImpl extends BaseMybatisDao<LinksMapper> implements Li
         }
         return list;
     }
+
+
 }