我正在尝试使用RestTemplate上传一个文件,代码如下.
MultiValueMap<String, Object> multipartMap = new LinkedMultiValueMap<>();
multipartMap.add("file", new ClassPathResource(file));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(new MediaType("multipart", "form-data"));
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<MultiValueMap<String, Object>>(multipartMap, headers);
System.out.println("Request for File Upload : " + request);
ResponseEntity<byte[]> result = template.get().exchange(
contextPath.get() + path, HttpMethod.POST, request,
byte[].class);
Run Code Online (Sandbox Code Playgroud)
我有MultipartResolverbean和Controller代码
@RequestMapping(value = "/{id}/image", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
@Transactional(rollbackFor = Exception.class)
public byte[] setImage(@PathVariable("id") Long userId,
@RequestParam("file") MultipartFile file) throws IOException {
// Upload logic
}
Run Code Online (Sandbox Code Playgroud)
我得到以下例外
org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'file' is not …Run Code Online (Sandbox Code Playgroud) I'm new to stackoverflow, but read tons of posts here and now stuck.my application.properties is read, but the portion for configuring hikaricp is ignored/has no effect.
I read https://www.javadevjournal.com/spring-boot/spring-boot-hikari/ and folowed those steps there, still any success.
pom.xml
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.4.10.Final</version>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
<version>5.4.10.Final</version>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions> …Run Code Online (Sandbox Code Playgroud) 我正在使用带有Spring Data Jpa的Query DSL QueryDslPredicateExecutor
我有以下实体;
@Table(name="a_table")
@Entity
public class A {
@OneToOne
@JoinColumn(name = "b_id")
private B b;
}
@Table(name="b_table")
@Entity
public class B {
@Column(...)
private String name;
}
Run Code Online (Sandbox Code Playgroud)
当我构建Predicate传递到我的存储库时,我做了类似的事情.
QA qa = QA.a;
BooleanBuilder booleanBuilder = new BooleanBuilder();
for(String name : strings) {
BooleanExpression b_name_eq= qa.b.name.eq(name);
BooleanExpression some_other_expression = ...;
booleanBuilder.or(ExpressionUtils.and(b_name_eq, some_other_expression));
}
return booleanBuilder.getValue();
Run Code Online (Sandbox Code Playgroud)
这会产生如下查询
select ... , ... , ...
from a_table at
cross join b_table bt
where at.b_id=bt.id
and (bt.name=? and some_other_expression …Run Code Online (Sandbox Code Playgroud) config ×1
cross-join ×1
hikaricp ×1
java ×1
querydsl ×1
resttemplate ×1
spring ×1
spring-boot ×1
spring-mvc ×1