2016-08-22 4 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 

는 모습을 가지고있는 메소드의 이름을 변경합니다. Integer 또는 Long (또는 getId()가 반환하는 모든 유형) 대신 Userr을 허용합니다. – Florian

+0

사용자 개체를 수락하는 메서드가 있습니다. 하지만 여전히 작동하지 않습니다.하지만 user.getID()를 전달하고 Long으로 받아 들일 때 작동합니다. 하지만 User 객체를 전달하고 public으로 받아 들일 때 Double getCurrentProfitAndLoss (Userr user)는 작동하지 않습니다. –

+0

아마도 HomePageService를 추가하여 문제의 원인을 찾을 수 있습니다. 삽입을 쉽게하기 위해 올바른 형식으로 삽입하십시오. – Florian

답변

관련 문제