是否有方法或一些智能方法易于阅读,以便在Groovy中组合元素?我知道Iterable#combinations或者GroovyCollections#combinations它实现了重复的部分排列,因为我理解它到目前为止.见例子.
// Groovy combinations result
def e = ['a', 'b', 'c']
def result = [e, e].combinations()
assert [['a', 'a'], ['b', 'a'], ['c', 'a'], ['a', 'b'], ['b', 'b'], ['c', 'b'], ['a','c'], ['b', 'c'], ['c', 'c']] == result
// What I'm looking for
def e = ['a', 'b', 'c']
def result = ???
assert [['a', 'b'], ['a', 'c'], ['b', 'c']] == result
Run Code Online (Sandbox Code Playgroud)
随意发布替代解决方案.我仍然在寻找更好的可读性(它在非开发人员的脚本中使用)和性能(没有不必要的迭代).
我有hibernate查询性能的问题,我无法弄清楚.在下面的代码片段中,我需要选择具有至少一个映射和过滤映射的实体.我正在使用FETCH JOIN来加载仅过滤的映射.但在这种情况下,我的查询存在性能问题.Hibernate说警告日志:
org.hibernate.hql.ast.QueryTranslatorImpl - 使用collection fetch指定的firstResult/maxResults; 在记忆中应用!
当我省略FETCH JOIN并且只剩下JOIN查询时很快.但结果我将所有映射加载到实体,这对我来说是不可接受的状态.有没有办法提高查询性能?映射表中有很多行.
HQL查询:
select distinct e from Entity
join fetch e.mappings as mapping
where e.deleted = 0 and e.mappings is not empty
and e = mapping.e and mapping.approval in (:approvals)
Run Code Online (Sandbox Code Playgroud)
实体:
@Entity
@Table(name="entity")
class Entity {
...
@OneToMany(mappedBy="entity", cascade=CascadeType.REMOVE, fetch=FetchType.LAZY)
@OrderBy("created")
private List<Mapping> mappings = new ArrayList<Mapping>();
...
}
@Entity
@Table(name="mapping")
class Mapping {
public static enum MappingApproval {
WAITING, // mapping is waiting for approval
APPROVED, // mapping was approved
DECLINED; // …Run Code Online (Sandbox Code Playgroud) 在使用MVP架构设计应用程序时,我提出了关于实例化视图的问题.在我的情况下,演示者必须与视图完全分离,以便轻松更改UI工具包.只要只有一个视图,一切都很清楚.当需要动态创建视图时,我的问题出现了.例如,当单击新按钮时,弹出窗口要求用户填写一些数据.我有两个解决方案,但我对其他人感到好奇.我在下面给出了我的方法的示例代码.
让我们的父视图实例化对话框视图并将其返回到父对象,其中对话框演示者也实例化.我不喜欢具体视图必须实例化另一个视图的想法.我有一种感觉,实例化不是视图的责任.
public interface View {
public void setPresenter(Presenter presenter);
public void showView();
}
public interface NewDialogView implements View {
/* ommited ordinary getters/setters for view */
}
public interface MainWindowView implements View {
/* ommited ordinary getters/setters for view */
public NewDialogView createNewDialog();
}
public interface Presenter {
public View getView();
}
public class NewDialogPresenter implements Presenter {
protected NewDialogView view;
public MainWindow(NewDialogView view) {
this.view = view;
this.view.setPresenter(this);
}
public View getView() {
return view;
}
}
public …Run Code Online (Sandbox Code Playgroud)用Joda-Time图书馆代表一年中最好的方式是什么?我正在寻找一些像YearMonth年份一样优雅的东西.
我正在尝试编写一个简单的 WebApp 来将文件上传到 MongoDB 数据库中。我可以上传文档的主题和对象的日期(作为字符串数据类型)。我现在正在尝试将实际文件上传到 MongoDB,但事实证明这很困难。我尝试了 MultipartFile,但它不会加载文件。然后我尝试将字符串获取到文件路径并产生空指针异常(可能是因为字符串路径指向本地资源,而不是在服务器上)。
如何使用 web 应用程序将文件上传到 MongoDB?我为所有的代码道歉,但我不知道我应该发布多少。
错误:
java.lang.NullPointerException
at java.io.File.<init>(File.java:251)
at com.jcdc.domain.FileUpload.setFile(FileUpload.java:34)
at com.jcdc.controller.DocumentController.create(DocumentController.java:43)
at com.jcdc.controller.DocumentController$$FastClassByCGLIB$$f5f3eaff.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.interceptor.CustomizableTraceInterceptor.invokeUnderTrace(CustomizableTraceInterceptor.java:256)
at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at com.jcdc.controller.DocumentController$$EnhancerByCGLIB$$6b66bfcf.create(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) …Run Code Online (Sandbox Code Playgroud) 随着我正在努力的项目变得越来越大,我开始非常不确定将类分成包.假设项目有很多层,在这些层中是接口和实现,甚至更多的子层(组件).我总是最终得到很多包装,这些包装开始变得有点混乱.
所以我想知道其他人使用包的方法.你喜欢有很多课程很少的课程或很少有课程的课程吗?您更喜欢将实现与接口分开吗?等等...一般来说,您使用套餐的日常习惯以及您的方法的优点/缺点.
谢谢你的帖子.
我想知道是否在JAVA中将计算数据写入文本文件.我的JAVA代码是基于GUI的gpa计算器.我只想添加一个JButton和ActionListener,它将类名,GPA点和计算出的GPA写入.txt文件.
这是我的JFrame驱动程序代码:
import javax.swing.JFrame;
public class Driver00
{
public static void main(String[] args)
{
/*
* Create a frame (outside box) and write what text
* will be displayed as the frame title
*/
JFrame frame = new JFrame("PHILIP MCQUITTY");
// give frame a size
frame.setSize(520, 375);
// set location on the computer screen will frame appear
frame.setLocation(400, 166);
// use this so when you press X in corner, frame will close
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Add your panel to the frame. …Run Code Online (Sandbox Code Playgroud) 使用MyBatis定义集合实现的正确方法是什么?考虑下面的例子。我想LinkedHashSet从映射返回。Set如果我不想LinkedHashSet在映射接口中进行硬编码,应该在哪里指定实现。
映射片段:
<select id="selectAll" resultType="Language">
SELECT
<include refid="languageColumns"/>
FROM language
ORDER BY ord
</select>
Run Code Online (Sandbox Code Playgroud)
映射界面:
public interface LanguageDAO {
public Set<Language> selectAll();
}
Run Code Online (Sandbox Code Playgroud) 我如何使用JFace API设置不可调整大小的窗口.考虑下面创建应用程序窗口的代码.我找不到任何设置窗口的方法,因为在shell对象或应用程序窗口父级上无法调整大小.有什么我想念的吗?
public class Application extends ApplicationWindow
{
public Application()
{
super(null);
}
protected Control createContents(Composite parent)
{
prepareShell();
return parent;
}
protected void prepareShell() {
Shell shell = getShell();
shell.setSize(450, 300);
}
public static void main(String[] args)
{
Application app = new Application();
app.setBlockOnOpen(true);
app.open();
Display.getCurrent().dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
有没有办法使用SpringMVC设置MyBatis以获得整个http请求的一个事务?通常OpenSessionInViewFilter在MyBatis中有类似Hibernate的东西,还是应该编写自己的过滤器来实现这种行为?
java ×9
mybatis ×2
file ×1
file-upload ×1
groovy ×1
hibernate ×1
jface ×1
jodatime ×1
mongodb ×1
mvp ×1
organization ×1
package ×1
resizable ×1
set ×1
spring ×1
spring-mvc ×1
sql-order-by ×1
swt ×1
text ×1
week-number ×1