是否有必要包裹背衬物体?我想做这个:
@RequestMapping(value = "/Test", method = RequestMethod.POST)
@ResponseBody
public boolean getTest(@RequestBody String str1, @RequestBody String str2) {}
Run Code Online (Sandbox Code Playgroud)
并使用这样的JSON:
{
"str1": "test one",
"str2": "two test"
}
Run Code Online (Sandbox Code Playgroud)
但相反,我必须使用:
@RequestMapping(value = "/Test", method = RequestMethod.POST)
@ResponseBody
public boolean getTest(@RequestBody Holder holder) {}
Run Code Online (Sandbox Code Playgroud)
然后使用这个JSON:
{
"holder": {
"str1": "test one",
"str2": "two test"
}
}
Run Code Online (Sandbox Code Playgroud)
那是对的吗?我的另一个选项是改变RequestMethod到GET和使用@RequestParam的查询字符串,或者使用@PathVariable与两种RequestMethod.
有一些实用方法可以创建ImmutableMaplike Immutable.of(Key, value)和它的重载.
但这种方法在课堂上HashMap或课堂上都不存在.
有没有更好的方法来做到这一点或番石榴假设这样的地图总是一个恒定的地图,是最好的选择,并不需要提供实用程序.LinkedHashMapMapsImmutableMapHashMap
我正在寻找缓存Mono(仅当它成功时)这是 WebClient 调用的结果。
通过阅读项目反应器插件文档,我不觉得CacheMono很合适,因为它也缓存了我不想要的错误。
因此,CacheMono我没有使用,而是执行以下操作:
Cache<MyRequestObject, Mono<MyResponseObject>> myCaffeineCache =
Caffeine.newBuilder()
.maximumSize(100)
.expireAfterWrite(Duration.ofSeconds(60))
.build();
MyRequestObject myRequestObject = ...;
Mono<MyResponseObject> myResponseObject = myCaffeineCache.get(myRequestObject,
requestAsKey -> WebClient.create()
.post()
.uri("http://www.example.com")
.syncBody(requestAsKey)
.retrieve()
.bodyToMono(MyResponseObject.class)
.cache()
.doOnError(t -> myCaffeineCache.invalidate(requestAsKey)));
Run Code Online (Sandbox Code Playgroud)
在这里,我调用缓存Mono,然后将其添加到咖啡因缓存中。
任何错误都会输入doOnError以使缓存无效。
这是缓存MonoWebClient 响应的有效方法吗?
我需要使用CloudFormation模板为Auto Scaling组中的实例设置"Instance Protection"属性.
我通常在我的AWS控制台中这样做:EC2 - > Auto Scaling Groups
但我似乎无法在CloudFormation 文档中找到它
我正在部署JavaFX应用程序,但我不太确定需要签署什么和不需要签名.这是我的想法:
- 安装文件: 显然需要签名.
- 启动应用程序的EXE: 我认为这需要签名,虽然感觉有点好笑,因为它不是我的代码.
- 我的JAR文件:我相信这些也需要签名,但我不确定如果不这样做会发生什么可怕的事情.
- 我从网上抓起的图书馆JAR:我不觉得我应该签署这些.有什么理由吗?
- Java运行时: 我猜我没有理由签署这个,如果我这样做,我可能会违反某些协议.
- JNLP文件: 不使用此,没理由触及此.
我看得出来了吗?我签署了正确的文件吗?
在我目前的Java/Spring项目中,我正处于与PayPal集成的阶段.在配置Java类来处理付款流程后,按照此处的说明,我运行我的应用程序并尝试使用paypal签出订单.
我被正确地重定向到PayPal登录页面,并在登录后进入此付款审核页面:
但是在我点击"继续"后,我没有完成付款,而是重定向到我的个人资料页面.
这是我的代码:
Paypal prop = this.paypalDao.get();
String clientId = prop.getClientID();
String clientSecret = prop.getClientSecret();
APIContext apiContext = new APIContext(clientId, clientSecret, "sandbox");
if(payerId != null) {
if(guid != null) {
Payment payment = new Payment();
payment.setId(map.get(guid));
PaymentExecution paymentExecution = new PaymentExecution();
paymentExecution.setPayerId(payerId);
payment.execute(apiContext, paymentExecution);
String url = request.getContextPath();
return url+"/orders";
}
} else {
List<Produto> lista_de_produtos = this.getListaDeProdutos(clienteId);
Double total = 0.0;
for(Produto produto : lista_de_produtos)
total = total + produto.getPreco();
DecimalFormat df = new DecimalFormat("0.00");
String …Run Code Online (Sandbox Code Playgroud) 我有以下课程:
public class A{
List<AA> aaList;
public A(List<AA> aaList){
this.aaList = aaList;
}
//getters and setters + default constructor
public class AA {
String aaString;
public AA(String aaString){
this.aaString = aaString;
}
//getters and setters + default constructor
}
}
Run Code Online (Sandbox Code Playgroud)
我希望有两个同类的对象,让我们说:
A a = new A(Arrays.asList(new A.AA(null)));
A a2 = new A(Arrays.asList(new A.AA("test")));
Run Code Online (Sandbox Code Playgroud)
当我映射a到时a2,a2应该保留,test因为a有一个null.
我该如何配置Orika?
我尝试过类似的东西:
mapperFactory.classMap(A.AA.class, A.AA.class)
.mapNulls(false)
.byDefault()
.register();
mapperFactory.classMap(A.class, A.class)
.mapNulls(false)
.customize(new CustomMapper<A, …Run Code Online (Sandbox Code Playgroud) 我的MapReduce必须从HBase读取记录并需要写入zip文件.我们的客户特别询问减速器输出文件应该只是.zip文件.
为此,我编写了ZipFileOutputFormat包装来压缩记录并写入zip文件.
此外,我们不能使用缓冲区并将所有行保留到缓冲区然后迭代,因为某些文件包含19GB的记录,那时它将抛出一个java.lang.OutOfMemoryError.
一切似乎都好,但有一个问题:
该.zip是越来越为每个键创建的文件.在我的输出文件中,我可以看到许多输出文件,这些是每行键分隔文件.我不知道如何将它组合在zip文件中.
这是我的实施 ZipFileOutputFormat.java
public class ZipFileOutputFormat<K, V> extends FileOutputFormat<K, V> {
public static class ZipRecordWriter<K, V> extends org.apache.hadoop.mapreduce.RecordWriter<K, V> {
private ZipOutputStream zipOut;
public ZipRecordWriter(FSDataOutputStream fileOut) {
zipOut = new ZipOutputStream(fileOut);
}
@Override
public void close(TaskAttemptContext context) throws IOException, InterruptedException {
// TODO Auto-generated method stub
zipOut.closeEntry();
zipOut.finish();
zipOut.close();
zipOut.flush();
}
@Override
public void write(K key, V value) throws IOException {
String fname = null;
if (key instanceof …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Spring Framework Cloud 创建一个 Maven 项目。我定义了 pom.xml 文件如下
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.RELEASE</version>
</parent>
<properties>
<!-- Stand-alone RESTFul application for testing only -->
<start-class>io.pivotal.microservices.services.Main</start-class>
</properties>
<dependencies>
<dependency>
<!-- Setup Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<!-- Setup Spring MVC & REST, use Embedded Tomcat -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<!-- Setup Spring Data common components -->
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<!-- Testing starter -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<!-- Setup Spring Data JPA Repository support …Run Code Online (Sandbox Code Playgroud) 是否可以保证在线程持有其监视器时不会对对象进行垃圾回收?
例如
class x {
private WeakReference<Object> r;
Object getMonitorObject() {
Object o = new Object();
r = new WeakReference<>(o);
return o;
}
void thread1() throws Exception {
synchronized (getMonitorObject()) {
Thread.sleep(3000);
}
}
void thread2() {
Object b = r.get();
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,是否有任何保证在另一个线程正在休眠时b被非nullif thread2()调用thread1()?让我们假设整个过程thread2()是thread1()在另一个线程中休眠时执行的。
我在 Hibernate 和 Spring 中使用 Hibernate 验证器,但似乎验证不起作用。当我不输入字符串或输入 1 个字符的字符串(不在min=4和之间max=20)时,不会显示任何错误,因此会保存在表中。我错过了什么?
package dao;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@Entity
@Table(name="etudiant")
public class Etudiant {
@Id
@Column(name="ID_ETUDIANT")
@GeneratedValue
private Long idEtudiant;
@Column(name="NOM")
@Size (min=4, max=20)
private String nom;
@Size(min=4, max=20, message="nom doit etre entre 4 et 20 svp..")
@Column(name="PRENOM")
private String prenom;
@Column(name="DATE_NAISSANCE")
@Temporal(TemporalType.DATE)
private Date dateNaissance;
@NotNull
@Column(name="EMAIL")
private String email;
public Etudiant() …Run Code Online (Sandbox Code Playgroud) java ×9
spring ×3
amazon-ec2 ×1
code-signing ×1
collections ×1
guava ×1
h2 ×1
hadoop2 ×1
hibernate ×1
http ×1
javafx ×1
mapper ×1
mapreduce ×1
maven ×1
null ×1
orika ×1
paypal ×1
pom.xml ×1
primary-key ×1
spring-cloud ×1
spring-mvc ×1
validation ×1
zip ×1