小编phu*_*ury的帖子

多个方法参数的@Cacheable键

春季文档:

@Cacheable(value="bookCache", key="isbn")
public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)
Run Code Online (Sandbox Code Playgroud)

如何指定@Cachable使用isbncheckWarehouse作为键?

java spring ehcache

66
推荐指数
3
解决办法
11万
查看次数

禁用通过外部属性的spring方法缓存

我使用ehcache和注释驱动配置配置了spring方法缓存.

但是,我希望能够从我们在应用程序中使用的配置文件中禁用它.

我的第一个想法是,net.sf.ehcache.CacheManager.CacheManager()如果禁用方法缓存,则不带参数调用.抛出异常:

java.lang.IllegalArgumentException: loadCaches must not return an empty Collection
at org.springframework.util.Assert.notEmpty(Assert.java:268)
at org.springframework.cache.support.AbstractCacheManager.afterPropertiesSet(AbstractCacheManager.java:49)
Run Code Online (Sandbox Code Playgroud)

我的第二个想法是配置net.sf.ehcache.CacheManager.CacheManager()默认数据,以便不使用缓存(maxElementsInMemory 0等).但是仍然使用缓存,这不是我想要的.

有一个属性,net.sf.ehcache.disabled但我不想禁用也使用ehcache的hibernate缓存.

Q如何配置所有内容以使用spring方法缓存但从外部配置文件中禁用它?我不想修改应用程序上下文,也不想修改启用/禁用方法缓存的代码.只能修改我们在应用程序中使用的配置文件.

java spring ehcache

6
推荐指数
1
解决办法
5504
查看次数

更改列中的数据类型时将 int 转换为值

liquibase 是否可以在执行 a 时进行某种映射modifyDataType

考虑以下示例:

<changeSet id="1" author="me">
    <createTable tableName="person">
        <column name="id" type="int">
            <constraints primaryKey="true" nullable="false" />
        </column>
        <column name="firstName" type="varchar(100)"></column>
        <column name="lastName" type="varchar(100)"></column>
        <column name="marital_status" type="int">
            <constraints nullable="false" />
        </column>
    </createTable>
</changeSet>
<changeSet id="2" author="me">
    <modifyDataType tableName="person" columnName="type"
        newDataType="varchar(36)" />
</changeSet>
Run Code Online (Sandbox Code Playgroud)

我希望在我的“类型”列中发生以下映射:

0->single
1->married
etc..
Run Code Online (Sandbox Code Playgroud)

这可以用 liquibase 实现吗?我通过命令行使用它。

liquibase

5
推荐指数
1
解决办法
2364
查看次数

image.onload 和 image.onerror 的无限循环

我正在尝试加载和图像,如果 url 无效,则输入错误图像。在我的情况下, onerror 事件似乎被无限调用:

html:

<div id="output"></div>
Run Code Online (Sandbox Code Playgroud)

javascript:

function createImage(imageId) {
    var spinnerUrl = 'http://placehold.it/600&text=spinner';
    var errorUrl = 'http://placehold.it/600&text=error';
    var successUrl = 'http://placehold.com/600&text=success';
    var img = new Image();
    img.onerror = function() {
        console.log('no image at url: ' + imageId);
        this.src = errorUrl;
    };
    img.onload = function() {
        this.src = successUrl;
    };
    img.src = spinnerUrl;   
    return img;
};

function loadImage(id) {
    document.getElementById(id).appendChild(createImage('image-id'));
};

loadImage('output');
Run Code Online (Sandbox Code Playgroud)

您会注意到日志显示 'no image at url: image-id'

javascript

2
推荐指数
1
解决办法
2635
查看次数

结果集中的重复检索返回null

我有一个问题ResultSet.getString,当我第一次返回值时调用它,但第二次返回null(这没有关闭结果集或sql连接)

if (rs.getString(i) == null) {
    properties.setProperty(metaData.getColumnLabel(i), "");
} else {
    properties.setProperty(metaData.getColumnLabel(i), rs.getString(i));
}
Run Code Online (Sandbox Code Playgroud)

当然代码很容易修复,以避免第二次调用,rs.getString()但我想要了解的是为什么第二次返回null如果第一次没有

java jdbc

2
推荐指数
1
解决办法
291
查看次数

标签 统计

java ×3

ehcache ×2

spring ×2

javascript ×1

jdbc ×1

liquibase ×1