我是GSON的新手,并获得了这种格式的JSON响应(只是一个更简单的例子,因此值没有意义):
{
"Thomas": {
"age": 32,
"surname": "Scott"
},
"Andy": {
"age": 25,
"surname": "Miller"
}
}
Run Code Online (Sandbox Code Playgroud)
我希望GSON使它成为一个Map,PersonData显然是一个Object.名称字符串是PersonData的标识符.
正如我所说,我对GSON很新,只尝试过类似的东西:
Gson gson = new Gson();
Map<String, PersonData> decoded = gson.fromJson(jsonString, new TypeToken<Map<String, PersonData>>(){}.getType());
Run Code Online (Sandbox Code Playgroud)
但这引发了错误:
Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 3141
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏:)
我需要在后台实现一项任务,那么我的任务是什么?我有一个存储每个客户租金金额的表,所以我需要在特定的datetime
ackf 之后计算每个月的租金价格,所以我用谷歌搜索它,我发现了一段代码(它是nuget叫webbackgrounder
)我把它添加到我的解决方案,它给了我这部分代码来处理我的任务:
using System;
using System.Threading;
using System.Threading.Tasks;
namespace WebBackgrounder.DemoWeb
{
public class SampleJob : Job
{
public SampleJob(TimeSpan interval, TimeSpan timeout)
: base("Sample Job", interval, timeout)
{
}
public override Task Execute()
{
return new Task(() => Thread.Sleep(3000));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道如何编写我的任务?
更多细节:这里
我发现这篇文章,但实际上我不知道我可以长时间使用这种方法吗?最好的祝福 .
任何想法将不胜感激.
所以我正在阅读泛型方法,我感到困惑.我先说一下这个问题:
在这个例子中:假设我需要一个适用于任何类型T的selectionSort版本,通过使用调用者提供的外部可比较.
第一次尝试:
public static <T> void selectionSort(T[] arr, Comparator<T> myComparator){....}
Run Code Online (Sandbox Code Playgroud)
假设我有:
现在,我这样做:
selectionSort(arr, myComparator);
Run Code Online (Sandbox Code Playgroud)
并且它不起作用,因为myComparator不适用于Vehicle的任何子类.
然后,我这样做:
public static <T> void selectionSort(T[] arr, Comparator<? super T> myComparator){....}
Run Code Online (Sandbox Code Playgroud)
这个声明会起作用,但我不完全确定我一直在做什么......我知道使用是要走的路.如果"?super T"的意思是"一个未知的超类型T",那么我是强加上限还是上限?为什么超级?我的目的是让T的任何子类使用myComparator,为什么"?super T".如此困惑......如果您对此有任何见解我会很感激..
谢谢!
我有一个 Spring Boot 应用程序,我正在尝试将侦听器配置为已有的队列。以下是我在application.yml
文件中配置的内容。我还使用引用 spring 文档的适当配置注释了我的配置类@EnableRabbit
和侦听器@RabbitListener
。
请注意,每个属性都有一个有效的默认值,我在将它们发布到此处之前已将其删除。
spring:
rabbitmq:
host: ${rmq_host}
port: ${rmq_port}
virtualHost: ${rmq_virtual_host}
requestedHeartbeat: ${rmq_requested_heartbeat_seconds}
listener:
simple:
concurrency: ${rmq_listener_config_concurrent_users}
autoStartup: ${rmq_listener_config_auto_startup}
acknowledge-mode: ${rmq_listener_config_ack_mode}
ssl:
enabled: ${rmq_ssl_enabled:true}
keyStore: ${rmq_ssl_keystore}
keyStorePassword: ${rmq_ssl_keystore_password}
trustStore: ${rmq_ssl_truststore}
trustStorePassword: ${rmq_ssl_truststore_password}
Run Code Online (Sandbox Code Playgroud)
使用此配置,当我尝试启动应用程序时,它会抛出以下异常。
org.springframework.amqp.rabbit.listener.exception.FatalListenerStartupException: Authentication failure
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:532)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1389)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:65)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:368)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:565)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:90)
at …
Run Code Online (Sandbox Code Playgroud) hadoop OpenJDK服务器VM警告:您已加载库/usr/lib/hadoop/lib/native/libhadoop.so.1.0.0,它可能已禁用堆栈保护.VM将尝试立即修复堆栈防护.强烈建议您使用'execstack -c'修复库,或将其与'-z noexecstack'链接.
我正在尝试安装时收到此消息,hadoop-yarn-resourcemanger
因为所有其他安装的hadoop
软件包都显示软件包在您的系统上已损坏.如何解决这个问题?谢谢
我只是尝试了一些代码片段并发现了一个观察结果,与使用 java 8 流相比,使用简单的 for 循环给了我更好的性能结果。现在,我可能在理解这些事情时错过了一些东西。我需要帮助理解差异。在下面添加我的代码。
//Following takes almost 3ms
public int[] testPerf(int[] nums, int[] index) {
List<Integer> arrayL = new ArrayList<>();
for(int i =0; i< index.length; i++){
arrayL.add(index[i], nums[i]);
}
return arrayL.stream().mapToInt(i -> i).toArray();
}
//Following takes almost 1ms
public int[] testPerf(int[] nums, int[] index) {
List<Integer> arrayL = new ArrayList<>();
for(int i =0; i< index.length; i++){
arrayL.add(index[i], nums[i]);
}
int [] result = new int[index.length];
for(int i =0; i< index.length; i++){
result[i] = arrayL.get(i);
}
return result;
} …
Run Code Online (Sandbox Code Playgroud) 我在OSX Mavericks上运行Intellij 12,尝试使用持久性方面添加已在XML中定义的数据源.
我可以找到并选择源代码,但是当我尝试测试连接时,我得到:
与XXXXX的连接失败:线程"main"中的异常java.lang.ClassNotFoundException:java.net.URLClassLoader $ 1.run(URLClassLoader.java:366)中的com.mysql.jdbc.Driver java.net.URLClassLoader $ 1.run( URLClassLoader.java:355)java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:354)at java.lang.ClassLoader.loadClass(ClassLoader.java:425)at sun .misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308)at java.lang.ClassLoader.loadClass(ClassLoader.java:358)at java.lang.Class.forName0(Native Method)at java.lang.Class.forName (Class.java:190)at com.intellij.persistence.database.console.RemoteJdbcServer.main(RemoteJdbcServer.java:15)
看起来这只是一个类路径问题,但我有一个非常艰难的时间弄清楚我要做什么才能在类路径上获取mysql jar.
我发现的每个问题都涉及将jar添加到编译或测试应用程序的类路径中,这不是我在这里寻找的.我的应用程序很好地连接到mysql,这是有问题的IntellijIDE.我在哪里需要添加此文件的路径?
你不能把大价值放在小杯子里.嗯,好的,你可以,但你会失去一些.正如我们所说,你会得到溢出.编译器试图帮助防止这种情况,如果它可以从你的代码中告诉你某些东西不适合你正在使用的容器(变量).
例如,
int x= 24;
byte b= x;
// Won't work!!
Run Code Online (Sandbox Code Playgroud)
现在字节的范围是-128
到127
.现在,我的问题是为什么这不起作用?毕竟,x
is 的值是24
,并且24
肯定足够小以适应字节(可能是一个非常新手级别的问题,但我真的很困惑这个概念).
我正在编写一个函数,我需要根据包含用户电子邮件的逗号分隔字符串从表中获取Title(例如Mr/Miss/Mrs)FirstName和LastName.
到目前为止,我试过以下
我的SQL小提琴 PS.首先在fiddler页面上构建模式,然后尝试执行查询
当我运行以下
select dbo.fn_getUserNamefrmEmail('abc.def@gmail.com')
Run Code Online (Sandbox Code Playgroud)
我得到了正确的输出 Mr. Abc Def
但是当我试着奔跑的时候
select dbo.fn_getToUserNames('abc.def@gmail.com, pqr.stu@gmail.com, xyz.mno@gmail.com, stu.v@gmail.com',',')
Run Code Online (Sandbox Code Playgroud)
我得到NULL - 0因为我将结果设置为0,如果它是NULL
我无法理解我做错了什么,需要帮助.
我已经在android中创建了一个从数组列表中生成随机文本的应用程序。现在我想分享Java代码生成的文本。这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sorella);
Resources res = getResources();
myString = res.getStringArray(R.array.myArray);
String q = myString[rgenerator.nextInt(myString.length)];
TextView tv = (TextView) findViewById(R.id.text1);
tv.setText(q);
Button home=(Button)findViewById(R.id.bottone);
home.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "HERE GENERATE TEXT FROM ARRAY LIST");
startActivity(Intent.createChooser(shareIntent, "Condividi con..."));
}
});
}
}
Run Code Online (Sandbox Code Playgroud) 我在我的spring上下文xml中有以下xml配置,我使用基于注释的方法非常少,无法弄清楚如何使用注释来表示以下内容,需要帮助.
<bean id="myPolicyAdmin" class="org.springframework.security.oauth2.client.OAuth2RestTemplate">
<constructor-arg>
<bean class="org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails">
<property name="accessTokenUri" value="${accessTokenEndpointUrl}" />
<property name="clientId" value="${clientId}" />
<property name="clientSecret" value="${clientSecret}" />
<property name="username" value="${policyAdminUserName}" />
<property name="password" value="${policyAdminUserPassword}" />
</bean>
</constructor-arg>
</bean>
Run Code Online (Sandbox Code Playgroud)
在我的java类(策略管理器)中,它被称为如下,我实际上是在引用一个示例并尝试将其转换为所有注释.
@Autowired
@Qualifier("myPolicyAdmin")
private OAuth2RestTemplate myPolicyAdminTemplate;
Run Code Online (Sandbox Code Playgroud)
编辑:我尝试创建一个bean,org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails
但不知道如何设置其属性以及如何作为构造函数args访问它myPolicyAdminTemplate
我是java新手,只是为了学习目的编写了一个程序.我有两个字符串数组,我想比较两个字符串数组的长度.如果长度相等,则将每个第一个字符串数组的值与每个第二个数组的值进行比较.如果值匹配则打印该值.无法纠正问题所在?
package com.equal.arrat;
import java.util.ArrayList;
import java.util.List;
public class ArrayEqual {
public static void main(String[] args) {
String s[] = {"anuj","kr","chaurasia"};
String s1[] = {"anuj","kr","chaurasia"};
if (s.length==s1.length)
{
System.out.println(s.length);
for (int i =0 ; i>=s.length;i++)
{
for (int j =0 ;j>=s1.length;j++)
{
System.out.println("test");
if (s[i].equals(s1[j]))
{
System.out.println("ok" + s[i]);
}
else{
System.out.println("not ok");
}
}
}
}
else{
System.out.println("Length Not Equal");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图使用Spring 3.0提供的@Async注释使方法异步
我做了以下
包括以下内容 module-context.xml
<task:executor id="initiateContactCreation" pool-size="2-10" queue-capacity="5"/>
<task:annotation-driven executor="initiateContactCreation" />
Run Code Online (Sandbox Code Playgroud)
带注释的方法 @Async
@Async
private void initiateContactCreation(String fromUserId, List<String> toUsers){
logger.info("Inside Async method for contact creation");
ContactDetails contactDetails = new ContactDetails();
contactDetails.setUserId(fromUserId);
contactDetails.setContactEmailIds(toUsers.toArray(new String[toUsers.size()]));
this.contactsAndDirSvc.addContact(contactDetails);
logger.info("Returning from Async method for contact creation");
}
Run Code Online (Sandbox Code Playgroud)
但我发现该方法不会立即返回控制.
我的记录器显示来自initiateContactCreation
日志的日志addContact
(PS.它花费时间执行此方法,我不希望它同步执行)然后从我调用的方法记录initiateContactCreation
我究竟做错了什么?