栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring boot搭建web应用集成thymeleaf模板实现登陆

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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;


@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;




@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基类。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/142856.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号