如何在Java中编写自定义功能/方法? (RFT)
题
我需要在RFT(Java)中一遍又一遍地处理几行代码,因此自定义方法/函数/过程是最佳(也是唯一)解决方案。
我没有Java经验,所以我需要一些帮助。
该方法将接收一些参数,并且不会返回任何值。
基本上,它将将新记录输入到数据库(基于Web的应用程序)中。多少张记录?这取决于数据,因此我需要基于参数。
当前的代码看起来像
text__firstname(ANY,NO_FLAGS).setText(dpString("StudentName"));
text__surname(ANY,NO_FLAGS).setText(dpString("StudentSurnameName"));
在PHP中,所需功能看起来像
function add_student($first_name,$surname){
text__firstname(ANY,NO_FLAGS).setText($first_name);
text__surname(ANY,NO_FLAGS).setText($surname);
}
所以我可以称呼它
add_student(dpString("StudentName"),dpString("StudentSurnameName"));
解决方案 3
所以我在寻找这样的东西
private boolean add_student($first_name,$surname){
text__firstname(ANY,NO_FLAGS).setText($first_name);
text__surname(ANY,NO_FLAGS).setText($surname);
return true;
}
其他提示
我是一个.net的人,而不是一个Java人,但是应该像下面一样,我也从未使用过RFT,所以我假设内部文字可以正常工作。您必须将替换WithType替换为任何类型的text__firstname和text_surname。
public void AddStudent(ReplaceWithType text__firstname, ReplaceWithType text__surname)
{
text__firstname(ANY,NO_FLAGS).setText(dpString("StudentName"));
text__surname(ANY,NO_FLAGS).setText(dpString("StudentSurnameName"));
}
我建议您看看Java API并获得一本好的Java书。
您可以写这样的方法。
public void setTextValues(TestObject firstName , TestObject surName){
while(dp.dpnext()){
firstName(ANY,NO_FLAGS).setText(dpString("StudentName"));
surName(ANY,NO_FLAGS).setText(dpString("StudentSurnameName"));
}
}
dpnext命令自动迭代到数据库中的下一个记录。
希望这对您有帮助!
不隶属于 StackOverflow