解决向redis添加\t被自动转义成\\t的问题,添加标志样例类配置模板

This commit is contained in:
RenKaiGe-Office
2018-05-21 19:06:19 +08:00
parent c9ff568a8b
commit c09c317785
7 changed files with 76 additions and 38 deletions

View File

@@ -51,24 +51,36 @@ public class ConfigSourcesController extends BaseRestController {
protected ServicesRequestLogService servicesRequestLogService; protected ServicesRequestLogService servicesRequestLogService;
@Autowired @Autowired
ConfigRedisService configRedisServiceimpl; ConfigRedisService configRedisService;
@RequestMapping(value = "/save", method = RequestMethod.GET) @RequestMapping(value = "/save", method = RequestMethod.GET)
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller") @ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true) @ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
public String testRedis() { public String testRedis(Integer type) {
try { try {
Map<String, String> map = new HashMap<String, String>(); if(type==1) {
Map<String, String> map = new HashMap<String, String>();
long id=configRedisServiceimpl.getIncrId("seq_compileid"); long id=configRedisService.getIncrId("seq_compileid");
map.put("cfg_id", id+""); //int id=2;
map.put("is_valid", "1"); map.put("cfg_id", id+"");
map.put("dst_file", "/home/1234/"); map.put("is_valid", "1");
map.put("dst_file_md5", "fasdfdasfsdafdsafadsf"); map.put("dst_file", "home");
map.put("time_stamp", new Date().getTime() + ""); map.put("dst_file_md5", "fasdfdasfsdafdsafadsf");
map.put("level", "20"); map.put("time_stamp", new Date().getTime() + "");
map.put("file_id",id+""); map.put("level", "20");
configRedisServiceimpl.saveConfigYSPDemoCompile(96,map); map.put("file_id",id+"");
configRedisService.saveConfigYSPDemoCompile(96,map);
}else {
Map<String, String> map = new HashMap<String, String>();
long id=configRedisService.getIncrId("seq_compileid");
//int id=2;
map.put("cfg_id", id+"");
map.put("is_valid", "1");
map.put("service", "100");
map.put("description", "123"+id);
map.put("level", "20");
configRedisService.saveConfigYSPDemoCompile(100,map);
}
return "ok"; return "ok";
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -2,6 +2,7 @@ package com.nis.web.dao.impl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
@@ -9,5 +10,12 @@ public abstract class BaseRedisDao<K, V> {
@Autowired @Autowired
protected RedisTemplate<K, V> redisTemplate; protected RedisTemplate<K, V> redisTemplate;
// public void setRedisTemplate(RedisTemplate<K, V> redisTemplate) {
// StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// redisTemplate.setKeySerializer(stringRedisSerializer);
// redisTemplate.setValueSerializer(stringRedisSerializer);
// this.redisTemplate = redisTemplate;
// }
} }

View File

@@ -12,8 +12,20 @@ import java.util.Map;
* *
*/ */
public interface ConfigRedisService { public interface ConfigRedisService {
/**
* 保存ysp样例配置接口
* @param service 业务类型
* @param map
*/
public void saveConfigYSPDemoCompile(int service, Map<String, String> map); public void saveConfigYSPDemoCompile(int service, Map<String, String> map);
/**
* 保存ysp配置接口
* @param service
* @param map
*/
public void saveConfigYSPCompile(int service, Map<String, String> map);
/** /**
* 获取指定key的自增长值 * 获取指定key的自增长值
* @param key 需要自增的key * @param key 需要自增的key

View File

@@ -2,9 +2,7 @@ package com.nis.web.service.restful;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@@ -43,18 +41,17 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
valBF.append(map.get(valStr)); valBF.append(map.get(valStr));
} else if (valStr.equals("&nbsp")) { } else if (valStr.equals("&nbsp")) {
valBF.append(" "); valBF.append(" ");
} else { } else if (valStr.equals("\\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t
valBF.append(valStr.trim()); valBF.append("\t");
} else if (valStr.equals("\\n")) {
valBF.append("\n");
} }
} }
DynamicJedisDataBase.setRedisDataBase(maatXmlExpr.getRedisDB(), redisTemplate);
System.out.println(keyBF.toString());
System.out.println(valBF.toString());
// DynamicJedisDataBase.setRedisDataBase(maatXmlExpr.getRedisDB(), redisTemplate.opsForValue().set(keyBF.toString(), new String(valBF));
// redisTemplate);
// System.out.println(keyBF.toString());
// System.out.println(valBF.toString());
//redisTemplate.boundValueOps(keyBF.toString()).
redisTemplate.opsForValue().set(keyBF.toString(), valBF.toString());
// redisTemplate.boundValueOps(keyBF.toString()).set(valBF.toString()); // redisTemplate.boundValueOps(keyBF.toString()).set(valBF.toString());
} }
@@ -101,9 +98,8 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
} }
} }
@Override
public Long getIncrId(String key) { public Long getIncrId(String key) {
DynamicJedisDataBase.setRedisDataBase(2, redisTemplate); DynamicJedisDataBase.setRedisDataBase(2, redisTemplate);
// RedisAtomicLong atomicLong = new RedisAtomicLong(key, // RedisAtomicLong atomicLong = new RedisAtomicLong(key,
// redisTemplate.getConnectionFactory()); // redisTemplate.getConnectionFactory());
// //
@@ -112,8 +108,12 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
// atomicLong.expire(liveTime, TimeUnit.SECONDS); // atomicLong.expire(liveTime, TimeUnit.SECONDS);
// } // }
// return id; // return id;
return redisTemplate.boundValueOps(key).increment(1l); return redisTemplate.boundValueOps(key).increment(1l);
} }
@Transactional
public void saveConfigYSPCompile(int service, Map<String, String> map) {
}
} }

View File

@@ -13,8 +13,7 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
default-lazy-init="true">
<!-- 加载配置文件,不知道为啥不能加载redis.properties的内容,先把redis.properties里面的内容放到jdbc.properties里面吧 --> <!-- 加载配置文件,不知道为啥不能加载redis.properties的内容,先把redis.properties里面的内容放到jdbc.properties里面吧 -->
<context:property-placeholder <context:property-placeholder
ignore-unresolvable="true" location="classpath:jdbc.properties" /> ignore-unresolvable="true" location="classpath:jdbc.properties" />
@@ -29,8 +28,8 @@
<bean id="connectionFactory" <bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig" p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="0" scope="prototype" /> p:database="0" />
<!-- p:password="" --> <!-- p:password="" scope="prototype"-->
<bean id="stringRedisSerializer" <bean id="stringRedisSerializer"
@@ -45,8 +44,4 @@
<!-- 设置开启事务 --> <!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" /> <property name="enableTransactionSupport" value="true" />
</bean> </bean>
</beans> </beans>

View File

@@ -127,6 +127,7 @@ jdbc.test.password=OrTu/cLwlduYPW/tmxqNgQ==
##redis连接 ##redis连接
##################################################################################################################################### #####################################################################################################################################
redis.host=10.0.6.228 redis.host=10.0.6.228
#redis.host=10.0.6.32
redis.port=6379 redis.port=6379
redis.pass= redis.pass=
redis.maxIdle=10 redis.maxIdle=10

View File

@@ -3,14 +3,24 @@
xsi:schemaLocation="http://www.w3school.com.cn maat.xsd"> xsi:schemaLocation="http://www.w3school.com.cn maat.xsd">
<p:maatType service="96;97;98;99;100;101;160;161;162;163;164;165"> <p:maatType service="96;97;98;99;160;161;162;163">
<p:expressions> <p:expressions>
<p:keyExpression>file_index_info;,;[cfg_id]</p:keyExpression> <p:keyExpression>EFFECTIVE_RULE;:;FILE_INDEX_INFO;,;[cfg_id]</p:keyExpression>
<p:valueExpression>[cfg_id];\t;[is_valid];\t;[dst_file];\t;[dst_file_md5];\t;[time_stamp];&amp;nbsp;[level];\t;[file_id];\n</p:valueExpression> <p:valueExpression>[cfg_id];\t;[is_valid];\t;[dst_file];\t;[dst_file_md5];\t;[time_stamp];&amp;nbsp;[level];\t;[file_id];\n</p:valueExpression>
<p:redisDB>2</p:redisDB> <p:redisDB>2</p:redisDB>
</p:expressions> </p:expressions>
</p:maatType> </p:maatType>
<p:maatType service="100;101;164;165">
<p:expressions>
<p:keyExpression>EFFECTIVE_RULE;:;mark_sample;,;[cfg_id]</p:keyExpression>
<p:valueExpression>[cfg_id];\t;[service];\t;[level];\t;[description];\t;[is_valid]</p:valueExpression>
<p:redisDB>2</p:redisDB>
</p:expressions>
</p:maatType>
</p:maat> </p:maat>