小编Man*_*dit的帖子

如何为List <Class name>创建JSONArray

我有一个叫做的课

class Student {
   String name;
   String age;
}
Run Code Online (Sandbox Code Playgroud)

我有一个返回List对象的方法

public List<Student> getList(){

 List<Student> li =new ArrayList();
 ....

 li.add(new Student('aaa','12'));
 ... 

 return li;    
}
Run Code Online (Sandbox Code Playgroud)

我需要将该列表转换为JSONArray

[{"name":"sam","age":"12"},{"name":"sri","age":"5"}]
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我这个吗?先谢谢你...

java json list arraylist

13
推荐指数
4
解决办法
7万
查看次数

Netbeans拒绝自动建议已知的进口类

我刚刚发现我的NetBeans突然停止导入Java API中的类,但仍然可以从我的外部库中导入类.看看下面的图片:

NetBeans编辑器

正如你所看到的,List并且ArrayListjava.util包中的类,但是这里没有显示导入它们的通常建议,而是要求我创建类.我知道我可以输入import java.util.List;代码的顶部,但之前的生活更好!我需要帮助谢谢.

java import netbeans autosuggest

12
推荐指数
2
解决办法
4981
查看次数

Java中如何获取字符类型的类别名称?

返回Character.getType(int codePoint)一个整数,但我找不到从中获取 unicode 类别名称(例如“Lu”或“Cn”)的方法。Character.getCategoryTypeName(int codePoint)我想要的是一个返回表示类型的字符串的方法。

类别名称位于常量注释中,一种方法是为返回的类型编写一个 switch case,然后手动对类型名称进行编码,如下所示:

我原来的计划是这样的:

for (int i = 0; i <= 0x10FFFF; i++) {
    switch (Character.getType(i)) {

        // General category "Sc" in the Unicode specification.
        // public static final byte CURRENCY_SYMBOL = 26;
        case Character.CURRENCY_SYMBOL: 
            map.put(i, "Sc");
            break;

        ....
     }
}
Run Code Online (Sandbox Code Playgroud)

但这会非常乏味。是否有自动方法或库来完成任务?

java unicode character

6
推荐指数
1
解决办法
1886
查看次数

无法找到XML架构命名空间的Spring NamespaceHandler

我遇到了以下问题.我正在尝试使用Maven或Ivy插件为eclipse从pom.xml文件生成deps并运行GWT webapp.我已经检查过100次spring-tx在依赖项中.我正在使用所有3.1.3版本的spring.jar就在类路径上.我手动检查了maven依赖库列表(对于Ivy来说是pom.xml*).我还检查了META-INF/*文件在jar中的位置并没有损坏.

我没有使用maven来构建/运行任何东西,但是eclipse调试目标来运行GWT webapp.

我在互联网上看到很多线程但没有解决我的问题.相关:http://jira.codehaus.org/browse/MASSEMBLY-360

有人能指出这个问题可能的根本原因吗?

违规资源:ServletContext资源[/WEB-INF/applicationContext.xml]; 嵌套异常是org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法找到XML架构命名空间的Spring NamespaceHandler [http://www.springframework.org/schema/tx]攻击资源:类路径资源[应用程序-context/hibernate.xml]:org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法找到XML架构命名空间的Spring NamespaceHandler [http://www.springframework.org/schema/tx]攻击资源:类路径资源[application-context/hibernate.xml]

  at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
  at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
  at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
Run Code Online (Sandbox Code Playgroud)

这是我的maven pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>UserInterface</groupId>
    <artifactId>UserInterface</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>3.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.9.Final</version>
        </dependency>
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.2-pre8</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>4.1.9.Final</version>
            <exclusions>
                <exclusion>
                    <artifactId>c3p0</artifactId>
                    <groupId>c3p0</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency> …
Run Code Online (Sandbox Code Playgroud)

spring xsd namespaces

5
推荐指数
0
解决办法
2177
查看次数

Spring Boot 2.5.0、Spring Cloud 2020.0.2 和 Hibernate 5.4.31 - H2 数据库多行插入失败

在使用 SB 版本 2.5.0、Spring Cloud(用于集中配置 2020.0.2)开发 Spring Boot 应用程序时,Hibernate 版本为 5.4.31(我没有使用特定的 Hibernate 版本,它是根据 Spring Boot 兼容性)。使用 H2 数据库作为内存数据,因为我需要创建用于演示的示例应用程序。

在资源文件夹中,我确实有我的 SQL 文件。当我命名它时,data.sql应用程序根本不会启动。当我将此文件重命名为 时import.sql,我的应用程序启动了,但仍然面临多行插入问题。

数据插入SQL文件

/* Data for Entity DataTable */
    INSERT INTO data_table (name) VALUES
    ('Data 1'),
    ('Data 2'),
    ('Data 3');
Run Code Online (Sandbox Code Playgroud)

当我的应用程序使用 Spring Boot 2.3.10.RELEASE 和 Spring Cloud Hoxton.SR5 运行时,这工作得非常好。

我也尝试过JPA和Hibernate的属性来解决这个问题,但仍然没有成功。查找我使用的属性如下:

spring.jpa.properties.hibernate.jdbc.batch_size=20
spring.jpa.properties.hibernate.order_inserts=true
Run Code Online (Sandbox Code Playgroud)

由于更新了 Spring Boot 和 Spring Cloud 版本,我不确定是否有什么特别需要设置 H2 数据库以用于多行插入。

看起来与 Hibernate 或 H2 数据库问题相关。

WARN 7952 --- [           main] o.h.t.s.i.ExceptionHand lerLoggedImpl    : GenerationTarget encountered …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa h2 spring-boot

5
推荐指数
1
解决办法
2779
查看次数

如何用putty维护Session?

我发现当我使用putty进行UNIX服务器连接时,它会在一段时间后得到超时消息.每当我打开已经连接的putty窗口时,它已经闲置了30分钟,它会超时,我必须再次登录到新的putty会话.

unix putty session-timeout

4
推荐指数
1
解决办法
6401
查看次数

如何在Android中的switch case中使用String []输入?

如何在开关盒中使用字符串数组的输入?

String[] mon=new String[]{"January","February","March","April","May","June","July","August","September","October","November","December"};

switch (mon)
{
    case "January":
        m=1;
        break;
    case "February":
        m=1;
        break;                  
}
Run Code Online (Sandbox Code Playgroud)

java arrays switch-statement

4
推荐指数
1
解决办法
4590
查看次数

包装类java中的奇怪行为

public class Test {
    public static void main(String args[]) {
        int i = 10;
        Integer a = new Integer(i);
        System.out.println(a);        //tostring method overriden
        System.out.println(a.hashCode());
    }
}
Run Code Online (Sandbox Code Playgroud)

产量:
10
10

现在我的问题是为什么hashCode()在这种情况下覆盖方法.如果我想在上面的代码中找到包装类对象的对象引用.我该怎么做?

java

4
推荐指数
1
解决办法
107
查看次数

如何让一个 MySQL 用户只访问一个架构

我搜索了很多关于“如何仅允许一个用户访问一个架构”的内容,但没有找到任何令人信服的解决方案。我已经阅读GRANTREVOKE找到了解决方案,例如授予或撤销特定用户对特定表的权限。

我正在寻找的是,当有多个用户时,每个用户都可以访问定义的架构,而一个用户将拥有对一个架构的完全访问权限。而且我不希望一个用户访问另一个 Schema,除了被授予访问权限的那个。

请建议如何准确地使用GRANTREVOKE来执行此操作?

mysql permissions

4
推荐指数
1
解决办法
4698
查看次数

最终类中的Powermock静态最终方法

我正在写的测试案例:

public class AClassUnderTest {

    // This test class has a method call
    public Long methodUnderTest() {

         // Uses the FinalUtilityClass which contains static final method
         FinalUtilityClass.myStaticFinalMethod(<3-parameters-here>);

         // I want to mock above call so that test case for my "methodUnderTest" passes
    }
}
Run Code Online (Sandbox Code Playgroud)

我有一个最后一堂课.

public final class FinalUtilityClass {

   /**
    * Method has 3 parameters
    */
   public static final MyBean myStaticFinalMethod(<3-parameters-here>) {

   }
}
Run Code Online (Sandbox Code Playgroud)

我已经在我的测试类中添加了以下代码:

@RunWith(PowerMockRunner.class)
@PrepareForTest({ FinalUtilityClass.class })
Run Code Online (Sandbox Code Playgroud)

我想写一个测试用例来嘲笑它.我想模拟调用,myStaticFinalMethod()以便我可以获得预期的MyBeaninstatnce,我可以在进一步的代码中使用它来通过我的测试用例.

<3-parameters-here>是日历,字符串,字符串.

我试过做: …

java unit-testing powermockito

4
推荐指数
1
解决办法
1万
查看次数