小编Tom*_*Tom的帖子

在Java中为具有循环引用的对象实现equals和hashCode

我定义了两个类,它们都包含对另一个对象的引用.它们看起来与此类似(这是简化的;在我的真实域模型中,A类包含B的列表,每个B都有一个返回父A的引用):

public class A {

    public B b;
    public String bKey;

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((b == null) ? 0 : b.hashCode());
        result = prime * result + ((bKey == null) ? 0 : bKey.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof A))
            return false;
        A other …
Run Code Online (Sandbox Code Playgroud)

java equals hashcode

33
推荐指数
1
解决办法
5114
查看次数

xkcd:外部性

所以2013年4月1日xkcd 外部性网络漫画以Skein 1024 1024哈希破坏比赛为特色.我假设这必须只是一个蛮力的努力,随机字符串被哈希以努力匹配兰德尔的发布哈希?它是否正确?

此外,我对Skein哈希理论的了解实际上并不存在,但作为一个中等程度的程序员,我能够在1024 1024模式下使用一些输入字符串在本地下载和运行SkeinFish(C#)和Maarten Bodewes Skein实现(Java).但是,它们给出的哈希值与xkcd为相同输入返回的哈希值不同.这可能是一个非常天真的问题,但不同的Skein实现会给出不同的哈希值吗?什么Skein实现是xkcd使用的?

谢谢你赦免我的无知!

hash cryptography skein

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

在WPF数据网格中的多个列上排序

如何设置我的WPF数据网格以对多个列进行排序,类似于具有两个可排序的列,单击第一列的标题进行主要排序,然后单击SHIFT点击第二列的标题进行二次排序.我希望当用户点击第一列的标题时自动发生多列排序,而不必在第二列标题上单击SHIFT.有没有办法在xaml中完全执行此操作?如果不是,我怎么能在后面的代码中执行此操作?目前使用VB.Net但如果你有一个C#片段是可以接受的.谢谢!

c# vb.net wpf datagrid

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

RestTemplate客户端与cookie

我正在用Java编写一个简单的客户端,以允许可重用​​使用通过RESTful API访问的专有病毒扫描软件.要上传用于扫描API的文件,需要使用POSTfor Connect,然后使用POSTfor将文件发布到服务器.在对Connect的响应中,POST服务器设置了cookie,后者需要在POST发布文件时使用.我目前正在RestTemplate我的客户端使用Spring .

我的问题是如何访问响应中的cookie以便随后转发回服务器POST?我可以看到它们存在于返回的标题中,但是没有方法ResponseEntity可以访问它们.

java cookies spring http resttemplate

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

使用RestTemplate POST InputStream

我有一个客户端需要将大量的大型json文件POST到服务器.我已经能够通过将每个文件读入内存并使用RestTemplate发布整个文件来实现它.但是,客户端快速耗尽处理大型json文件的内存.我想切换到流式方法,但无法弄清楚如何正确使用RestInmplate的FileInputStream.我发现了这个问题,并使用了接受的答案中给出的代码,但我仍然看到内存使用和OutOfMemory异常使我相信它不是流式传输文件,但仍然完全将它们读入内存.我究竟做错了什么?这是我目前的情况:

final InputStream fis = ApplicationStore.class.getResourceAsStream(path);

final RequestCallback requestCallback = new RequestCallback() {
    @Override
    public void doWithRequest(final ClientHttpRequest request) throws IOException {
        request.getHeaders().add("Content-type", "application/json");
        IOUtils.copy(fis, request.getBody());
    }
};

final RestTemplate restTemplate = new RestTemplate();
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setBufferRequestBody(false);     
restTemplate.setRequestFactory(requestFactory);     
final HttpMessageConverterExtractor<String> responseExtractor =
         new HttpMessageConverterExtractor<String>(String.class, restTemplate.getMessageConverters());

restTemplate.execute("http://" + host + ":8080/upads-data-fabric" + "/ruleset", httpMethod, requestCallback, responseExtractor);
Run Code Online (Sandbox Code Playgroud)

java resttemplate

15
推荐指数
2
解决办法
7945
查看次数

在JDK 6上安装最新的JAX-WS

我按照这里的说明 JDK v1.6.0_31之上正确安装了最新的JAX-WS版本(2.2.6)(即将JAX-WS发行版中的jaxws-api.jar和jaxb-api.jar复制到我的$ {JAVA_HOME}/lib/endorsed目录).从Eclipse内部我可以正确运行wsimport ant任务,生成的代码在以下注释中给出了一个版本标记:

/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.6b21 
* Generated source version: 2.2
* 
*/
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是生成的客户端代码显示错误导致我相信编译器仍在使用JAX-WS版本2.1:

The constructor Service(URL, QName, WebServiceFeature[]) is undefined
Run Code Online (Sandbox Code Playgroud)

The attribute required is undefined for the annotation type XmlElementRef
Run Code Online (Sandbox Code Playgroud)

我尝试在启动Eclipse时显式设置-Djava.endorsed.dir arg,我也尝试在Eclipse-> Preferences-> Java-> InstalledJREs下设置这个arg,但这些都没有帮助.我的wsimport ant任务类路径被定义为查看JAX-WS 2.2.6 jar.我也试过设置我的项目构建路径来拉入2.2.6罐子.似乎没什么用.我错过了什么吗?

jax-ws

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

xml配置的示例优先于Spring中的注释配置

在我读过的一本书中,XML配置的优先级高于注释配置.

但是没有任何例子.

你能举例说明一下吗?

java spring annotations spring-mvc xml-configuration

9
推荐指数
1
解决办法
5169
查看次数

WebApplicationContext不会自动装配

我写这个测试类:

@ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" })
public class CandidateControllerTest {

        @Mock(name = "candidateService")
        private CandidateService candidateService;

        @InjectMocks
        private CandidateMenuController candidateMenuController = new CandidateMenuController();


        @Autowired
        WebApplicationContext wac;

        MockMvc mockMvc;


        @Before
        public void before() {



            mockMvc = MockMvcBuilders.webApplicationContextSetup(wac).build();
         }
    }
Run Code Online (Sandbox Code Playgroud)

但:

代码执行后,我看到下一个跟踪:

java.lang.IllegalArgumentException: WebApplicationContext is required
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.test.web.server.setup.InitializedContextMockMvcBuilder.<init>(InitializedContextMockMvcBuilder.java:39)
    at org.springframework.test.web.server.setup.MockMvcBuilders.webApplicationContextSetup(MockMvcBuilders.java:73)
    at controllers.CandidateControllerTest.before(CandidateControllerTest.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at …
Run Code Online (Sandbox Code Playgroud)

java testing spring spring-mvc

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

请问Hibernate saveOrUpdate方法删除孩子?

我有一个应用程序通过休眠加载对象,然后将这些对象作为分离的对象传递给另一个层.对这些对象的任何更改都会发送回hibernate层,我会调用saveOrUpdate()这些对象.

saveOrUpdate()如果我在调用之前只是从集合中删除子对象,那么hibernate是否会删除传入对象中集合中包含的一对多关系子对象saveOrUpdate()

如果没有,那么通常如何在使用分离对象的hibernate应用程序中完成?

java hibernate

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

在Spring MVC 3.2中实现JSONP

我知道可以在早期版本的Spring MVC中使用自定义过滤器来实现JSONP.此外,此示例描述了通过扩展MappingJacksonHttpMessageConverter类和修改域对象在Spring MVC 3.1中实现JSONP的方法.

除了使用上述方法之外,还有更简单(或传统)的方法来解决Spring MVC 3.2中的JSONP吗?我没有在Spring 3.2文档中看到JSONP.

jsonp spring-mvc

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