0

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

如何传递用户对象?

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

公共类 HomePageService {

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

1 回答 1

0

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

findCurrentProfitAndLossByUser

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

于 2016-08-22T12:18:34.233 回答