小编Dam*_*her的帖子

JPA瞬态注释和JSON

这是关于JPA瞬态注释的以下问题的后续操作 为什么JPA有@Transient注释?

我有一个我不想持久的瞬态变量,它标有瞬态注释.但是,当我想从我的其余控制器生成JSON时,此瞬态变量在输出的JSON中不可用.

POJO PublicationVO是直接的,没有花哨的属性,只有一些私有属性(持久化)有getter和setter以及1个瞬态变量.

@RequestMapping(value = { "{publicationId}"}, method = RequestMethod.GET, produces = "application/json")
@ResponseBody public PublicationVO getPublicationDetailsJSON(@PathVariable(value = "publicationId") Integer publicationId) {
    LOG.info("Entered getPublicationDetailsJSON - publicationId: " + publicationId);

    //Call method to get the publicationVO based on publicationId
    PublicationVO publicationVO = publicationServices.getPublicationByIdForRestCalls(publicationId);       
    LOG.info("publicationVO:{}", publicationVO);

    LOG.info("Exiting getPublicationDetailsJSON");
    return publicationVO;
}
Run Code Online (Sandbox Code Playgroud)

PublicationVO如下

    package com.trinity.domain.dao;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonInclude;

@Entity
@Table(name …
Run Code Online (Sandbox Code Playgroud)

java rest spring json jackson

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

春季休息和Jsonp

我想让我的Spring休息控制器返回jsonp,但我没有快乐

完全相同的代码工作正常,如果我想返回json但我有一个要求返回jsonp 我已添加在转换器中我找到了在线执行jsonp转换的源代码

我使用的是Spring 4.1.1.RELEASE和Java 7

任何帮助是极大的赞赏

这是有问题的代码

MVC-调度-servlet.xml中

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">


  <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
       <property name="favorPathExtension" value="false" />
       <property name="favorParameter" value="true" />
       <property name="parameterName" value="mediaType" />
       <property name="ignoreAcceptHeader" value="false"/>
       <property name="useJaf" value="false"/>
       <property name="defaultContentType" value="application/json" />

       <property name="mediaTypes">
            <map>
                <entry key="atom"  value="application/atom+xml" />
                <entry key="html"  value="text/html" />
                <entry key="jsonp" value="application/javascript" />
                <entry key="json"  value="application/json" />
                <entry key="xml"   value="application/xml"/>
            </map>
        </property>
  </bean>

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="contentNegotiationManager" ref="contentNegotiationManager" /> …
Run Code Online (Sandbox Code Playgroud)

java rest jquery spring jsonp

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

Hibernate Projections/Lazy Loading用于非必需的1对1映射

我有以下2个班级(为这篇文章修剪)

public class ApplicationVO implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -3314933694797958587L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    private Integer id;


    @OneToOne(fetch = FetchType.LAZY, mappedBy = "application")
    @Cascade({ CascadeType.ALL })
    @JsonIgnore
    private ApplicationHomeScreenVO applicationHomeScreen;

...
...
... 
}


public class ApplicationHomeScreenVO implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -9158898930601867545L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    @JsonProperty("id") …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate hibernate-mapping hibernate-criteria

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

春天休息 - 发布文件

我有以下代码用于将文件发布到服务,它工作正常.我唯一的问题是,我必须编写一个临时文件来获取FileSystemResource,以便使用restTemplate发布对象

无论如何,我可以调整以下代码,以便我不必写一个临时文件?

    public String postNewIcon2(Integer fileId, MultipartFile multiPartfile) {
    LOG.info("Entered postNewIcon");

    Map<String, Object> params = getParamsWithAppKey();
    params.put("fileId", fileId);

    String result = null;
    File tempFile = null;
    try {

        String originalFileNameAndExtension = multiPartfile.getOriginalFilename();

        String tempFileName = "c:\\temp\\image";
        String tempFileExtensionPlusDot = ".png";

        tempFile = File.createTempFile(tempFileName, tempFileExtensionPlusDot);
        multiPartfile.transferTo(tempFile);
        FileSystemResource fileSystemResource = new FileSystemResource(tempFile);

        // URL Parameters
        MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
        parts.add("file", fileSystemResource);

        // Post
        result = restTemplate.postForObject(getFullURLAppKey(URL_POST_NEW_ICON), parts, String.class, params);

    } catch (RestClientException restClientException) {
        System.out.println(restClientException);
    } catch (IOException ioException) …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

4
推荐指数
1
解决办法
6032
查看次数

JNA - 设置资源路径

我试图设置JNA与自定义DLL交谈,但无济于事

它一直在说它正在寻找lcoation/target/classes /中的资源路径

我想知道是否可以添加一个可以获取我的DLL的资源位置?

我的代码如下

System.setProperty("jna.debug_load", "true");
System.setProperty("jna.debug_load.jna", "true");

System.setProperty("jna.platform.library.path", "C:\\Development\\dll\\");

Native.loadLibrary("customDLL", CustomDLL.class);
Run Code Online (Sandbox Code Playgroud)

如果我手动将dll添加到文件夹/ target/classes /,DLL将按预期加载

我正在使用Eclipse Luna 32位JDK 1.7.0_65 32位JNA 4.1.0

任何帮助是极大的赞赏

谢谢Damien

java dll jna

3
推荐指数
1
解决办法
8349
查看次数