我正在使用描述Jackson数据类型JSR310页面的库,但我仍然难以让它工作.
我配置了以下bean:
@Bean
@Primary
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JSR310Module());
return mapper;
}
Run Code Online (Sandbox Code Playgroud)
当我调用我的REST API时,日期格式输出是yyyy-MM-dd'T'HH:ss.SSSSSS,例如2015-04-11T00:10:38.905847.这可以通过我的AngularJS代码处理得很好.
当我想向REST API提交内容时,日期会发布为yyyy-MM-dd'T'HH:mm:ss.SSS'Z',例如2015-04-09T08:30:00.000Z
杰克逊最后一直在抱怨'Z'.如果我查看LocalDateTimeDeserializer它在文档中使用的DateTimeFormatter.ISO_LOCAL_DATE_TIMEboils ISO_LOCAL_DATE'T'ISO_LOCAL_TIME,它提到它没有覆盖区域.
所以我想我应该设置DateFormat在ObjectMapper我创建:
@Bean
@Primary
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JSR310Module());
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"));
return mapper;
}
Run Code Online (Sandbox Code Playgroud)
但这没有任何作用.我将其更改为简单的类似yyyy-MM-dd但序列化日期保留为以前的格式,反序列化也不受影响.
我在这做错了什么才能让它发挥作用?据我所知,我的JavaScript代码中的日期格式是ISO 8601格式...
我有以下XHTML:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<head>
<title>TODO supply a title</title>
</head>
<body>
<f:metadata>
<f:viewParam id="productCV" name="productName" value="#{productBean.product}"
converter="#{productConverter}" required="true"/>
</f:metadata>
<ui:composition template="/templates/mastertemplate.xhtml">
<!-- Define the page title for this page-->
<ui:define name="pageTitle">
<h:outputFormat value="#{msgs.productPageTitle}">
<f:param value="#{productBean.product.description}"/>
</h:outputFormat>
</ui:define>
<!-- Pass the categoryName parameter to the sidebar so the category of this product is highlighted-->
<ui:param name="categoryName" value="#{productBean.product.categoryName}"/>
<ui:define name="content">
<!-- If productconversion failed, show this error-->
<h:message id="error" for="productCV" style="color: #0081c2;" rendered="#{productBean.product == null}" />
<!-- If productconversion succeeded …Run Code Online (Sandbox Code Playgroud) 我在通用基类中有以下方法:
public virtual void Insert(TEntity entity) {
dbSet.Add(entity);
}
Run Code Online (Sandbox Code Playgroud)
我的服务层使用该Insert方法添加新记录。现在我希望能够返回一个布尔值,以确保它正确插入。类似于以下内容:
public virtual int Count {
get {
return dbSet.Count();
}
}
public virtual bool Insert(TEntity entity) {
int count = this.Count;
dbSet.Add(entity);
return this.Count == count + 1;
}
Run Code Online (Sandbox Code Playgroud)
有没有更优雅的方法呢?我是否完全错误地接近它?我可以为 Delete 方法做类似的事情,但是我将如何检查 anUpdate是否已成功执行?
我在包中有一些过程/函数,-2291当违反FOREIGN KEY约束时捕获异常.
我从不同的过程中删除了异常,并在包体中声明它,如下所示:
e_ouder_niet_gevonden EXCEPTION;
PRAGMA EXCEPTION_INIT(e_ouder_niet_gevonden,-2291);
Run Code Online (Sandbox Code Playgroud)
现在当我使用包中的一个过程时没有问题.但是,我想要实现的是任何过程/函数都可以使用该异常.我该怎么做呢?