如何将userDetails作为参数传递

时间:2016-08-22 10:35:23

标签: java spring hibernate roo

如何将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);
    } 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;
}

如何传递用户对象?

这是接受用户对象的方法,我没有收到任何错误。

public class HomePageService {

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

1 个答案:

答案 0 :(得分:0)

我假设你使用jpa。因此,您定义了以ById结尾但实际使用该对象的方法findCurrentProfitAndLossById。 因此,将方法的名称更改为

findCurrentProfitAndLossByUser

查看此网站http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation

相关问题