注意 调用的方法必须是1.public static String 方法名(参数1,参数2)
2. public static void 方法名(参数1,参数2)
例子1 .多个变量相乘获取相乘的数据
public class CalculatorForJmeter {
int a=0;
int b=0;
public static String getmultiply(int a,int b) {
return String.valueOf(a*b);
}
}
int num=2;
int price=1;
String TotalPrice=CalculatorForJmeter.getmultiply(num,price);
vars.put("smallTotalPrice",TotalPrice);
log.info(vars.get("smallTotalPrice"))
例子2.把获取的数据保存一个文件中
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class AppendFile {
//将content写入到指定文件fileName中
public static void appendFile(String fileName, String content) throws IOException {
FileWriter writer = null;
try {
writer = new FileWriter(fileName, true);
content = content+"\n";
writer.write(content);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (writer != null) {
writer.close();
}
}
}
}
String filepath="/Users/yudongya/orderNum.txt";
String data="${deliveryOrderCode}";
AppendFile.appendFile(filepath,data);
vars.put("data",data);
log.info("======="+data);
log.info("+++++++++"+vars.get("data"));