SpringSecurity实现后台管理员登录(二)

需求:login.ftl页面中登录成功后进入index.ftl页面中

一、pom.xml中添加json转换相关的包

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dependency>  
  2.     <groupId>com.fasterxml.jackson.core</groupId>  
  3.     <artifactId>jackson-core</artifactId>  
  4.     <version>2.4.4</version>  
  5. </dependency>  
  6. <dependency>  
  7.     <groupId>com.fasterxml.jackson.core</groupId>  
  8.     <artifactId>jackson-databind</artifactId>  
  9.     <version>2.4.4</version>  
  10. </dependency>  
  11. <dependency>  
  12.     <groupId>com.fasterxml.jackson.core</groupId>  
  13.     <artifactId>jackson-annotations</artifactId>  
  14.     <version>2.4.4</version>  
  15. </dependency>  

二、applicationContext-mvc.xml中添加json转换相关的配置

 

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <!--token 拦截校验 -->  
  2. <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />  
  3. <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">  
  4.     <property name="favorPathExtension" value="false" />  
  5.     <property name="favorParameter" value="true" />  
  6.     <property name="ignoreAcceptHeader" value="false" />  
  7.     <property name="mediaTypes">  
  8.         <value>  
  9.             atom=application/atom+xml  
  10.             html=text/html  
  11.             json=application/json  
  12.             *=*/*  
  13.         </value>  
  14.     </property>  
  15. </bean>  

三、applicationContext-security.xml中

将<intercept-url pattern="/service/index/index"access="ROLE_AUTHORITY"/>

改为<intercept-url pattern="/service/index/index" />

这里只是要实现简单的登录功能,所以没有设计权限。加了access=” "ROLE_AUTHORITY”会导致无法登录。

四、实现效果

原文地址:https://www.cnblogs.com/grimm/p/6732866.html