请回答这个问题,我开发了一个访问LinkedIn数据的Spring启动应用程序但是当我点击“连接到linkedIn ”按钮时,URL改为“ http://localhost:8080/connect/linkedin “to” http://localhost:8080/connect/linkedin#!“
LinkedInController.java
package com.linkedIn;
import javax.inject.Inject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.linkedin.api.LinkedIn;
import org.springframework.social.linkedin.api.LinkedInProfile;
import org.springframework.social.linkedin.api.impl.LinkedInTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/")
public class LinkedInController {
private LinkedIn linkedIn;
private ConnectionRepository connectionRepository;
@Inject
public LinkedInController(LinkedIn linkedIn, ConnectionRepository connectionRepository) {
this.linkedIn = linkedIn;
this.connectionRepository = connectionRepository;
}
@RequestMapping(method = RequestMethod.GET)
public String helloLinkedIn(Model model) {
if (connectionRepository.findPrimaryConnection(LinkedIn.class) == null) {
return "redirect:/connect/linkedin";
}
LinkedInProfile linkedInProfile = linkedIn.profileOperations().getUserProfile();
model.addAttribute("linkedInProfile", linkedInProfile);
return "hello";
}
}
\ src \ main \ resources \ templates \ connect \ linkedinConnect.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1"></meta>
<title>Hello LinkedIn</title>
</head>
<body>
<h3>Connect to LinkedIn</h3>
<form action="/connect/linkedin" method="POST">
<input type="hidden" name="scope" value="user_posts" />
<div class="formInfo">
<p>You aren't connected to LinkedIn yet. Click the button to
connect this application with your LinkedIn account.</p>
</div>
<button type="submit">Connect to LinkedIn</button>
</form>
</body>
</html>
答案 0 :(得分:0)
项目目录结构
<强>控制器强>
package com.linkedIn.controller;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.linkedin.api.LinkedIn;
import org.springframework.social.linkedin.api.ProfileOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/linkedin")
public class LinkedInController {
`private LinkedIn linkedIn;`
`private ConnectionRepository connectionRepository;`
public LinkedInController(LinkedIn linkedIn, ConnectionRepository connectionRepository) {
this.linkedIn = linkedIn;
this.connectionRepository = connectionRepository;
}
@GetMapping
public String helloLinkedIn(Model model) {
if (connectionRepository.findPrimaryConnection(LinkedIn.class) == null) {
return "redirect:/connect/linkedin";
}
// ProfileOperations user = linkedIn.profileOperations();
model.addAttribute("linkedInProfile", linkedIn.profileOperations().getUserProfileFull());
return "linkedin";
}
}
springboot-linkedin-apply Github Project
页面