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

Spring boot搭建web應(yīng)用集成thymeleaf模板實(shí)現(xiàn)登陸

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

Spring boot 搭建web應(yīng)用集成了thymeleaf模板實(shí)現(xiàn)登陸
下面是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>
  <!--基本配置,設(shè)置編碼,入口,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>

  <!-- 設(shè)置編譯 -->
  <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包 ,操作數(shù)據(jù)庫的,類似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驅(qū)動-->
    <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 數(shù)據(jù)源連接池-->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.0.25</version>
    </dependency>

    <!-- 添加權(quán)限認(rèn)證-->
    <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è)務(wù)接口。BaseContrller為自己封裝的Controller基類。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • MyBatis-Plus 通用IService使用詳解

    MyBatis-Plus 通用IService使用詳解

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

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

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

    Java枚舉之EnumSet詳解

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

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

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

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

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

    哈希表在算法題目中的實(shí)際應(yīng)用詳解(Java)

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

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

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

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

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

    淺談Java設(shè)計(jì)模式系列-裝飾器模式

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

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

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

最新評論

庆云县| 西青区| 嵩明县| 南通市| 舞阳县| 普洱| 江口县| 安多县| 鄯善县| 延津县| 林州市| 黑水县| 泸水县| 泸溪县| 宜良县| 成都市| 阳谷县| 武乡县| 庆阳市| 天水市| 景东| 北海市| 遂宁市| 竹山县| 化隆| 南江县| 双鸭山市| 阿克陶县| 五家渠市| 甘德县| 昭苏县| 兰西县| 墨江| 华阴市| 亳州市| 六盘水市| 鹤壁市| 马关县| 应用必备| 淄博市| 保山市|