我有一个junit测试方法,它将CommonsMultipartFile对象作为参数.
我正在尝试创建一个FileItem对象,以便将其传递给构造函数,
CommonsMultipartFile(org.apache.commons.fileupload.FileItem fileItem)
Run Code Online (Sandbox Code Playgroud)
为此,我尝试使用DiskFileItem构造函数创建FileItem对象,
DiskFileItem(java.lang.String fieldName, java.lang.String contentType, boolean isFormField, java.lang.String fileName, int sizeThreshold, java.io.File repository)
Run Code Online (Sandbox Code Playgroud)
但我不知道如何传递任何这些参数.
我所有这些都在Spring 3 MVC控制器中工作,但是为了进行junit测试,我需要传递一个方法两个对象.一个是UploadItem对象,如下所示,
import org.springframework.web.multipart.commons.CommonsMultipartFile;
public class UploadItem {
private String fileName;
private String filePath;
private CommonsMultipartFile fileData;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public CommonsMultipartFile getFileData() {
return fileData;
}
public void setFileData(CommonsMultipartFile fileData) { …Run Code Online (Sandbox Code Playgroud) 所以我有一个主JSP索引页面"index.jsp",它有几个包含.就像是,
<%@ include file="/WEB-INF/views/includes/jstl/include.jsp" %>
<%@ include file="/WEB-INF/views/includes/licenses/license.jsp" %>
<%@ include file="/WEB-INF/views/includes/generalHtml/header.jsp" %>
<%@ include file="/WEB-INF/views/includes/navigation/navbar.jsp" %>
<%@ include file="/WEB-INF/views/includes/generalHtml/footer.jsp" %>
Run Code Online (Sandbox Code Playgroud)
"include.jsp"包含字符串"String basePath = request.getContextPath();".
"navbar.jsp"使用"basePath",但Eclipse在"navbar.jsp"的任何一行上放置一个红色X,该行使用"basePath",消息"basePath无法解析".
我的webapp工作正常,但想知道可能导致这种情况的原因,或者它是否可以解决?或者也许有办法让Eclipse忽略这个?我只想让假阳性的红色X消失.我想Eclipse并不理解"navbar.jsp"从"include.jsp"获取"basePath",因为它与"index.jsp"一起编译.
我正在开发一个最近引入lambda表达式的项目.一个例子是这样的.
public class ExampleItemWriter implements ItemWriter<MyItem> {
public void write(List<? extends MyItem> list) throws RepositoryException {
list.stream().forEach((item)->{
if (item == null) {
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
我不相信里面的细节forEach()与问题有关,但如果他们是我可以发布.在整个代码中还有一些其他类似的表达式抛出相同的异常.
java.lang.BootstrapMethodError: call site initialization exception
at java.lang.invoke.CallSite.makeSite(CallSite.java:328)
at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:296)
at com.example.repository.batch.ExampleItemWriter.write(ExampleItemWriter.java:83)
at sun.reflect.GeneratedMethodAccessor198.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy93.write(Unknown Source)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151)
at org.springframework.batch.core.step.item.FaultTolerantChunkProcessor$3.doWithRetry(FaultTolerantChunkProcessor.java:329)
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:255)
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:188)
at org.springframework.batch.core.step.item.BatchRetryTemplate.execute(BatchRetryTemplate.java:217)
at org.springframework.batch.core.step.item.FaultTolerantChunkProcessor.write(FaultTolerantChunkProcessor.java:422)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199) …Run Code Online (Sandbox Code Playgroud) 我有一个配置了 SSO 的 Argo Workflows 实例。当我单击工作流程链接时,如果我未登录,它会将我带到登录页面,这迫使我单击“登录”按钮将我重定向到我的 SSO 提供商,然后在成功时将我重定向到工作流程。
有谁知道是否可以配置 SSO 身份验证,以便跳过登录页面并将用户直接重定向到 SSO 登录页面?我一直在浏览文档和源代码,但没有运气,我想在放弃之前我会在这里问。
首先,我有一个Spring 3.0控制器,其方法类似于以下方法.
我正在向视图传递一个名为"message"的对象,如果已经通过"doStuff"方法设置,则希望通过视图打印该消息.
@RequestMapping("/index")
public ModelAndView doStuff() {
ModelAndView mav = new ModelAndView();
Map<String, String> message = new HashMap<String, String>();
message.put("message", "Hello World");
mav.setViewName("pages/myView");
mav.addObject("message", message);
return mav;
}
Run Code Online (Sandbox Code Playgroud)
该视图类似于以下内容,
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<html>
<head>
<title>Test</title>
</head>
<body>
<c:if test="${message.message} != null">
<div class="msg">test1: ${message.message}</div>
</c:if>
<c:if test="${message.message} != ''">
<div class="msg">test2: ${message.message}</div>
</c:if>
<c:if test="${message.message}">
<div class="msg">test3: ${message.message}</div>
</c:if>
<c:if test="not empty ${message.message}">
<div class="msg">test4: ${message.message}</div>
</c:if>
<div class="msg">test5: …Run Code Online (Sandbox Code Playgroud) 我有两个实体,Document并BodyElement试图用Hibernate 4.2来坚持它们.mtdt_t填入正确的,但外键docid的mtdt_body_t表NULL.
我看到hibernate试图插入没有docid值.insert into mtdt_body_t values ( )
@Entity
@Table(name = "mtdt_t")
public class Document implements Serializable {
@Id
@Column(name = "docid", unique = true, nullable = false)
private String docid;
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@OrderColumn
@JoinColumn(name = "docid", nullable = false)
private BodyElement bodyElement;
public String getDocid() {
return docid;
}
public void setDocid(String docid) {
this.docid = docid; …Run Code Online (Sandbox Code Playgroud) 我试图创建使用Spring的批处理作业ListItemReader<String>,ItemProcessor<String, String>和ItemWriter<String>.
XML如下所示,
<job id="sourceJob" xmlns="http://www.springframework.org/schema/batch">
<step id="step1" next="step2">
<tasklet>
<chunk reader="svnSourceItemReader"
processor="metadataItemProcessor"
writer="metadataItemWriter"
commit-interval="1" />
</tasklet>
</step>
<step id="step2">
<tasklet ref="lastRevisionLoggerTasklet"></tasklet>
</step>
</job>
<bean id="svnSourceItemReader"
class="com.example.repository.batch.SvnSourceItemReader"
scope="prototype">
<constructor-arg index="0">
<list>
<value>doc1.xkbml</value>
<value>doc2.xkbml</value>
<value>doc3.xkbml</value>
</list>
</constructor-arg>
</bean>
<bean id="metadataItemProcessor"
class="com.example.repository.batch.MetadataItemProcessor"
scope="prototype" />
<bean id="metadataItemWriter"
class="com.example.repository.batch.MetadataItemWriter"
scope="prototype" />
Run Code Online (Sandbox Code Playgroud)
读者,处理者和作家都是香草,
public class SvnSourceItemReader extends ListItemReader<String> {
public SvnSourceItemReader(List<String> list) {
super(list);
System.out.println("Reading data list " + list);
}
@Override
public String read() {
String out = …Run Code Online (Sandbox Code Playgroud) 我有一个包含三列的MySQL(5.1.49)表.
mysql> create table testme(id int auto_increment, id2 int not null, somedate datetime, primary key(id));
Run Code Online (Sandbox Code Playgroud)
在我的情况下,id2不是唯一的,但我想返回具有不同id2值和max somedate的行.
这是一些示例数据.
mysql> insert into testme values (1, 5, '2012-01-02 01:01:01'),(2, 5, '2012-02-02 02:02:02'),(3, 7, '2010-01-10 11:01:33');
Run Code Online (Sandbox Code Playgroud)
这个问题几乎可以回答我的问题,但是使用额外的id字段,返回的id和id2不匹配.对于id2 = 5,它返回id = 1而不是id = 2.
mysql> select id, id2, max(somedate) from testme group by id2;
+----+-----+---------------------+
| id | id2 | max(somedate) |
+----+-----+---------------------+
| 1 …Run Code Online (Sandbox Code Playgroud) 我的目标是获取XML字符串并使用XMLBeans XmlObject解析它并添加一些子节点.
这是一个示例文档(xmlString),
<?xml version="1.0"?>
<rootNode>
<person>
<emailAddress>joefoo@example.com</emailAddress>
</person>
</rootNode>
Run Code Online (Sandbox Code Playgroud)
这是添加一些节点后我想要XML文档的方式,
<?xml version="1.0"?>
<rootNode>
<person>
<emailAddress>joefoo@example.com</emailAddress>
<phoneNumbers>
<home>555-555-5555</home>
<work>555-555-5555</work>
<phoneNumbers>
</person>
</rootNode>
Run Code Online (Sandbox Code Playgroud)
基本上,只需添加<phoneNumbers/>两个子节点的节点<home/>和<work/>.
就我而言,
XmlObject xml = XmlObject.Factory.parse(xmlString);
Run Code Online (Sandbox Code Playgroud)
谢谢
java ×5
spring ×3
jsp ×2
spring-mvc ×2
argo ×1
distinct ×1
eclipse ×1
file-upload ×1
group-by ×1
hibernate ×1
include ×1
jstl ×1
lambda ×1
maven ×1
mysql ×1
one-to-one ×1
spring-batch ×1
validation ×1
xml ×1
xmlbeans ×1