gpt4 book ai didi

java - 如何在 LS2J 的另一个类的参数中传递一个对象?

转载 作者:行者123 更新时间:2023-11-30 08:22:23 25 4
gpt4 key购买 nike

我正在尝试使用 LS2J 将一个 java 类(一个 bean)的对象传递给另一个类。

问题是返回了一个错误:

LS2J Error: Threw java.lang.ClassNotFoundException: com.pasquier.DTO.WS.LogWSDTO

我不知道为什么?

我有一个通常带有 getter 和 setter 的类 bean。我想在另一个中传递此类的实例。

我在 Lotus LS2J 中的类(class):

Class LogWebService
sessionJava As JAVASESSION
classJava As JAVACLASS
objectJava As JAVAOBJECT
methodJava As JAVAMETHOD

Public Sub New()
Set sessionJava = New JAVASESSION
Set classJava = sessionJava.GetClass("com.pasquier.launcher/LogWebService")
Set objectJava = classJava.CreateObject
End Sub

Public Sub setLog(logDTO As LogWSDTO)
Set methodJava = classJava.GetMethod("setLog","(Lcom/pasquier/DTO/WS/LogWSDTO;)V")
objectJava.setLog(logDTO)
End Sub

End Class

崩溃的是setLog方法

我在代码中调用它:

Class LogGetAllDocumentsDAO

Private ilog As LogWebService
Private logDTO As LogWSDTO
Private docDTO As LogGetAllDocumentsDTO

Public Sub New(logWSparam As LogWSDTO, docDTOparam As LogGetAllDocumentsDTO)
Set Me.logDTO = logWSparam
Set Me.docDTO = docDTOparam
End Sub


Public Sub appelLog()
Set ilog = New LogWebService()

' error: LS2J Error: Threw java.lang.ClassNotFoundException: com.pasquier.DTO.WS.LogWSDTO
Call ilog.setLog(logDTO)


End Sub

一个想法?

我在与 LogWebService 相同的库中有一个类 LogDTO。

Class LogWSDTO
sessionJava As JAVASESSION
classJava As JAVACLASS
objectJava As JAVAOBJECT
methodJava As JAVAMETHOD


Public Sub New()
Set sessionJava = New JAVASESSION
Set classJava = sessionJava.GetClass("com.pasquier.DTO.WS/LogWSDTO")
Set objectJava = classJava.CreateObject
End Sub

如果我明白我不能通过 logDTO :

Set Me.logDTO = logWSparam

是吗?但是我该怎么做呢??


好吧,我试过了,但没用。

我在 LS2J 中添加了一个 getObjet 方法(不在 java 中,仅在 lotus 中)

Class LogWSDTO
sessionJava As JAVASESSION
classJava As JAVACLASS
objectJava As JAVAOBJECT
methodJava As JAVAMETHOD


Public Sub New()
Set sessionJava = New JAVASESSION
Set classJava = sessionJava.GetClass("com.pasquier.DTO.WS/LogWSDTO")
Set objectJava = classJava.CreateObject
End Sub


Public Function getJavaObject()
Set getJavaObject = objectJava
End Function

我尝试在我的程序中调用它:

Class LogGetAllDocumentsDAO

Private ilog As LogWebService
Private logDTO As LogWSDTO
Private docDTO As LogGetAllDocumentsDTO

Public Sub New(logWSparam As LogWSDTO, docDTOparam As LogGetAllDocumentsDTO)
Set Me.logDTO = logWSparam
Set Me.docDTO = docDTOparam
End Sub


Public Sub appelLog()
Call ajouterParam()
Set ilog = New LogWebService()

Call ilog.setLog(logDTO.getJavaObject())
End Sub

我无法保存此更改:它返回:

"type mismatch on : GETJAVAOBJECT"


所以我尝试在 LogWebService 的 java 类中添加该方法。我在 LS2J 中尝试:

Public Function getJavaObject()         
Set methodJava = classJava.GetMethod("getJavaObject","()Lcom/pasquier/DTO/WS/LogWSDTO;")
getJavaObject = objectJava.getJavaObject()
End Function

我调用:

Public Sub appelLog()           
Set ilog = New LogWebService()
Set logDTO = logDTO.getJavaObject
Call ilog.setLog(logDTO)

它不起作用,同样的信息,我哭了!!!

最佳答案

objectJava.setLog(logDTO) - logDTO 必须是 LS2J 生成的 Java 对象。它不适用于 LotusScript 类对象。

将方法 getJavaObject() 添加到您的 LotusScript 类 LogWSDTO,它返回 LS2J Java 对象 objectJava。然后以这种方式使用它:

objectJava.setLog(logDTO.getJavaObject())

这是一个工作示例:

LotusScript 代理:

Option Declare
UseLSX "*javacon"
Use "AandB"

Class LogWSDTO
sessionJava As JAVASESSION
classJava As JAVACLASS
objectJava As JAVAOBJECT

Public Sub New()
Set sessionJava = New JAVASESSION
Set classJava = sessionJava.GetClass("de.leonso.test/B")
Set objectJava = classJava.CreateObject
End Sub

Public Function getJavaObject()
Set getJavaObject = objectJava
End Function
End Class

Sub Initialize
Dim sessionJava As JAVASESSION
Dim classJavaA As JAVACLASS
Dim objectJavaA As JAVAOBJECT
Dim lsB As LogWSDTO

Set sessionJava = New JAVASESSION
Set classJavaA = sessionJava.GetClass("de.leonso.test/A")
Set objectJavaA = classJavaA.CreateObject
Set lsB = New LogWSDTO()

print objectJavaA.a(lsB.getJavaObject())

End Sub

Java ScriptLibrary“AandB”中的 Java 类:

package de.leonso.test;

public class A {
public String a(B b) {
return b.b();
}
}

package de.leonso.test;

public class B {
public String b() {
return ("hallo");
}
}

关于java - 如何在 LS2J 的另一个类的参数中传递一个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24432443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com