How to open specific user profile based on what is

2019-08-22 10:51发布

At first this sounded very simple, but actually I couldn't find a way to implement this.

I have Spring web app, with rest controllers and database. I have users in my web app and I want to open specific page in which details of that user will be shown. So how do I send information about what is clicked on (link to that specific user's details) to another page where the details about user are being displayed?

This is what I tried and when I load profile page nothing appears on it: index.html

<html ng-app="app" ng-controller="appController">

<head >
<script src="js/angular.min.js"></script>
<script src="js/App.js"></script>
<p ng-click = "setProfileDetails(john)"><a href="profile.html">profile</a></p>

profile.html

Here I use the same App.js file so I can read the same controller.

<body ng-controller = "appController">
<div ng-model = "profileDetails">
{{profileDetails.username}}
</div>
</body>

App.js

$sopce.profileDetails = null;

$scope.setProfileDetails = function(username){
$http.get("services/rest/getUser/" + username).then(function(response){
$scope.profileDetails = response.data;
}, function(Response){
});
}

2条回答
霸刀☆藐视天下
2楼-- · 2019-08-22 11:00

You should expose an endpoint which returns user details provided some user identifier like userId. So, when someone clicks on a user, send the userId to the API and retrieve the response and display it. You just need to make a simple API call. Details about your front-end implementation are missing.

查看更多
Ridiculous、
3楼-- · 2019-08-22 11:12

on jsp page:

<form action="user-details/${userid}">
//list of users or whatever you want
</form>

on controller

@RequestMapping("user-details/{userid}")
public String showUserDetails(@PathVariable int userid, Model model) {
    model.addAttribute("userDetails",userDAO.getUserDetailsById(userid);
    return "/ac_user/user-details";
}
查看更多
登录 后发表回答