小编Ore*_*est的帖子

如何从AppCompat库更改SwitchCompat的颜色

我的应用程序中有一些不同颜色的开关控件,并且我使用多个自定义可绘制选择器来更改颜色.

随着AppCompat v21库的发布,引入了一个新的android.support.v7.widget.SwitchCompat控件.

是否可以在没有客户可绘制选择器的情况下以编程方式更改SwitchCompat的颜色,但是使用XML或代码?

android switchcompat

124
推荐指数
5
解决办法
10万
查看次数

Hibernate:LazyInitializationException:懒得初始化一个角色集合.无法初始化代理 - 没有会话

我有下一个错误: nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.example.Model.entities, could not initialize proxy - no Session

我的Model实体:

class Model {
...
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "model", orphanRemoval = true)
    @Cascade(CascadeType.ALL)
    @Fetch(value = FetchMode.SUBSELECT)
    public Set<Entity> getEntities() {
        return entities;
    }

    public void addEntity(Entity entity) {
        entity.setModel(this);
        entities.add(entity);
    }

}
Run Code Online (Sandbox Code Playgroud)

我有一个服务类:

@Service
@Transactional
class ServiceImpl implements Service {
    @Override
    public void process(Model model) {
        ...
        model.addEntity(createEntity());
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用其他服务方法调用服务:

@Override
@JmsListener(destination = …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa spring-transactions

12
推荐指数
2
解决办法
4万
查看次数

如何在Spring中将RequestHeader转换为自定义对象

我的控制器中有方法:

@RequestMapping(method = RequestMethod.POST)
public CustomObject createCustomObject(final @RequestHeader("userId") Long userId) {
   ...
}
Run Code Online (Sandbox Code Playgroud)

我可以编写一些自定义转换器或类似的东西来将此RequestHeader userId参数转换为User对象,因此我的方法将是:

@RequestMapping(method = RequestMethod.POST)
public CustomObject createCustomObject(final User user) {
   ...
}
Run Code Online (Sandbox Code Playgroud)

是否可以使用spring-mvc?

java spring spring-mvc

11
推荐指数
1
解决办法
4269
查看次数

Lombok @ Log4j2注释在IntelliJ IDEA中不起作用

我在我的项目中使用Lombok库并且@Log4j2注释有问题.不知道为什么,但它没有产生的log领域class.

但是当我将注释更改为@Slf4j有效时,我可以在IntelliJ IDEA的"结构"选项卡中看到它.

我正在使用它gradle作为构建工具.几乎没有依赖"

dependencies {
    compileOnly("org.projectlombok:lombok")
    compile("org.springframework.boot:spring-boot-starter-log4j2")
}
Run Code Online (Sandbox Code Playgroud)

java intellij-idea lombok log4j2

10
推荐指数
1
解决办法
6624
查看次数

如何在Android上信任自签名证书?

我为我的服务器生成了自签名证书.然后使用设置 - >安全性 - >安装将其添加到Android.

当我尝试使用应用程序连接到我的服务器时,我收到错误:

java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Run Code Online (Sandbox Code Playgroud)

据我所知,在我将证书添加到可信任之后它应该可以正常使用我的服务器,或者我可能会遗漏一些东西?这个想法是通过Android系统添加证书,不要更改应用程序代码.

顺便说一句,我OkHttpClient用于网络连接.也许我应该为https连接启用一些东西?

ssl android ssl-certificate okhttp

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

是否可以使用 OkHttp 设置占位符路径参数

我有一个 url http://example.com/{x}/push/{y},我正在使用 OkHttp 卷曲它。

final HttpUrl httpUrl = HttpUrl
                .parse("http://example.com/{x}/push/{y}")
                .newBuilder()
                ???
                .build();
Run Code Online (Sandbox Code Playgroud)

是否可以设置这些参数{x}{y}路径参数?我可以看到类似的方法addPathSegment,这在某种程度上是相关的,但不是我想要的。

android okhttp

7
推荐指数
1
解决办法
3614
查看次数

Spring中如何处理并发访问的事务

我有一种方法的服务:

    @Service
    public class DefaultTestService implements TestService {
        private static final Logger LOGGER = Logger.getLogger(DefaultTestService.class);
        @Autowired
        private TestRepository testRepository;

        @Transactional(readOnly = false, isolation = Isolation.SERIALIZABLE)
        @Override
        public void incrementAndGet(Long testModelId) {
            LOGGER.debug("Transaction is active: " + TransactionSynchronizationManager.isActualTransactionActive());
            final TestModel tm = testRepository.findOne(testModelId);
            if (tm != null) {
                LOGGER.debug("Updated " + testModelId + " from value: " + tm.getValue());
                tm.setValue(tm.getValue() + 1);
                testRepository.save(tm);
            } else {
                LOGGER.debug("Saved with id: " + testModelId);
                final TestModel ntm = new TestModel();
                ntm.setId(testModelId);
                testRepository.save(ntm);
            } …
Run Code Online (Sandbox Code Playgroud)

java spring spring-transactions spring-data

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

如何在gradle中修复transformClassesWithInstantRunForDebug

我有Android应用程序工作正常,但几个小时前它开始Run 'app' click在Android Studio中显示我的错误:

Error:Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> org.objectweb.asm.tree.analysis.AnalyzerException: Execution can fall off end of the code
Run Code Online (Sandbox Code Playgroud)

如果我从控制台构建应用程序,就像gradle assembleRelease一切正常.

所以我的问题是如何解决这个问题,可能导致这个问题.它让我发疯,因为我无法从Android Studio启动我的应用程序.

顺便说一句:我已经尝试谷歌和许多关于multidex问题的答案,但我想这不是我的选择.

android gradle android-studio

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

如何在 JAXB 中转义 unmarshal xml 上的特殊字符

我有下一个 xml 文件

<xml name="Places">
    <data>
        <row Code="1" Name="#X1.A&B(City)" />
    </data>
</xml>
Run Code Online (Sandbox Code Playgroud)

在执行 unmarshal 后,The reference to entity "B" must end with the ';' delimiter由于 Name 属性内的 & 符号,我收到异常。

JAXBContext jaxbContext = JAXBContext.newInstance(Root.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
File xml = new File("test2.xml");
Object obj = unmarshaller.unmarshal(xml);
Run Code Online (Sandbox Code Playgroud)

我怎样才能逃脱这些角色?

我已经尝试添加 CharacterEscapeHandler 但它不适用于 Unmarshaller

private static class EscapeHandler implements CharacterEscapeHandler {
    @Override
    public void escape(char[] buf, int start, int len, boolean isAttValue,
            Writer out) throws IOException {
           ...
    }

}

unmarshaller.setProperty("com.sun.xml.bind.marshaller.CharacterEscapeHandler", …
Run Code Online (Sandbox Code Playgroud)

java xml jaxb

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

如何在go中实现类似的界面?

我最近开始研究Go并面临下一期.我想实现Comparable接口.我有下一个代码:

type Comparable interface {
    compare(Comparable) int
}
type T struct {
    value int
}
func (item T) compare(other T) int {
    if item.value < other.value {
        return -1
    } else if item.value == other.value {
        return 0
    }
    return 1
}
func doComparison(c1, c2 Comparable) {
    fmt.Println(c1.compare(c2))
}
func main() {
    doComparison(T{1}, T{2})
}
Run Code Online (Sandbox Code Playgroud)

所以我收到了错误

cannot use T literal (type T) as type Comparable in argument to doComparison:
    T does not implement Comparable (wrong type for compare method)
        have …
Run Code Online (Sandbox Code Playgroud)

go go-interface

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