起初这听起来很简单,但实际上我找不到实现这个的方法。
我有Spring网络应用程序,有休息控制器和数据库。我的网络应用中有用户,我想打开特定页面,其中将显示该用户的详细信息。那么如何将有关点击内容的信息(链接到该特定用户的详细信息)发送到另一个显示用户详细信息的页面?
这是我尝试过的,当我加载个人资料页面时,它上面没有任何内容: 的index.html
from lxml import html
import requests
class page_crawler(object):
main_link = "https://www.yellowpages.com/search?search_terms=pizza&geo_location_terms=San%20Francisco%2C%20CA"
base_link = "https://www.yellowpages.com"
def __init__(self):
self.links = [self.main_link]
def crawler(self):
for link in self.links:
self.get_link(link)
def get_link(self, link):
print("Running page "+ link)
page = requests.get(link)
tree = html.fromstring(page.text)
item_links = tree.xpath('//h2[@class="n"]/a[@class="business-name"][not(@itemprop="name")]/@href')
for item_link in item_links:
return self.base_link + item_link
links = tree.xpath('//div[@class="pagination"]//li/a/@href')
for url in links:
if not self.base_link + url in self.links:
self.links += [self.base_link + url]
class Info_grabber(page_crawler):
def __init__(self, plinks):
page_crawler.__init__(self)
self.plinks = [plinks]
def passing_links(self):
for nlink in self.plinks:
print(nlink)
self.crawling_deep(nlink)
def crawling_deep(self, uurl):
page = requests.get(uurl)
tree = html.fromstring(page.text)
name = tree.findtext('.//div[@class="sales-info"]/h1')
phone = tree.findtext('.//p[@class="phone"]')
try:
email = tree.xpath('//div[@class="business-card-footer"]/a[@class="email-business"]/@href')[0]
except IndexError:
email=""
print(name, phone, email)
if __name__ == '__main__':
crawl = Info_grabber(page_crawler)
crawl.crawler()
crawl.passing_links()
profile.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>
文件,因此我可以读取相同的控制器。
App.js
App.js
<body ng-controller = "appController">
<div ng-model = "profileDetails">
{{profileDetails.username}}
</div>
</body>
答案 0 :(得分:1)
您应该公开一个返回用户详细信息的端点,并提供一些用户标识符,例如userId。因此,当有人点击用户时,将userId发送到API并检索响应并显示它。您只需要进行简单的API调用即可。缺少有关前端实施的详细信息。
答案 1 :(得分:1)
在jsp页面上:
<form action="user-details/${userid}">
//list of users or whatever you want
</form>
控制器上的
@RequestMapping("user-details/{userid}")
public String showUserDetails(@PathVariable int userid, Model model) {
model.addAttribute("userDetails",userDAO.getUserDetailsById(userid);
return "/ac_user/user-details";
}