[英]How do I can pass userDetails as a parameter
How do I pass Userr instance as a parameter. 如何将Userr实例作为参数传递。 I have tried this but it's not working. 我已经尝试过了,但是没有用。
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;
}
But when I pass as a single property of Userr like this it works fine. 但是,当我像这样通过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;
}
How do I pass user object? 如何传递用户对象?
This is the method accepting user object and I am not getting any error. 这是接受用户对象的方法,我没有收到任何错误。
public class HomePageService { 公共类HomePageService {
public Double getCurrentProfitAndLoss(Userr user) {
System.out.println("iside HOmepageService");
Double currentProfitPercPA = StrategyExitReport.findCurrentProfitAndLossById(user);
System.out.println("iside currentProfitPercPA" + currentProfitPercPA);
return currentProfitPercPA;
}
}
I am assuming that you use jpa. 我假设您使用jpa。 So you defined the method findCurrentProfitAndLossById that is ends with ById but you actually use the object. 因此,您定义了以ById结尾的方法findCurrentProfitAndLossById,但实际上使用了该对象。 So change the name of the method to 因此,将方法名称更改为
findCurrentProfitAndLossByUser
have a look at this site http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation 看看这个网站http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.