小编vel*_*s4j的帖子

Spring RestTemplate和泛型类型ParameterizedTypeReference集合,如List <T>

Abstract控制器类需要REST中的对象列表.使用Spring RestTemplate时,它不会将其映射到所需的类,而是返回Linked HashMAp

 public List<T> restFindAll() {

    RestTemplate restTemplate = RestClient.build().restTemplate();
    ParameterizedTypeReference<List<T>>  parameterizedTypeReference = new ParameterizedTypeReference<List<T>>(){};
    String uri= BASE_URI +"/"+ getPath();

    ResponseEntity<List<T>> exchange = restTemplate.exchange(uri, HttpMethod.GET, null,parameterizedTypeReference);
    List<T> entities = exchange.getBody();
    // here entities are List<LinkedHashMap>
    return entities;

}
Run Code Online (Sandbox Code Playgroud)

如果我用,

ParameterizedTypeReference<List<AttributeInfo>>  parameterizedTypeReference = 
    new ParameterizedTypeReference<List<AttributeInfo>>(){};
    ResponseEntity<List<AttributeInfo>> exchange =
  restTemplate.exchange(uri, HttpMethod.GET, null,parameterizedTypeReference);
Run Code Online (Sandbox Code Playgroud)

它工作正常.但不能放入所有子类,任何其他解决方案.

java resttemplate spring-web spring-rest

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

按钮单击时,Primefaces在新选项卡中打开页面

我有这个

<h:outputLink value="http://.....index.html"
target="_blank">open</h:outputLink>
Run Code Online (Sandbox Code Playgroud)

但它显示像链接.我怎样才能创建这个按钮?我需要按钮"打开".当我按下此按钮时,我需要在浏览器的新选项卡中打开我的链接.

jsf primefaces

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

没有ScheduledExecutorService类型的限定bean 的TaskScheduler

这是调度配置

@Configuration
@EnableScheduling
public class RWInventorySchedule {

protected org.slf4j.Logger log = LoggerFactory.getLogger(RWInventorySchedule.class);

@PersistenceContext
private EntityManager entityManager;


   @Bean
   public RWInventoryProcessor constructInventoryProcessor() {
       log.debug("RWInventorySchedule constructs InventoryProcessor, entityManager : {} " , entityManager);
       return new RWInventoryProcessor(entityManager);
    }
}
Run Code Online (Sandbox Code Playgroud)

库存处理器如下

public class RWInventoryProcessor  {
 ...
 @Scheduled(fixedRate = 5000,initialDelay = 3000)
 @Transactional
 public void runProcess() {
   ...
 }
}
Run Code Online (Sandbox Code Playgroud)

在执行期间,在调试日志中获取以下错误

DEBUG org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor - 找不到默认的TaskScheduler bean org.springframework.beans.factory.NoSuchBeanDefinitionException:没有'org.springframework.scheduling.TaskScheduler'类型的限定bean可用

...
DEBUG org.springframework. scheduling.annotation.ScheduledAnnotationBeanPostProcessor - 找不到默认的ScheduledExecutorService bean org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'java.util.concurrent.ScheduledExecutorService'的限定bean

我错过了什么

java spring spring-scheduled

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

Spring @Transactional提交失败; Deby + Eclipselink

以下是spring配置

日期来源

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
    <property name="driverClassName" value="${rwos.dataSource.driverClassName}" />
    <property name="url" value="${rwos.dataSource.url}" />
    <property name="username" value="${rwos.dataSource.user}" />
    <property name="password" value="${rwos.dataSource.password}" />
 </bean>
Run Code Online (Sandbox Code Playgroud)

实体经理配置

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

  <bean id="persistenceUnitManager" class="org.springframework.data.jpa.support.MergingPersistenceUnitManager">
        <property name="defaultDataSource" ref="dataSource"/>
  </bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitManager" ref="persistenceUnitManager"/>
        <property name="persistenceUnitName" value="com.retailwave.rwos_rwos-data-pojo_jar_4.0.0PU"/>
  </bean>

  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"  lazy-init="true">
                <property name="entityManagerFactory" ref="entityManagerFactory"/>
                <property name="dataSource" ref="dataSource" />
  </bean>
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
</beans>
Run Code Online (Sandbox Code Playgroud)

以下是用于保留实体的代码段

@Singleton
@Component
public class RWTransactionDao {

@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager …
Run Code Online (Sandbox Code Playgroud)

java spring jpa derby eclipselink

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

JRE系统库缺少tools.jar

我使用的是Ubuntu 12.04(LTS).在我的Eclipse项目中,我需要使用com.sun.tools.attach包.但是,我的JRE系统库不包含包含该包的tools.jar文件.

我尝试为Java 6和7安装不同的JRE和JDK.我注意到他们中的一些在他们的libs文件夹中有提到的jar文件但是在选择JRE时Eclipse仍然无法将它包含在我的类路径中.引用tools.jar直接解决了问题,但由于这是一个共享项目,我不允许修改类路径,因此这对我来说不是一个可行的解决方案.

我的朋友正在使用具有相同版本的Eclipse和默认JRE的MAC,并且没有这个问题.我们发现,对他来说,tools.jar是classes.jar的一部分,在我的设置中并非如此(我没有classes.jar).

您认为这个问题的根源是什么?任何建议将不胜感激.

多谢你们!!!

java eclipse classpath

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

sql 在子集中创建序列号 - apache derby

能够使用以下查询生成序列号

CREATE SEQUENCE seqno AS integer
START WITH 1;

SELECT t1.*,
   (NEXT VALUE
    FOR seqno) AS seqno
FROM
  (SELECT l.TRANSACTION_ID,
      l.HSN
   FROM RWLINEITEM l
   WHERE l.TRANSACTION_ID IN ('CS610-20-10003','CS610-20-10002')
   GROUP BY l.TRANSACTION_ID,l.HSN) t1
Run Code Online (Sandbox Code Playgroud)

这给出了结果

sql 输出

要求是通过 Transaction 和 HSN 生成序列号,例如

预期结果

有什么办法可以达到这个结果。使用 derby-10.13.1.1

sql derby window-functions

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

从JTabbedPane隐藏选项卡

我正在使用Netbeans gui创建一个简单的应用程序.

这是我的结构(布局是免费设计):

在此输入图像描述

基本上我有3个选项卡,并希望根据条件隐藏其中一个(图像中的选择一个).如果用户作为某些权限显示该选项卡,否则不显示该选项卡.

在我的代码上,我试过了;

 if (userRole == 1){
    pnlAdiconarSala.setVisible(false);
 }
Run Code Online (Sandbox Code Playgroud)

但此选项卡始终显示.

通过我的实现,我可以隐藏选项卡吗?

java swing jtabbedpane

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

JPA:选择随机行

这是我的JPA ENTITY

@Entity
@NamedQueries({  
        @NamedQuery(name = "Question.randQuestion", query = "SELECT q FROM Question AS q ORDER BY     RANDOM")
})
@Table(name = "questions")
public class Question implements Serializable {
.....
}
Run Code Online (Sandbox Code Playgroud)

问题是:

eclipse给了我这个namedQuery的错误.它说:"在FROM子句中没有定义标识变量'RANDOM'"

我也试过RAND()而不是RANDOM和NEWID().

谢谢.

java jpa named-query jpql

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

通过Spring rest模板下载大文件

服务器代码:

@POST
@Path("reportDownload")
@Consumes(MediaType.APPLICATION_JSON)
public Response generateReport(QueryData queryData) {
     File file = new File("report.xlsx") // large file
     StreamingOutput stream = new FileStreamingOutput(file) ; 
        return Response.ok(stream, MediaType.APPLICATION_OCTET_STREAM)
            .header("filename" , file.getName())
            .build();
}
Run Code Online (Sandbox Code Playgroud)

客户代码:

使用以下代码,我可以将文件下载到一定的限制。获取大文件的内存堆错误。

final String uri = buildUri("/reportGenerate/reportDownload");

    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setReadTimeout(read_timeout);
    factory.setConnectTimeout(connection_timeout);

    RestTemplate restTemplate = new RestTemplate(factory);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    List<MediaType> mediaTypeList = new ArrayList<>();
    mediaTypeList.add(MediaType.APPLICATION_OCTET_STREAM);
    headers.setAccept(mediaTypeList);
    HttpEntity entity = new HttpEntity(queryData, headers);
    ResponseEntity<byte[]> data = restTemplate.exchange(uri, HttpMethod.POST, entity, byte[].class);
    HttpHeaders responseHeader = data.getHeaders(); …
Run Code Online (Sandbox Code Playgroud)

java spring resttemplate spring-rest

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

使用xslt sort对给定顺序进行排序

我正在使用

<xsl:sort />
Run Code Online (Sandbox Code Playgroud)

排序表中的行.的价值

@result 
Run Code Online (Sandbox Code Playgroud)

可能失败,被忽略或通过.由于按字母顺序排序,它不会按我想要的顺序出现.这是

失败 - 被忽略 - 通过

我如何实现这一点我正在使用xslt 1.0

这是我的代码

<xsl:apply-templates select="results/test-case">
<xsl:sort select="@result" /> 
</xsl:apply-templates>
Run Code Online (Sandbox Code Playgroud)

xml xslt-1.0

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

Apache Camel创建Consumer组件

我是Apache Camel的新手。在hp不间断中,有一个接收器,它接收事件管理器生成的事件,就像流一样。我的目标是建立一个消费者端点,该端点接收传入的消息并通过Camel处理它。

另一个终点,我只需要在日志中编写它即可。从我的研究中我了解到,对于Consumer端点,我需要创建自己的组件,并且配置将像

   from("myComp:receive").to("log:net.javaforge.blog.camel?level=INFO")
Run Code Online (Sandbox Code Playgroud)

这是我的代码片段,它接收来自事件系统的消息。

 Receive receive = com.tandem.ext.guardian.Receive.getInstance();
    byte[] maxMsg = new byte[500]; // holds largest possible request 
    short errorReturn = 0;
    do { // read messages from $receive until last close 
        try {
            countRead = receive.read(maxMsg, maxMsg.length);
            String receivedMessage=new String(maxMsg, "UTF-8");
            //Here I need to handover receivedMessage to camel 

        } catch (ReceiveNoOpeners ex) {
            moreOpeners = false;
        } catch(Exception e) {
            moreOpeners = false;
        }
    } while (moreOpeners);
Run Code Online (Sandbox Code Playgroud)

有人可以提供一些提示来指导如何使它成为消费者。

java apache-camel

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

结果集错误

我使用 Java EE 和 derby,我尝试从我的结果集中获取数据并将它们放入 int 和 string 但不起作用它给了我这个错误:

java.sql.SQLException: 当前游标位置的操作无效。

我尝试了 result.next() 但什么都没有,这是我的代码:

    Connection conn = null;
    Statement stmt = null;
    ResultSet result = null;  

    Hotel hot = new Hotel();
    try {
        synchronized (dataSource) {
            conn = dataSource.getConnection();
        }



        stmt = conn.createStatement();
        String req = "SELECT * FROM hotel WHERE num = " + num;
        result = stmt.executeQuery(req);                                                              

        }

        //result.next();           

        int xxnum = result.getInt(1);
        String nom = result.getString("nom");
        String villeV = result.getString("ville");
        int etoilesV = result.getInt("etoiles");
        String directeur = …
Run Code Online (Sandbox Code Playgroud)

java sql resultset

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