2.1 主界面显示登陆人 2.1.1 后端代码 在 pinyougou-manager-web 新建 LoginController.java

package  com.pinyougou.manager.controller;
 
 
import  java.util.HashMap;
 
 
import  java.util.Map;
 
 
import  org.springframework.security.core.context.SecurityContextHolder; import  org.springframework.security.core.userdetails.UserDetails; import  org.springframework.web.bind.annotation.RequestMapping;
import  org.springframework.web.bind.annotation.RestController; @RestController
@RequestMapping("/login")
 
 
public  class  LoginController  { @RequestMapping("name") public  Map  name(){
String  name=SecurityContextHolder.getContext()
 
 
.getAuthentication().getName(); Map  map=new  HashMap();
map.put("loginName",  name);
 
 
 
 
}
 
}

2.1.1 前端代码 (1)新建 loginService.js

//登陆服务层app.service('loginService',function($http){
//读取登录人名称
 
this.loginName=function(){
 
 
return  $http.get('../login/name.do');
 
 
}
 
});

(2)新建 indexController.js

app.controller('indexController'  ,function($scope,$controller  ,loginService){
 
//读取当前登录人
 
$scope.showLoginName=function(){ loginService.loginName().success(
function(response){
 
 
$scope.loginName=response.loginName;
 
 
}
 
 
);
 
 
}
 
});
页面上引入 JS

<script  type="text/javascript"  src="../plugins/angularjs/angular.min.js"></script>

<script  type="text/javascript"  src="../js/base.js"></script>
<script  type="text/javascript"  src="../js/service/loginService.js"></script>
<script  type="text/javascript"  src="../js/controller/indexController.js"></script>

指令 将页面上的测试用户 替换成 {{loginName}} 2.1 退出登录 在 pinyougou-manager-web 的 spring-security.xml 的 http 节点中添加配置