我是java的新手,我想在同一个类的另一个方法中使用私有方法的结果作为参数。
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string Upload(string img, string firstname, string lastname, string emailaddress)
{
string base64 = img.Replace("data:image/png;base64,", "");
string path = ConfigurationManager.AppSettings["UploadImagePath"];
string fileName = "Image_" + DateTime.UtcNow.Year + DateTime.UtcNow.Month + DateTime.UtcNow.Day + DateTime.UtcNow.Hour + DateTime.UtcNow.Minute + DateTime.UtcNow.Second + DateTime.UtcNow.Millisecond + "_" + Guid.NewGuid() + ".jpg";
int imageQuality;
if (!int.TryParse(ConfigurationManager.AppSettings["UploadImageQuality"], out imageQuality))
{
imageQuality = 50;
}
byte[] bytes = Convert.FromBase64String(img);
System.Drawing.Image image;
using (MemoryStream ms = new MemoryStream(bytes))
{
image = System.Drawing.Image.FromStream(ms);
}
try
{
EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, imageQuality);
ImageCodecInfo jpegCodec = null;
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
for (int i = 0; i < codecs.Length; i++)
{
if (codecs[i].MimeType == "image/jpeg")
{
jpegCodec = codecs[i];
}
}
if (jpegCodec != null)
{
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
image.Save(path + fileName, jpegCodec, encoderParams);
}
}
catch (Exception ex)
{
return "Message:" + ex.Message + " Source:" + ex.Source + " Inner Exception:" + ex.InnerException;
}
return fileName;
}
和我打算使用上述方法的结果的方法如下。
private String getMaxDate() {
String QryMaxDate = "SELECT Max(NAV_DATE) as maxdate FROM NAVS WHERE CONFIRMD IS NOT NULL AND SECURITY_CODE <> '002'";
try {
em = LocalEntityManagerFactory.createEntityManager();
return em.createNativeQuery(QryMaxDate).getSingleResult().toString();
} finally {
em.close();
}
}
请帮忙。
答案 0 :(得分:0)
只要每个方法都在同一个类中,public
方法就可以访问private
方法。你的第String maxDate = getMaxDate();
行应该没问题。
答案 1 :(得分:0)
您可以将getMaxDate()的结果分配给String,如下所示:
String result = getMaxDate();
然后在get_account_balance()中使用result,如下所示:
get_account_balance(result)
如果您在将结果作为参数传递时遇到问题,则只需更改方法的签名,如下所示:
get_account_balance(String MemberNo, String result)
您也可以在方法中调用getMaxDate(),如下所示:
.setParameter("max", getMaxDate())
我认为你正在寻找。