假设我有class USER属性.
在一些示例中,我看到UserService class为某些功能定义.
我很困惑应该在User Class中编写哪些东西或函数以及UserService中的哪些东西.
对于e,g如果我想写一些函数来验证数据库中的用户,比如
validate(user,pass)
Run Code Online (Sandbox Code Playgroud)
应该在哪里写这些功能
如果我有的话 class ShoppingProducts
我希望得到特定用户购买的所有产品,我应该在哪个类中编写我的意思 product class or UserService or ProductService
最初我宣布了所有的bean dispatcher-servlet,我的应用程序工作了.我真的需要一个applicationContext.xml档案吗?
任何人都可以告诉我,我可以将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) 我有一个列表,其中包含一个我要迭代的地图
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)
任何帮助?
我试图使用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) 我有一些简单的代码,用于学习使用路标库的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) 我认为以下内容没有任何区别:
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代码中有以下枚举:
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是枚举值之一,以便我可以基于此采取适当的行动?
我想清楚地了解开发JSF应用程序的正确方法.在我们的项目中,模型和控制器是同一个类,由CDI bean表示.我有点困惑这是不是一个好习惯.据我了解MVC模式,控制器应该处理用户操作(例如提交表单),模型应该包含业务逻辑和数据.或者可以,他们在同一个班级?
此外,每个页面都应该有自己独立的控制器/模型(即它被认为是一种好的做法)吗?
我无法理解这是怎么可能的,所以我只会展示代码.
这有效.正如所料,打印了"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 ×8
spring ×3
el ×2
jsp ×2
jstl ×2
spring-mvc ×2
caching ×1
cdi ×1
collections ×1
enums ×1
hibernate ×1
instanceof ×1
jax-ws ×1
jpa ×1
jsf ×1
preferences ×1
syntax ×1
web-services ×1