小编Boz*_*zho的帖子

应该在applicationContext和dispatcherServlet中声明哪些bean

最初我宣布了所有的bean dispatcher-servlet,我的应用程序工作了.我真的需要一个applicationContext.xml档案吗?

java spring spring-mvc

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

我可以在JAXWS Web服务方法中将Hibernate实体作为返回值返回吗?

任何人都可以告诉我,我可以将Hibernate实体作为JAXWS Web服务方法中的返回值返回!

的确,我有一些这样的实体:

@Entity
public class Parent {
...
    private Childone childoneByChildoneid;    
    @ManyToOne
    public
    @javax.persistence.JoinColumn(name="ChildOneId",referencedColumnName="Id")
    Childone getChildoneByChildoneid() {
        return childoneByChildoneid;
    }    
    public void setChildoneByChildoneid(Childone childoneByChildoneid) {
        this.childoneByChildoneid = childoneByChildoneid;
    }
...
}

@Entity
public class Childone {
...
    private Collection<Parent> parentsById;
    @OneToMany(mappedBy = "childoneByChildoneid")
    public Collection<Parent> getParentsById() {
        return parentsById;
    }
    public void setParentsById(Collection<Parent> parentsById) {
        this.parentsById = parentsById;
    }
...
}
Run Code Online (Sandbox Code Playgroud)

并有这样的服务:

@Stateless
@WebService()
public class MasterDataService {
    @EJB
    private MasterDataManager manager;
    @WebMethod
    public Parent getParent(int parentId) {
        return …
Run Code Online (Sandbox Code Playgroud)

java web-services hibernate jpa jax-ws

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

如何在java中迭代List <Map <String,Object >>

我有一个列表,其中包含一个我要迭代的地图

List<Map<String, Object>> featureService=featureSubscriptionDao.getUnsubscribedSevice();
Run Code Online (Sandbox Code Playgroud)

我的dao方法是

@Override
public List<Map<String, Object>> getUnsubscribedSevice() {
    String sql="select * from tblservice where public='false'";
    return getJdbcTemplate().queryForList(sql);
}
Run Code Online (Sandbox Code Playgroud)

任何帮助?

java collections

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

Spring 3.1 Cache名称空间问题

我试图使用3.1弹簧缓存配置和命名空间按照春季文档.我也从春季网站下载了最新的jar,但我仍然遇到有关命名空间的问题

Unable to locate Spring NamespaceHandler for element 'cache:annotation-driven' of schema namespace 'http://www.springframework.org/
Run Code Online (Sandbox Code Playgroud)

模式/高速缓存"

spring配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">


cache:annotation-driven />

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache"/>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" 
    p:config-location="classpath:ehcache.xml"/>
Run Code Online (Sandbox Code Playgroud)

spring caching

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

java.util.prefs.Preferences.put()有效,但Preferences.nodeExists()总是返回false

我有一些简单的代码,用于学习使用路标库的OAuth身份验证.我正在尝试将请求令牌,令牌密钥和引脚保存为Java首选项,使用java.util.prefs.Preferences.将数据放入首选项工作正常(我检查文件已创建并存储信息).但是,在我put()将数据放入Preferences文件后,我立即尝试检查节点是否存在,而且我总是得到false.

我还尝试重新运行代码,并在尝试再次保存数据之前检查节点的存在,但我仍然得到错误.

我做错了什么?

这是代码:

package com.example;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.prefs.Preferences;

import oauth.signpost.OAuth;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.basic.DefaultOAuthProvider;

public class ReadMain {

    public static void main(String[] args) throws Exception {

        OAuthConsumer consumer = 
        new DefaultOAuthConsumer(
                "??",
                        "??");

        OAuthProvider provider = 
        new DefaultOAuthProvider(
            "https://www.readability.com/api/rest/v1/oauth/request_token/",
                    "https://www.readability.com/api/rest/v1/oauth/access_token/", 
                    "https://www.readability.com/api/rest/v1/oauth/authorize/");

        System.out.println("Fetching request token from Readability...");

        Preferences prefs = Preferences.userNodeForPackage(ReadMain.class);

        final String PREF_TokenSecret    = "com/example/TS";
        final String PREF_RequestToken   = "com/example/RT";
        final String …
Run Code Online (Sandbox Code Playgroud)

java preferences

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

"instanceof List"和"o instanceof List <?>"之间的区别

我认为以下内容没有任何区别:

    Object o = new LinkedList<Long>();

    System.out.println(o instanceof List); 
    System.out.println(o instanceof List<?>);
Run Code Online (Sandbox Code Playgroud)

是否有任何实际用途,instanceof List<?>何时instanceof List不能使用而反之亦然?

java syntax instanceof

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

与JSTL中的枚举值进行比较

我在我的后端java代码中有以下枚举:

public static enum CountryCodes implements EnumConstant {
                   USA, CAN, AUS;}
Run Code Online (Sandbox Code Playgroud)

在jsp中我试图遍历枚举值并进行比较:

<c:set var="countryCodes" value="<%=RequestConstants.CountryCodes.values()%>" />
<td><select>
   <c:forEach items="${countryCodes}" var="countryCode">
      <c:choose>
         <c:when test="${CURRENT_INSTITUTION.countryCode == countryCode}">
            <option value="${countryCode}" selected="selected">${countryCode}</option>
         </c:when>
         <c:otherwise>
            <option value="${countryCode}">${countryCode}</option>
         </c:otherwise>
      </c:choose>
   </c:forEach>
</select></td>
Run Code Online (Sandbox Code Playgroud)

但问题是,CURRENT_INSTITUTION.countryCode从数据库中读取并且可能不是枚举值之一.

如果CURRENT_INSTITUTION.countryCode是枚举值以外的值(比方说CHN),则比较会抛出以下异常:

java.lang.IllegalArgumentException:没有定义枚举const CountryCodes.CHN.

我必须应对这种情况,因为数据库存储旧数据,这些数据未经过完整性检查,可能包含无效值.

那么有没有一种比较方法只是在CURRENT_INSTITUTION.countryCode不是枚举值之一时返回false ?或者有没有办法确定是否CURRENT_INSTITUION.countryCode是枚举值之一,以便我可以基于此采取适当的行动?

enums jsp jstl el

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

在JSF中区分模型和控制器

我想清楚地了解开发JSF应用程序的正确方法.在我们的项目中,模型和控制器是同一个类,由CDI bean表示.我有点困惑这是不是一个好习惯.据我了解MVC模式,控制器应该处理用户操作(例如提交表单),模型应该包含业务逻辑和数据.或者可以,他们在同一个班级?
此外,每个页面都应该有自己独立的控制器/模型(即它被认为是一种好的做法)吗?

java model-view-controller jsf design-patterns cdi

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

jstl条件不起作用

我无法理解这是怎么可能的,所以我只会展示代码.

这有效.正如所料,打印了"PAIR"列表:

<c:forEach var="element" items="${list}">
<c:choose>
    <c:when test="true">
       <div>PAIR ${element}</div>
    </c:when>
    <c:otherwise>
       <div>ODD ${element}</div>
    </c:otherwise>
</c:choose>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)

这不起作用.仅打印"ODD":

<c:forEach var="element" items="${list}">
<c:choose>
    <c:when test="true == true">
       <div>PAIR ${element}</div>
    </c:when>
    <c:otherwise>
       <div>ODD ${element}</div>
    </c:otherwise>
</c:choose>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?

java jsp jstl el

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

使用Reflection获取构造函数(或方法)参数注释

如何从构造函数参数中的参数获取注释.我试过了...

Class<?>[] params = constructor.getParameterTypes();
    if(params.length > 0) {
        paramValues = new Object[params.length];
        for(int i=0; i<params.length; i++) {                        
        Annotation[] constructorAnnotations = params[i].getAnnotations(); //This does not work.
        }   
    }
Run Code Online (Sandbox Code Playgroud)

java reflection constructor annotations

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