我想从带有JDBC的Oracle DB表中获取DATETIME列.这是我的代码:
int columnType = rsmd.getColumnType(i);
if(columnType == Types.DATE)
{
Date aDate = rs.getDate(i);
valueToInsert = aDate.toString();
}
else if(columnType == Types.TIMESTAMP)
{
Timestamp aTimeStamp = rs.getTimestamp(i);
valueToInsert = aTimeStamp.toString();
}
else
{
valueToInsert = rs.getString(i);
}
Run Code Online (Sandbox Code Playgroud)
我必须首先确定列类型.我感兴趣的字段被识别为Types.DATE,但它实际上是数据库中的DATETIME,因为它具有以下格式:"07.05.2009 13:49:32"
getDate截断时间:"07.05.2009"并且getString将".0"附加到它:"07.05.2009 13:49:32.0"
当然我可以删除最终的.0并一直使用getString,但这是一个肮脏的解决方法.
有任何想法吗 ?我一直在寻找一个getDateTime方法.
干杯,蒂姆
我想拦截401和其他错误,以便做出相应的反应.这是我的拦截器:
import { LoggingService } from './../logging/logging.service';
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpHandler, HttpRequest, HttpEvent, HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/do';
@Injectable()
export class TwsHttpInterceptor implements HttpInterceptor {
constructor(private logger: LoggingService) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.logger.logDebug(request);
return next.handle(request)
.do(event => {
if (event instanceof HttpResponse) {
this.logger.logDebug(event);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
虽然这适用于200个请求,但它不会拦截错误响应
我在chrome的开发控制台中看到的只有:
zone.js:2616 GET http:// localhost:8080/backend/rest/wrongurl 404(Not Found)
或这个
zone.js:2616 GET …
我收到以下异常:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Run Code Online (Sandbox Code Playgroud)
我做了一些研究并改变了我的连接代码:
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
CloseableHttpClient client = HttpClients.custom()
.setRedirectStrategy(new LaxRedirectStrategy())
.setSslcontext(sslContext)
.setConnectionManager(connMgr)
.build();
Run Code Online (Sandbox Code Playgroud)
这解决了到目前为止的问题,我不再获得异常并且连接正常.
当我在Tomcat中运行的Servlet中使用相同的代码时,问题再次出现.
为什么?
在我的 Vue 应用程序中,我有这个文件输入:
<input type="file" multiple @input="handleFileInput" />
Run Code Online (Sandbox Code Playgroud)
所选文件将传递给我的此上传方法:
public async uploadFiles(file: File) {
[...]
const formData = new FormData();
formData.append('fileName', file.name);
formData.append('file', file);
[...]
await axios.post('my-upload-url', formData);
}
Run Code Online (Sandbox Code Playgroud)
发送前的js日志:
发送后的网络日志:
我的 Resteasy 控制器回答:
@POST
@Transactional
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadMultipartData(@MultipartForm @Valid MyDto dto) {
// dto.file -> my file
}
Run Code Online (Sandbox Code Playgroud)
DTO:
public class MyDto {
@NotNull
@FormParam("file")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
public InputStream file;
}
Run Code Online (Sandbox Code Playgroud)
传输其他文件类型(pdf、png、jpg、mp3...)时,文件按预期位于 DTO 的 InputStream 中。但是,当文件是 .eml 文件时,InputStream 为 null。
更新:将文件从 text.eml 重命名为 test.txt …
我有一个JAVA类,它启动具有唯一ID的各种线程.每个线程都应该登录到以ID.log命名的唯一日志文件.
因为我只在运行时获取唯一ID,所以我必须以编程方式配置Log4J:
// Get the jobID
myJobID = aJobID;
// Initialize the logger
myLogger = Logger.getLogger(myJobID);
FileAppender myFileAppender;
try
{
myFileAppender = new FileAppender(new SimpleLayout(), myJobID + ".log", false);
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure(myFileAppender);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我按顺序启动作业,这可以正常工作 - 但是当我同时启动2个线程(同一类)时,会创建两个日志,但日志会混淆:第二个线程会记录到第一个和第二个日志中.
我怎样才能确保每个实例都是唯一的?我已经尝试为每个记录器实例提供一个唯一的名称,但它没有改变任何东西.
这是我发送HTTP请求的方式:
return this.http.get(url, { observe: 'response' })
Run Code Online (Sandbox Code Playgroud)
我想在我的HttpInterceptor中读取HttpResponse的HTTP标头:
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request)
.do(event => {
if (event instanceof HttpResponse) {
this.logger.logDebug(event); // Headers are missing here
}
})
.catch((err: HttpErrorResponse) => {
// Do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
拦截器在我的app.module.ts中是这样提供的:
{提供:HTTP_INTERCEPTORS,useClass:MyHttpInterceptor,多:true}
该事件似乎没有标题,即使在Chrome开发者控制台中,我也看不到任何标题:
但是,使用Postman时,我可以在响应中看到标题(如预期的那样)
Connection ?keep-alive
Content-Length ?14766
Content-Type ?application/json
Date ?Fri, 04 Aug 2017 14:50:46 GMT
Server ?WildFly/10
X-Powered-By ?Undertow/1
Run Code Online (Sandbox Code Playgroud)
如何在Angular中显示这些标题?
HTTP 的官方文档说要获得如下标头:
http
.get<MyJsonData>('/data.json', {observe: 'response'}) …Run Code Online (Sandbox Code Playgroud) 我想在我的MariaDB中获得毫秒级的精度。经过研究,我发现需要更改columnDefinition-因此我在实体中执行了以下操作:
@NotNull
@Column(name = "createdDate", columnDefinition = "DATETIME(3) NOT NULL")
@Temporal(TemporalType.TIMESTAMP)
private TimeStamp createdDate;
@PrePersist
void onPersist() {
createdDate = new Timestamp(new Date().getTime());
}
Run Code Online (Sandbox Code Playgroud)
创建列的结果SQL为:
`createdDate` DATETIME(3) NOT NULL
Run Code Online (Sandbox Code Playgroud)
现在,在数据库中,该值确实具有3个小数:
2016-09-12 16:57:44.000
Run Code Online (Sandbox Code Playgroud)
...但它们总是000
我做错了什么,或者我忘记了什么?
编辑:我试过没有JAVA:
CREATE TABLE `test` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`createdDate` DATETIME(3) NOT NULL,
PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
;
Run Code Online (Sandbox Code Playgroud)
然后:
INSERT INTO test (createdDate)
VALUES(current_timestamp())
Run Code Online (Sandbox Code Playgroud)
结果:
2016-09-13 13:57:44.000
Run Code Online (Sandbox Code Playgroud) 在Angular中调用我的REST服务时,没有响应头.
Angular中的登录方法
login(username: string, password: string) {
const credentials = { "username": username, "password": password };
return this.http.post(this.url, credentials)
.subscribe(
data => console.log(data), // JSON.stringify(data.headers) also is empty
error => console.log(error)
);
}
Run Code Online (Sandbox Code Playgroud)
Chrome开发工具控制台中的输出
响应{_body:"",状态:200,ok:true,statusText:"OK",标题:标题...}标题:Headers_headers:Map(0)_normalizedNames:Map(0)proto:Objectok:truestatus:200statusText:"OK "type:2url:" http:// localhost:8080/backend/rest/login "_body:"" proto:Body
但是当我向邮递员发送相同的帖子请求时,我得到了预期的结果:
Access-Control-Allow-Credentials ?true
Access-Control-Allow-Origin ?chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
Authorization ?Bearer eyJ[...]
Connection ?keep-alive
Content-Length ?0
Date ?Mon, 12 Jun 2017 13:19:54 GMT
Server ?WildFly/10
Vary ?Origin
X-Powered-By ?Undertow/1
Run Code Online (Sandbox Code Playgroud)
REST服务
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response authenticateUser(CredentialsDTO credentialsDTO) {
try {
authService.login(credentialsDTO.getUsername(), credentialsDTO.getPassword()); …Run Code Online (Sandbox Code Playgroud) A picture is worth a 1024 words:
How do I force those arrows to show all the time ? By default, they only appear on hover.
<input matInput type="number" placeholder="Value" [(ngModel)]="myValue">
Run Code Online (Sandbox Code Playgroud)
I could not find anything, and I am not even sure how these buttons are called.
我想使用拦截器将元数据添加到请求中。但是,我无法使用在几个示例中找到的代码:
https://binod.hashnode.dev/axios-interceptor
instance.interceptors.request.use(
function (config) {
config.metadata = { startTime: new Date() };
return config;
},
function (error) {
return Promise.reject(error);
}
);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
类型“InternalAxiosRequestConfig”上不存在属性“元数据”
我正在使用 Axios 1.4.0 和 Typescript 5.0.4。我究竟做错了什么?
angular ×3
java ×3
axios ×2
getdate ×1
http-headers ×1
interceptor ×1
javascript ×1
jpa ×1
log4j ×1
mariadb ×1
mime-types ×1
oracle ×1
quarkus ×1
rest ×1
resteasy ×1
resultset ×1
sql ×1
ssl ×1
tomcat ×1
typescript ×1