【发布时间】:2016-07-20 10:09:55
【问题描述】:
请回答这个问题,我开发了一个访问 LinkedIn 数据的 Spring Boot 应用程序,但是当我单击“connect to linkedIn”按钮时,URL 会从“http://localhost:8080/connect/linkedin”更改到“http://localhost:8080/connect/linkedin#!”
LinkedInController.java
包 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>
【问题讨论】:
标签: java spring spring-boot linkedin