2016-08-22 88 views
0

如何傳遞Userr實例作爲參數。我已經嘗試過,但它不起作用。如何將userDetails作爲參數傳遞

public Double getCurrentProfitAndLoss() { 
    Double currentProfitAndLoss = null; 
    Userr user = ((OptionsUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserr(); 
    user = Userr.findUserr(user.getId()); 
    HomePageService homePageService = homePageServiceFactory.getObject(); 

    System.out.println("homePageService object created"); 
    try { 
     currentProfitAndLoss = homePageService.getCurrentProfitAndLoss(user); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 
    return currentProfitAndLoss; 
} 

但是,當我作爲一個單一的屬性Userr這樣傳遞,它工作正常。

public Double getCurrentProfitAndLoss() { 
    Double currentProfitAndLoss = null; 
    Userr user = ((OptionsUser)  SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserr(); 
    user = Userr.findUserr(user.getId()); 
    HomePageService homePageService = homePageServiceFactory.getObject(); 

    System.out.println("homePageService object created"); 
    try { 
     currentProfitAndLoss = homePageService.getCurrentProfitAndLoss(user.getId()); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 
    return currentProfitAndLoss; 
} 

如何傳遞用戶對象?

這是接受用戶對象的方法,我沒有收到任何錯誤。

公共類HomePageService {

public Double getCurrentProfitAndLoss(Userr user) { 
System.out.println("iside HOmepageService"); 
Double currentProfitPercPA =  StrategyExitReport.findCurrentProfitAndLossById(user); 
System.out.println("iside currentProfitPercPA" + currentProfitPercPA); 
return currentProfitPercPA; 
} 
} 
+0

最有可能的,你必須改變在HomePageService各方法的簽名改變方法的名稱

findCurrentProfitAndLossByUser 

看看。讓它接受Userr而不是Integer或Long(或任何類型的getId()返回)。 – Florian

+0

我有一個方法接受用戶對象。但仍然沒有工作但是當我通過user.getID()並接受爲長期它的工作。但是,當我通過用戶對象,並接受爲公共雙重getCurrentProfitAndLoss(用戶用戶)stils它不起作用 –

+0

也許你可以添加HomePageService,以便有可能找到你的問題的原因。請插入正確的格式以方便閱讀。 – Florian

回答