小编Gre*_*ack的帖子

Json-cpp - 如何从string初始化并获取字符串值?

我的代码崩溃(调试错误!R6010 abort()已被调用).你能帮助我吗?我也想知道如何从字符串值初始化json对象.

Json::Value obj;
obj["test"] = 5;
obj["testsd"] = 655;
string c = obj.asString();
Run Code Online (Sandbox Code Playgroud)

c++ json jsoncpp

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

Spring引导自定义约束验证器未注入服务

这是我的自定义验证器,用于检查某些字段的可用性.UserRepository为null,因此验证器不会注入它.

public class AvailableValidator implements ConstraintValidator<Available,String> {

    @Autowired
    private UserRepository userRepository;

    private Available.Field type;

    public void initialize(Available usernameAvailable) {
        this.type = usernameAvailable.type();
    }

    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if (userRepository == null) System.out.println("\n\n------USER REPOSITORY IS NULL-------\n\n");


        switch (type){
            case EMAIL:
                return userRepository.findByEmail(s)==null;
            case NUMBER:
                return userRepository.findByNumber(s)==null;
            case NAME:
                return userRepository.findByName(s)==null;
            default:
                return false;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经阅读了类似的线程,我必须设置验证工厂.我这样做了:

@SpringBootApplication
public class Application {

    public static void main(String[] args){
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public Validator validator(){
        return new LocalValidatorFactoryBean();
    } …
Run Code Online (Sandbox Code Playgroud)

validation spring dependency-injection spring-boot spring-java-config

9
推荐指数
1
解决办法
3598
查看次数

如何在Json中发送java.util.Date?

我需要在json中发送数据.重要的是我希望保留语言环境,以便接收者在当地时间获取日期.我怎样才能做到这一点?

我不能简单地使用,Date.toString()因为如果他们的语言环境不同(不同的日期和月份名称等等),我将无法在接收端解析它.

这个问题有方法解决吗?

java string json date http

8
推荐指数
3
解决办法
3万
查看次数

Visual Studio"启动xslt调试"选项不可见

我正在编辑一个xlst文件,我无法运行它.我怎么做?在"XML"下,我只能看到"Create Schemas"(无法点击)和"Schemas".应该有一个选项来启动xslt有或没有调试.

c# xml xslt visual-studio

8
推荐指数
2
解决办法
5994
查看次数

System.out.println在Intellij Idea中写入的位置?

我找不到消息应该显示的终端.怎么称呼?我猜它应该在View-> Tool Windows中,但似乎没有任何工作.这是一个Maven项目,我只能看到GlassFish日志.

java console intellij-idea output

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

Spring Validation 自定义消息 - 字段名称

问题:如何在 Spring 中获取验证消息中的字段名称

有没有一种方法可以访问 ValidationMessages.properties 文件中的字段名称,例如下面我尝试使用 {0} 但它不起作用,我在某处见过它。我希望 Spring 动态地将字段名称放在那里,这样我就不必为每个类重复它。

public class RegistrationForm {

    @NotEmpty(message = "{NotEmpty}")
    private String email;


    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}
Run Code Online (Sandbox Code Playgroud)

ValidationMessages.properties

NotEmpty={0} TEST
Run Code Online (Sandbox Code Playgroud)

validation spring hibernate spring-mvc

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

Java泛型基于返回类型转换?

以下代码来自名为ButterKnife的Android库.我正在弄清楚它是如何工作的.

@SuppressWarnings("unchecked") // That's the point.
  public <T> T castParam(Object value, String from, int fromPosition, String to, int toPosition) {
    try {
      return (T) value;
    } catch (ClassCastException e) {
      throw new IllegalStateException("Parameter #"
          + (fromPosition + 1)
          + " of method '"
          + from
          + "' was of the wrong type for parameter #"
          + (toPosition + 1)
          + " of method '"
          + to
          + "'. See cause for more info.", e);
    }
  }
Run Code Online (Sandbox Code Playgroud)

我试图重新创建此函数的行为:

  @SuppressWarnings("unchecked")
    public static …
Run Code Online (Sandbox Code Playgroud)

java generics casting wildcard

5
推荐指数
2
解决办法
1515
查看次数

C中的Tilde算子

 unsigned short int i = 0;
 printf("%u\n",~i);
Run Code Online (Sandbox Code Playgroud)

为什么此代码在控制台中返回32位数字?它应该是16位,因为short是2个字节.

输出为4,294,967,295,应为65,535.

c int unsigned short

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

C++服务器端没有阻塞listen()

下面的代码不会阻止listen(),它只是完成执行.你能告诉我为什么吗?(initWSA返回true,我检查了它).我正在关注一个教程,我被告知它应该阻止,因为它正在寻找客户端连接.

#include <iostream>
#include <WinSock2.h>

#pragma comment(lib, "ws2_32.lib")
using namespace std;

#define PORT 10000
bool initWSA(){
    WSADATA wsadata;
    int error = WSAStartup(0x0202, &wsadata);
    if (error) return false;
    if (wsadata.wVersion != 0x0202){
        WSACleanup();
        return false;
    }
    return true;
}
void closeConnection(SOCKET s)
{
    //Close the socket if it exists
    if (s)
        closesocket(s);

    WSACleanup(); //Clean up Winsock
}
int main(){
    initWSA();
    SOCKET s;
    SOCKADDR_IN addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(PORT);
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (s == …
Run Code Online (Sandbox Code Playgroud)

c++ sockets connection winsock server

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

如何配置persistence.xml provider标签

嘿,我正在学习这些东西,我并没有真正理解所有内容,而且我有一个问题,我不知道在persistence.xml 中的 provider 标记中写什么

这是我的 persistence.xml 和 pom.xml 文件:

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.test.jpa</groupId>
<artifactId>JPAProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.36</version>
    </dependency>
</dependencies>

<build>
    <finalName>JPAProject</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

持久化文件

<?xml version="1.0" encoding="UTF-8"?>

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="Database" transaction-type="RESOURCE_LOCAL">
    <class>models.Employee</class>
    <provider>WHAT TO WRITE HERE ?</provider>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/jpa"/>
        <property name="javax.persistence.jdbc.user" value="root"/>
        <property name="javax.persistence.jdbc.password" value="root"/>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    </properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

java xml persistence jpa maven

3
推荐指数
1
解决办法
9226
查看次数

Spring Data Jpa无法创建存储库bean

我正在使用Tomcat应用程序服务器进行战争。

聚甲醛

<?xml version="1.0" encoding="UTF-8"?>
<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>pl.kni</groupId>
    <artifactId>stuff</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <spring.version>4.2.0.RELEASE</spring.version>
        <hibernate.version>4.3.10.Final</hibernate.version>
        <mysql.connector.version>5.1.36</mysql.connector.version>
        <log4j.version>1.2.17</log4j.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.9.0.RELEASE</version>
        </dependency>


        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <finalName>kni</finalName>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

分派器servlet

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
            http://www.springframework.org/schema/context …
Run Code Online (Sandbox Code Playgroud)

spring jpa spring-mvc maven spring-data-jpa

3
推荐指数
1
解决办法
1382
查看次数

RxJava - 何时使用带有create方法的Observable

我正在阅读教程:

http://code.tutsplus.com/tutorials/getting-started-with-reactivex-on-android--cms-24387

特别是RxAndroid,但它和RxJava几乎相同.我不确定我完全理解这个概念.

下面我写了一个方法,然后是一个示例用法.

我的问题是:这是实现我的函数的正确方法,以便我可以异步地在其他线程上运行它们吗?实际上,它们只会返回一个运行真实代码的已创建的Observable,并处理错误和所有这些内容.

或者这是错的,那么我想知道正确的方法.

Observable<String> googleSomething(String text){
    return Observable.create(new Observable(){
        @Override
        public void call(Subscriber<? super String> subscriber) {
             try {
                String data = fetchData(text); // some normal method
                subscriber.onNext(data); // Emit the contents of the URL
                subscriber.onCompleted(); // Nothing more to emit
            } catch(Exception e) {
                subscriber.onError(e); // In case there are network errors
            }
        }
    });
}

googleSomething("hello world").subscribeOn(Schedulers.io()).observeOn(Schedulers.immediate()).subscribe(...)
Run Code Online (Sandbox Code Playgroud)

还使用Schedulers.immediate()来执行当前线程上的订户代码?它说"创建并返回一个在当前线程上立即执行工作的调度程序." 在javadoc,但我不确定.

java multithreading reactive-programming rx-java

3
推荐指数
1
解决办法
3925
查看次数

项目外的 Spring Boot 自定义静态资源位置

如何添加自定义资源位置,例如位于名为 Resources 的文件夹中的 D 驱动器上。

@Configuration
public class StaticResourceConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
        registry.addResourceHandler("/**").addResourceLocations("D:/Resources/");
    }
}
Run Code Online (Sandbox Code Playgroud)

这不起作用。

这是我的应用程序类和唯一的其他配置文件。

@SpringBootApplication 公共类应用程序 {

public static void main(String args[]){
    SpringApplication.run(Application.class, args);
}

@Bean // for websocket endpoints
public ServerEndpointExporter serverEndpointExporter() {
    return new ServerEndpointExporter();
}

@Bean
public PasswordEncoder bcryptPasswordEncoder(){
    return new BCryptPasswordEncoder();
}
Run Code Online (Sandbox Code Playgroud)

}

resources spring-mvc spring-boot

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