springmvc 结合 ehcache

ehcache 版本使用ehcache-2.10.2.jar


需要的包

ehcache-2.10.2.jar

slf4j-api-1.7.7.jar

slf4j-jdk14-1.7.7.jar


使用log4j日志框架需要的包

slf4j-log4j12-1.7.7.jar

log4j-1.2.17.jar

全部包,下载地址

http://download.csdn.net/detail/wangzhiqiang123456/9565929

配置问题文件

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">  
    <diskStore path="java.io.tmpdir/ehcache"/>  
    <defaultCache  
           maxElementsInMemory="1000"  
           eternal="false"  
           timeToIdleSeconds="120"  
           timeToLiveSeconds="120"  
           overflowToDisk="false"/>  
                  
    <cache name="menuCache"   
           maxElementsInMemory="1000"   
           eternal="false"  
           timeToIdleSeconds="120"  
           timeToLiveSeconds="120"  
           overflowToDisk="false"   
           memoryStoreEvictionPolicy="LRU"/>  
</ehcache>  



applicationContext.xml 只有关于ehcache的配置,其他配置没有贴出来

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
 http://www.springframework.org/schema/tx 
 http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
 http://www.springframework.org/schema/cache
 http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.2.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
 
<!--开启缓存注解-->
<cache:annotation-driven cache-manager="cacheManager"/>
      

<!-- 缓存配置开始 -->
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">  
        <property name="configLocation" value="classpath:ehcache.xml" />  
    </bean>  
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">      
        <property name="cacheManager"  ref="cacheManagerFactory"/>      
    </bean>
<!-- 缓存配置结束 -->
    </beans>


测试方法

@Cacheable(value="menuCache")
public String getkey(String k)
{
log.debug("进来了");
return "55985985555";
}


log4j.properties

#定义根日志级别和输出端(定义了两个输出端) 
#log4j.rootLogger=DEBUG,CONSOLE,D,E  
log4j.rootLogger=DEBUG,CONSOLE
#定义第一个输出端,输出到控制台  
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout  
log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c(%L) - %m%n  
### 输出到日志文件 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n


### 保存异常信息到单独文件 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = logs/error.log 
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR 
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
  
#定义具体某个包下的日志输出级别   
log4j.logger.org.springframework=ERROR


slf4j+log4j出现的问题

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [zip:D:/Oracle/Middleware/user_projects/domains/base_qumancheng/servers/AdminServer/tmp/_WL_user/_appsdir_ainmeweb_dir/e5r7ej/war/WEB-INF/lib/slf4j-jdk14-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [zip:D:/Oracle/Middleware/user_projects/domains/base_qumancheng/servers/AdminServer/tmp/_WL_user/_appsdir_ainmeweb_dir/e5r7ej/war/WEB-INF/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.JDK14LoggerFactory]


错误提示,在两个包中存在相同的StaticLoggerBinder.class 删除一个class即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用SpringMVC结合Ajax批量修改,可以按照以下步骤进行: 1. 在前端页面中,通过Ajax请求将需要修改的数据以JSON格式发送到后端Controller。 2. 在后端Controller中,接收到请求后,可以将JSON数据转换成Java对象。 3. 使用SpringMVC的@Service注解,定义一个Service层的类,该类中定义一个方法,用于批量修改数据。 4. 在Service层的方法中,可以使用MyBatis等ORM框架进行数据库操作,批量修改数据。 5. 修改完成后,返回修改结果给前端页面。 以下是一个示例代码: 前端页面中的Ajax请求: ```javascript $.ajax({ url: "/batchUpdate", type: "POST", data: JSON.stringify({ "dataList": dataList }), contentType: "application/json;charset=utf-8", dataType: "json", success: function (data) { // 处理返回结果 } }); ``` 后端Controller中的方法: ```java @RequestMapping(value = "/batchUpdate", method = RequestMethod.POST) @ResponseBody public Map<String, Object> batchUpdate(@RequestBody Map<String, Object> map) { List<Data> dataList = (List<Data>) map.get("dataList"); Map<String, Object> resultMap = new HashMap<>(); try { int count = dataService.batchUpdate(dataList); resultMap.put("code", 0); resultMap.put("msg", "批量修改成功!"); } catch (Exception e) { resultMap.put("code", 1); resultMap.put("msg", "批量修改失败!"); } return resultMap; } ``` Service层的方法: ```java @Service public class DataServiceImpl implements DataService { @Autowired private DataMapper dataMapper; @Override public int batchUpdate(List<Data> dataList) { int count = 0; for (Data data : dataList) { count += dataMapper.update(data); } return count; } } ``` 其中,Data是需要修改的数据的Java对象,DataMapper是使用MyBatis框架的Mapper接口,用于数据库操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值