最近在intellij中设置了一个具有以下结构的多模块项目:
/module1
/module2
/web-module
/sql
/lib
/a few more folders
Run Code Online (Sandbox Code Playgroud)
我在Intellij中将module1 + 2和web-module设置为模块,以便显示,但是如何让sql和lib文件夹显示在项目面板中?它们应该包含在VCS中,但IntelliJ忽略它们.如何在模块外添加文件夹到项目?
项目和资源管理器视图的屏幕截图:

我们正在使用Jenkins,只是从没有身份验证的基于文件的git repo切换到使用GitBlit通过http进行适当的身份验证.
问题是 - maven如何在批处理模式下验证自己?
使用-Dusername和更新每个作业-Dpassword(并因此将密码存储在作业中)似乎不太可行.我已经读过settings.xml应该通过将git服务器指定为id来使用git,但是无论我做什么都没有效果(即发布插件提示输入凭据).
<properties>
<project.scm.id>git</project.scm.id>
</properties>
<scm>
<connection>scm:git:http://myserver:8081/r/gitauthtest.git</connection>
<developerConnection>scm:git:http://myserver:8081/r/gitauthtest.git</developerConnection>
</scm>
Run Code Online (Sandbox Code Playgroud)
<settings>
<servers>
<server>
<id>git</id>
<username>myUser</username>
<password>myPassword</password>
</server>
</servers>
</settings>
Run Code Online (Sandbox Code Playgroud)
有没有办法让这个工作?我无法相信一项简单且极为常见的任务,因为它没有简单的标准解决方案.
我们最近开始在生产环境上遇到一个奇怪的错误(测试环境工作正常).
java.lang.IllegalArgumentException:非法模式字符'y'
这是由以下代码引起的
SimpleDateFormat dateFormat = (SimpleDateFormat)DateFormat.getDateInstance();
dateFormat.applyLocalizedPattern("yyyy-MM-dd");
Run Code Online (Sandbox Code Playgroud)
例如,当使用'Y'而不是'y'表示年份时,通常会抛出此错误.如上所示,这不是这种情况.我不是100%确定服务器上设置的语言环境.Linux env LANG设置为"de_DE.UTF_8",因此可能会使用它.
输入SimpleDateFormat.java的源代码我找到了方法translatePattern(String pattern, String from, String to).这会抛出当patternfrom中不存在任何字符时提到的异常.在其他计算机上本地调试时,值看起来像这样
pattern ="yyyy-MM-dd"
from ="GyMdkHmsSEDFwWahKzZ"
从服务器上的例外来看,很明显第一个'y'不存在from.from从中获取formatData.getLocalPatternChars(),这是DateFormatSymbols从服务器上的语言环境初始化的.
是否有可用的格式没有'y'?这个错误已经开始发生而没有任何代码更改,据我所知,没有更改服务器配置.
假设我们有两个实体,A和B. B与A有多对一的关系如下:
@Entity
public class A {
@OneToMany(mappedBy="a_id")
private List<B> children;
}
@Entity
public class B {
private String data;
}
Run Code Online (Sandbox Code Playgroud)
现在,我想删除A对象并将删除级联到其所有子对象(B).有两种方法可以做到这一点:
1)添加cascade=CascadeType.ALL, orphanRemoval=true到OneToMany注释,让JPA在从数据库中删除A对象之前删除所有子项.
2)按原样保留类,只需让数据库级联删除即可.
使用后面的选项有什么问题吗?它会导致实体管理器保留对已删除对象的引用吗?我选择第二个选项的原因是选项一生成n + 1个SQL查询以进行删除,当对象A包含大量子节点时可能需要较长时间,而选项二只生成一个SQL查询然后继续愉快.对此有什么"最佳实践"吗?
我有几个页面需要userId才能工作,因此以下代码:
userpage.xhtml
<!-- xmlns etc. omitted -->
<html>
<f:metadata>
<f:viewParam name="userId" value="#{userPageController.userId}"/>
</f:metadata>
<f:view contentType="text/html">
<h:head>
</h:head>
<h:body>
<h:form>
<h:commandButton action="#{userPageController.doAction}" value="post"/>
</h:form>
</h:body>
</f:view>
Run Code Online (Sandbox Code Playgroud)
userPageController.java
@Named
@ViewScoped
public class userPageControllerimplements Serializable {
private static final long serialVersionUID = 1L;
@Inject protected SessionController sessionController;
@Inject private SecurityContext securityContext;
@Inject protected UserDAO userDAO;
protected User user;
protected Long userId;
public UserPage() {
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Long …Run Code Online (Sandbox Code Playgroud) 我在几个场景中使用EJB继承,有时在超类中使用注释,就像这个通用实体DAO:
public class JpaDAO<T>{
protected Class<T> entityClass;
@PersistenceContext(unitName="CarrierPortalPU")
protected EntityManager em;
protected CriteriaBuilder cb;
@PostConstruct
private void init() {
cb = em.getCriteriaBuilder();
}
public JpaDAO(Class<T> type) {
entityClass = type;
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void create(T entity) {
em.persist(entity);
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public T find(Object id) {
return em.find(entityClass, id);
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public List<T> findAll(){
CriteriaQuery<T> cq = cb.createQuery(entityClass);
Root<T> entity = cq.from(entityClass);
cq.select(entity);
return em.createQuery(cq).getResultList();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void remove(T entity) {
em.remove(em.merge(entity));
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public T edit(T entity) {
return …Run Code Online (Sandbox Code Playgroud) 在常见的MVC设计应用程序中,使服务层依赖于用户会话是一个坏主意吗?假设有一种服务方法从数据库中提取一些对象,并且您希望根据初始化调用的人返回不同的结果 - 例如,管理员可能获得10行对象,而普通用户可能只获得7行因为最后3个是"仅限管理员"的对象.解决这个问题的几种方法是:
最近,我开始越来越多地使用最后一种方法,因为它提供了一个干净的界面,并且使用起来非常实用.过滤器确保当前线程始终具有用户设置.这是不好的设计吗?我相信有些人可以将其视为从服务层到Web层的依赖,尽管我个人认为它们非常不相关.最大的后果是方法行为会因另一个类的状态而有所不同,这可能既是坏事也是好事.
你对此有何看法?如果这是一个糟糕的解决方案,那么什么会更强大?
我正在使用JPA/EJB/JSF开发Java EE6项目,我在为实体设计多语言支持方面遇到了一些麻烦.有三个相关实体:
语言(具有id)
能力(具有id)
CompetenceName(具有能力参考,语言参考和字符串)
Competence对使用Map实现的CompetenceName有一对多的引用,每个语言都包含一个对象,其中存在一个Competence的名称.请注意,权限是动态创建的,因此它们的名称不能存在于资源包中.
在网页上列出Competences时,我希望它们以当前登录用户的语言显示,它存储在Session Scoped Managed Bean中.
有没有什么好方法可以在不破坏MVC设计的情况下实现这一目标?我的第一个想法是通过FacesContext直接从Competence实体中的"getName"方法获取会话范围bean,并在CompetenceNames的地图中查找如下:
public class Competence
{
...
@MapKey(name="language")
@OneToMany(mappedBy="competence", cascade=CascadeType.ALL, orphanRemoval=true)
private Map<Language, CompetenceName> competenceNames;
public String getName(String controller){
FacesContext context = FacesContext.getCurrentInstance();
ELResolver resolver = context.getApplication().getELResolver();
SessionController sc = (SessionController)resolver.getValue(context.getELContext(), null, "sessionController");
Language language = sc.getLoggedInUser().getLanguage();
if(competenceNames.get(language) != null)
return competenceNames.get(language).getName();
else
return "resource missing";
}
Run Code Online (Sandbox Code Playgroud)
这个解决方案感觉非常粗糙,因为实体依赖于Controller层,并且每次我想要它的名字时都必须获取会话控制器.更符合MVC的解决方案是采用Language参数,但这意味着来自JSF的每一次调用都必须包含从会话作用域托管bean中获取的语言,这也不是一个好的解决方案.
有没有人对此问题有任何想法或设计模式?
在"创建新用户"jsf页面中,我有一个带有自定义转换器的SelectOneMenu和一个noSelectionOption selectItem,如下所示:(无关代码无关)
NewUser.xhtml
<h:form>
<h:selectOneMenu value="#{newUserController.user.department}"
required="true" converter="departmentConverter">
<f:selectItem itemLabel="Select a department" noSelectionOption="true"/>
<f:selectItems value="#{newUserController.departments}"
var="dep" itemLabel="#{dep.name}" itemValue="#{dep}"/>
</h:selectOneMenu>
<p:commandButton action="#{newUserController.saveUser}"
value="#{bundle.Save}"
ajax="false"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
NewUserController.java
@ManagedBean
@ViewScoped
public class NewUserController implements Serializable {
private static final long serialVersionUID = 10L;
@EJB private UserBean userBean;
private List<Department> departments;
private User user;
public NewUserController () {
}
@PostConstruct
public void init(){
user = new User();
departments = userBean.findAllDepartments();
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user …Run Code Online (Sandbox Code Playgroud) 是否可以在注释中使用类的简单名称?我的目标是使用包含该类的JNDI名称来获得注入的编译时安全性.
示例(我想要做的,这在编译时失败):
@EJB(mappedName = "java:module/" + MyService.class.getSimpleName())
private MyService myService;
Run Code Online (Sandbox Code Playgroud)
class.getSimpleName()似乎在运行时被解析,这不适用于注释.我可以以某种方式将它作为常量吗?
java ×3
annotations ×2
jpa ×2
jpa-2.0 ×2
jsf ×2
jsf-2 ×2
architecture ×1
converter ×1
database ×1
eclipselink ×1
ejb ×1
ejb-3.1 ×1
git ×1
inheritance ×1
java-ee-6 ×1
locale ×1
maven ×1
sql ×1
viewparams ×1