Spring Boot는 웹 응용 프로그램을 구축하고 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.xsd"> <modeversion> 4.0.0 </modelversion> <groupid> Exam </GroupId> <artifactid> </artifactem> <packaging> jar </packaging> <bersion> 1.0-snapshot </version> <!-스프링 부팅의 기본 구성-> <부모> <groupid> org.springframewort.boot </groupid> <artifactid> spring-boot-starter-parent </artifactid> <bersion> 1.2.7. version> </parent </parenting, jd k </parentin </parent </version. 버전-> <properties> <proffect.build.sourceencoding> utf-8 </project.build.sourceencoding> <tartclass> com.study.app </start-class> <java.version> 1.7 </java.version> <shiro.version> 1.3.0 </shiro.version> <! <플러그인> <groupid> org.springframework.boot </groupid> <artifactid> Spring-Boot-Maven-Plugin </artifactid> <pectionies> </fuplencies> </plugin> </plugins> </build> </build> <Artifactid> Spring-Boot-starter-web </artifactid> </areventency> <!-데이터베이스를 운영하는 JPA의 JAR 패키지는 Hibernate-> <pectionency> <groupID> org.springframework.boot </groupid> <theploat-starter--jpa </artifactid> <! 템플릿 JAR-> <pectionency> <groupid> org.springframework.boot </groupid> <artifactid> spring-boot-starter-thymeleaf </artifactid> </fectionency> <!-mysql 드라이버-> <pelepency> <groupid> mysql </groupid> <artifactid> mysql-connector-</artifactid> restfull 지원 추가-> <pectionency> <groupid> javax.ws.rs </groupid> <artifactid> javax.ws.rs-api </artifactid> <버전> 2.0.1 </dependency> <pection> <groupid> net.bull.javamelody <artifactid> <버전> 1.53.0 </version> </dependency> <!-드루이드 데이터 소스 연결 풀을 추가-> <pectionency> <groupid> com.alibaba </groupid> <artifactid> druid </artifactid> <version> 1.0.25 </version> </dependency> <!-ADD ADDMISSION AUTHENCICATION-> <GRUPID> ORG.APICHE.SHIPORO.HIPACHE.SHIPERO.SHIPERO.HIPACHE.SHIPENCIATION ADD <artifactid> shiro-core </artifactid> <bersion> $ {shiro.version} </version} </version> </dependency> <groupid> org.apache.shiro </groupId> <artifactid> spring </artifactid> <version> $ {shiro.version} </delpence> <groupid> org.apache.shiro </groupid> <artifactid> Shiro-web </artifactid> <버전> $ {shiro.version} </version} </version} </version} </depection> <groupid> org.apache.shiro </groupid> <artifactid> shiro-ehcache </artifactid> <버전> $ {shiro.version} </version> </dependency> <! <!-Shiro and Shiro의 통합-> <groupId> com.github.theborakompanioni </groupomid> <artifactid> thymeleaf-extras-shiro </artifactid> </project> </dependency>메인 엔트리 메소드
import org.springframework.boot.springApplication; import org.springframework.boot.autoconfigure.enableautoconfiguration; import org.springframewort.boot.autoconfigure.springbootapplication; import org.springframewort.botletiniet.spootservletiniet org.springframework.context.annotation.componentscan; import org.springframework.context.annotation.configuration;/***에 의해 작성되었습니다. */@configuration@componentscan@enableAutoConfigurationPublic Class App는 SpringBootserVletInitializer {public static void main (String [] args) {springApplication.run (App.Class, args); }}로그인 페이지에서 양식 코드 제출,
<form role = "form"th : action = "@{/user/login}}"th : method = "post"> <input type = "text"placeholder = "username"resight "="required "name ="username "/> <입력 유형 ="placeholder "placeholder ="require "name ="resight "="passwprd "</<goollade> <inputy" "place" "placeholder ="place " value = "Remember-Me"/> 기억 나게 </label> </form>컨트롤러 코드
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.nack.annotationalation; import; org.springframework.stereotyp.controller; import org.springframework.web.bind.annotation.requestmapping; import org.sprameframework.bind.annotation.requestmethod; import org.springframework.web.bind.annotation.restcontroller; 사용자 관리* 2016/12/12에 의해 생성되었습니다. */@controller@requestMapping (value = "/user") public class UserContrller는 basecontrller {@requestmapping (value = "/login", method = requestmethod.post) public string login (user user) {try {if (userservices.hasuser (user)) {return "return"return "return"; } else {return "retail"renirect :/"; }} catch (예외 e) {logger.error ( "로그인 실패 :"+e, e); } return "Reliprect :/"; } @requestmapping (value = "/index", method = requestmethod.get) public String index () {try {} catch (예외 e) {logger.error ( "로그인 실패 :"+e, e); } return "page/index/index"; } @autowired private userervices userervices;}사용자 서비스가 비즈니스 인터페이스 인 경우. Basecontrller는 컨트롤러 기본 클래스 자체를 캡슐화합니다.
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.