使用 jOOQ 3.8.6,由于获取的记录中存在一些 UDT ,我不得不实现记录映射器以从 Record 转换为 Pojo。现在,我想知道从 Pojo 创建 Record 时如何做相反的事情。
public void update(MyTable pojo){
MyTableRecord record = dsl.newRecord(tables.MyTable.MY_TABLE, pojo);
record.store();
}
Run Code Online (Sandbox Code Playgroud)
我有一个
org.jooq.exception.MappingException: An error ocurred when mapping record from class tables.pojos.MyTable
Run Code Online (Sandbox Code Playgroud)
因为一个
Caused by: org.jooq.exception.DataTypeException: Cannot convert from MyType (class udt.pojos.MyType) to class udt.records.MyTypeRecord
Run Code Online (Sandbox Code Playgroud)
我想我必须注册一个从 POJO 到 Record 的自定义转换器。有谁知道怎么做?
我维护一个Web应用程序,其中包含一个带有JSF标记的页面<f:event.我在服务类中重写了一个方法,以便抛出一个业务异常.但是,当抛出业务异常时,它不会被托管bean捕获,并且页面上会显示异常.似乎我的代码try/catch不起作用.
在XHTML中:
<f:event listener="#{resourceBean.init(enrollment)}" type="preRenderView" />
Run Code Online (Sandbox Code Playgroud)
Managed Bean中的监听器方法:
private boolean canCreateResource;
public void init(Enrollment enrollment) {
(...)
try {
canCreateResource = resourceService.canCreateResource(enrollment);
} catch (BusinessException e) {
canCreateResource = false;
}
}
Run Code Online (Sandbox Code Playgroud)
服务类中的方法:
public boolean canCreateResource(Enrollment enrollment) {
if (...) {
if (mandateService.isCoordinator(user, course)) {
return true;
} else {
throw new BusinessException("Undefined business rule.");
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
从我在其他网站上看到的内容,我想我必须实现一些JSF的处理程序类.但是哪个以及如何?
EDITED
OBS 1:BusinessException该类扩展了RuntimeException类.
OBS 2:canCreateResource创建属性以控制按钮的渲染.
我正在尝试使用h:inputFile标记上传图像文件并将其写入磁盘.
我的JSF代码:
<h:form id="fileUploadForm" enctype='multipart/form-data' prependId="false">
<h:inputFile value="#{solicitacaoManagedBean.imagemCarregada}" />
<br />
<h:commandButton styleClass="btn btn-primary " value="Enviar" action="#{solicitacaoManagedBean.enviarImagem}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
我的ManagedBean:
@Named(value = "solicitacaoManagedBean")
@SessionScoped
@MultipartConfig(location = "/home/rogerio/tmp/")
public class SolicitacaoManagedBean implements Serializable {
private Part imagemCarregada;
Run Code Online (Sandbox Code Playgroud)
(......)
public void enviarImagem() throws IOException {
try {
imagemCarregada.write("teste.jpg");
} catch (IOException ioe) {
System.out.println("Erro ao escrever: " + ioe.getLocalizedMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
据推测,方法write将项目上传到磁盘,IOException也不会被抛出/捕获.