我的代码崩溃(调试错误!R6010 abort()已被调用).你能帮助我吗?我也想知道如何从字符串值初始化json对象.
Json::Value obj;
obj["test"] = 5;
obj["testsd"] = 655;
string c = obj.asString();
Run Code Online (Sandbox Code Playgroud) 这是我的自定义验证器,用于检查某些字段的可用性.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
我需要在json中发送数据.重要的是我希望保留语言环境,以便接收者在当地时间获取日期.我怎样才能做到这一点?
我不能简单地使用,Date.toString()因为如果他们的语言环境不同(不同的日期和月份名称等等),我将无法在接收端解析它.
这个问题有方法解决吗?
我正在编辑一个xlst文件,我无法运行它.我怎么做?在"XML"下,我只能看到"Create Schemas"(无法点击)和"Schemas".应该有一个选项来启动xslt有或没有调试.
我找不到消息应该显示的终端.怎么称呼?我猜它应该在View-> Tool Windows中,但似乎没有任何工作.这是一个Maven项目,我只能看到GlassFish日志.
问题:如何在 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) 以下代码来自名为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) 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.
下面的代码不会阻止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) 嘿,我正在学习这些东西,我并没有真正理解所有内容,而且我有一个问题,我不知道在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)
我正在使用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) 我正在阅读教程:
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,但我不确定.
如何添加自定义资源位置,例如位于名为 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)
}
java ×5
spring ×3
spring-mvc ×3
c++ ×2
jpa ×2
json ×2
maven ×2
spring-boot ×2
validation ×2
xml ×2
c ×1
c# ×1
casting ×1
connection ×1
console ×1
date ×1
generics ×1
hibernate ×1
http ×1
int ×1
jsoncpp ×1
output ×1
persistence ×1
resources ×1
rx-java ×1
server ×1
short ×1
sockets ×1
string ×1
unsigned ×1
wildcard ×1
winsock ×1
xslt ×1