网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Springboot如何搭建web应用集成thymeleaf模板实现登陆

这篇文章将为大家详细讲解有关Spring boot如何搭建web应用集成thymeleaf模板实现登陆,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

为济南等地区用户提供了全套网页设计制作服务,及济南网站建设行业解决方案。主营业务为成都网站设计、成都网站建设、济南网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

Spring boot 搭建web应用集成了thymeleaf模板实现登陆
下面是pom.xml的配置



   4.0.0
   exam
   examSystem
   jar
   1.0-SNAPSHOT
  
  
    org.springframework.boot
    spring-boot-starter-parent
    1.2.7.RELEASE
  
  
  
    UTF-8
    com.study.App
    1.7
    1.3.0
  

  
  
    
      
        org.springframework.boot
        spring-boot-maven-plugin
        
        
      
    
  


  
    
      org.springframework.boot
      spring-boot-starter-web
    

    
    
      org.springframework.boot
      spring-boot-starter-data-jpa
    
    
    
      org.springframework.boot
      spring-boot-starter-thymeleaf
    
    
    
      mysql
      mysql-connector-java
    

    
    
      javax.ws.rs
      javax.ws.rs-api
      2.0.1
    

    
      net.bull.javamelody
      javamelody-core
      1.53.0
    
    
    
      com.alibaba
      druid
      1.0.25
    

    
    
      org.apache.shiro
      shiro-core
      ${shiro.version}
    
    
      org.apache.shiro
      shiro-spring
      ${shiro.version}
    
    
      org.apache.shiro
      shiro-web
      ${shiro.version}
    
    
      org.apache.shiro
      shiro-ehcache
      ${shiro.version}
    
    
    
      com.github.theborakompanioni
      thymeleaf-extras-shiro
      1.2.1
    
  

主入口main方法

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Created by on 2016/12/8.
 */
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class App extends SpringBootServletInitializer {


  public static void main(String[] args) {
    SpringApplication.run(App.class, args);
  }

}

登陆页提交表单代码,

 
    
    
    登录
    
       记住我
    
  

Controller 代码

package com.study.system.contrller;

import com.study.model.contrller.BaseContrller;
import com.study.model.po.User;
import com.study.system.services.UserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 *
 * 用户管理
 * Created by on 2016/12/12.
 */

@Controller
@RequestMapping(value = "/user")
public class UserContrller extends BaseContrller {

  @RequestMapping(value="/login",method= RequestMethod.POST)
  public String login(User user){
    try{
      if(userServices.hasUser(user)){
        return "redirect:/user/index";
      }else{
        return "redirect:/";
      }
    }catch (Exception e){
      logger.error("登陆失败:"+e,e);
    }
    return "redirect:/";
  }

  @RequestMapping(value="/index",method= RequestMethod.GET)
  public String index(){
    try{

    }catch (Exception e){
      logger.error("登陆失败:"+e,e);
    }
    return "page/index/index";
  }


  @Autowired
  private UserServices userServices;

}

其中 UserServices 为业务接口。BaseContrller为自己封装的Controller基类。

关于“Spring boot如何搭建web应用集成thymeleaf模板实现登陆”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


标题名称:Springboot如何搭建web应用集成thymeleaf模板实现登陆
文章转载:http://bjjierui.cn/article/jcsjeo.html

其他资讯