最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring boot搭建web應用集成thymeleaf模板實現登陸

 更新時間:2017年12月01日 09:12:16   作者:夢想漲價了  
這篇文章主要介紹了Spring boot搭建web應用集成thymeleaf模板實現登陸,頁面使用bootstrap,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Spring boot 搭建web應用集成了thymeleaf模板實現登陸
下面是pom.xml的配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>exam</groupId>
   <artifactId>examSystem</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>
  <!--spring boot 的基本配置 -->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.7.RELEASE</version>
  </parent>
  <!--基本配置,設置編碼,入口,jdk版本 -->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>com.study.App</start-class>
    <java.version>1.7</java.version>
    <shiro.version>1.3.0</shiro.version>
  </properties>

  <!-- 設置編譯 -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <dependencies>
        </dependencies>
      </plugin>
    </plugins>
  </build>


  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!--jpa的jar包 ,操作數據庫的,類似hibernate-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <!--thymeleaf模板jar-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!--mysql驅動-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <!-- 添加restfull的支持 -->
    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>javax.ws.rs-api</artifactId>
      <version>2.0.1</version>
    </dependency>

    <dependency>
      <groupId>net.bull.javamelody</groupId>
      <artifactId>javamelody-core</artifactId>
      <version>1.53.0</version>
    </dependency>
    <!-- 添加 druid 數據源連接池-->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.0.25</version>
    </dependency>

    <!-- 添加權限認證-->
    <dependency>
      <groupId>org.apache.shiro</groupId>
      <artifactId>shiro-core</artifactId>
      <version>${shiro.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.shiro</groupId>
      <artifactId>shiro-spring</artifactId>
      <version>${shiro.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.shiro</groupId>
      <artifactId>shiro-web</artifactId>
      <version>${shiro.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.shiro</groupId>
      <artifactId>shiro-ehcache</artifactId>
      <version>${shiro.version}</version>
    </dependency>
    <!--thymeleaf 和 shiro 的整合 -->
    <dependency>
      <groupId>com.github.theborakompanioni</groupId>
      <artifactId>thymeleaf-extras-shiro</artifactId>
      <version>1.2.1</version>
    </dependency>
  </dependencies>
</project>

主入口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);
  }

}

登陸頁提交表單代碼,

 <form class="form-signin" role="form" th:action="@{/user/login}" th:method="post">
    <input type="text" class="form-control" placeholder="用戶名" required="required" name="userName" />
    <input type="password" class="form-control" placeholder="密碼" required="required" name="passwprd" />
    <button class="btn btn-lg btn-warning btn-block" type="submit">登錄</button>
    <label class="checkbox">
      <input type="checkbox" value="remember-me" /> 記住我
    </label>
  </form>

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 為業(yè)務接口。BaseContrller為自己封裝的Controller基類。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • MyBatis-Plus 通用IService使用詳解

    MyBatis-Plus 通用IService使用詳解

    這篇文章主要介紹了MyBatis-Plus 通用IService使用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • 詳解SpringBoot如何正確解析日期格式

    詳解SpringBoot如何正確解析日期格式

    這篇文章主要介紹了SpringBoot如何正確解析日期格式,文中給出了兩種解決方案,通過代碼示例講解的非常詳細,對大家的學習或工作有一定的幫助,需要的朋友可以參考下
    2024-03-03
  • Java枚舉之EnumSet詳解

    Java枚舉之EnumSet詳解

    這篇文章主要介紹了Java枚舉之EnumSet詳解,使用時進行與或運算,但是定義多了之后,會很亂、臃腫,編寫容易出錯,EnumSet可以實現類似的功能,且使用起來很簡潔,需要的朋友可以參考下
    2023-12-12
  • Spring MVC 4.1.3 + MyBatis零基礎搭建Web開發(fā)框架(注解模式)

    Spring MVC 4.1.3 + MyBatis零基礎搭建Web開發(fā)框架(注解模式)

    本篇文章主要介紹了Spring MVC 4.1.3 + MyBatis零基礎搭建Web開發(fā)框架(注解模式),具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • Maven 多profile及指定編譯問題的解決

    Maven 多profile及指定編譯問題的解決

    這篇文章主要介紹了Maven 多profile及指定編譯問題的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • 哈希表在算法題目中的實際應用詳解(Java)

    哈希表在算法題目中的實際應用詳解(Java)

    散列表(Hash?table,也叫哈希表)是根據關鍵碼值(Key?value)而直接進行訪問的數據結構,下面這篇文章主要給大家介紹了關于哈希表在算法題目中的實際應用,文中介紹的方法是Java,需要的朋友可以參考下
    2024-03-03
  • 程序包org.springframework不存在的解決辦法

    程序包org.springframework不存在的解決辦法

    這篇文章主要介紹了程序包org.springframework不存在的解決辦法,在使用IDEA創(chuàng)建SpringBoot項目時,剛打開無法正常運行,本文通過圖文結合的方式給大家介紹的非常詳細,具有一定參考價值,需要的朋友可以參考下
    2024-07-07
  • 淺談Java消息隊列總結篇(ActiveMQ、RabbitMQ、ZeroMQ、Kafka)

    淺談Java消息隊列總結篇(ActiveMQ、RabbitMQ、ZeroMQ、Kafka)

    這篇文章主要介紹了淺談Java消息隊列總結篇(ActiveMQ、RabbitMQ、ZeroMQ、Kafka),小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-05-05
  • 淺談Java設計模式系列-裝飾器模式

    淺談Java設計模式系列-裝飾器模式

    這篇文章主要介紹了Java設計模式系列-裝飾器模式,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-03-03
  • springboot清除字符串前后空格與防xss攻擊方法

    springboot清除字符串前后空格與防xss攻擊方法

    這篇文章主要介紹了springboot清除字符串前后空格與防xss攻擊方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08

最新評論

专栏| 太谷县| 封开县| 昌乐县| 邳州市| 和田市| 东阿县| 科技| 高密市| 松滋市| 崇义县| 阿鲁科尔沁旗| 普陀区| 海口市| 长子县| 清徐县| 龙游县| 卓资县| 措勤县| 曲阜市| 任丘市| 定襄县| 大余县| 长治县| 临武县| 鄱阳县| 裕民县| 南康市| 正宁县| 织金县| 平谷区| 大余县| 嫩江县| 澜沧| 泊头市| 新和县| 博客| 阿图什市| 泸西县| 湟中县| 福泉市|