Spring Boot construye aplicaciones web e integra la plantilla THyMeleaf para lograr el inicio de sesión. La siguiente es la configuración de pom.xml
<? xml versión = "1.0" encoding = "utf-8"?> <Project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/xmlschemainstance" xsi: schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelever> 4.0.0 </modelversion> <MoupRoMid> Exam </groupID> <Atifactid> Examsystem </artistemid> <Apbackaging> jar </packaging> <versión> 1.0-snapshot </verversion> <!-Configuración básica del arranque de Spring-> <Parent> <MoupRoD> org.springframework.boot </groupid> <artifactid> spring-boot-starter-parent </artifactid> <versers> 1.2.7.release </versión> </breel> <! Configuración básica, Coding, iniciar Coding, Iniciar Coding, Iniciar Coding, inym Versión-> <Proteies> <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> </propietarios <! <glugins> <MoupRupid> org.springframework.boot </proupid> <artifactid> spring-boot-maven-plugin </artifactid> <pendencies> </dependencias> </glugin> </glugins> </struction> <pendencies> <pendencies> <proupid> org.springframework.Boot </groupid> <artifactID> spring-boot-starter-web </artifactid> </dependency> <!-el paquete jar jpa, que opera la base de datos, es similar a hibernate-> <pendency> <MoupRupid> org.springframework.boot </groupId> <artifactID> spring-boot-starter-starter-sat-jpa </artifactid> </thymeleMel> </thymeleMel> </thymeleMel> </thymeleMel> </thymeleMel> </thymeleMel> </thymeleMel> template jar--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--mysql driver--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> < <Versión> 1.53.0 </versión> </pendency> <!-Agregar grupo de conexión de fuente de datos Druid-> <pendency> <MoupRid> com.alibaba </proupid> <artifactid> druid </artifactid> <versión> 1.0.25 </versión> </dependencia> <!-Añadir la autenticación de permiso-> <pendency> <proupID> org.apache.shiro <artifactid> shiro-core </artifactid> <versión> $ {shiro.version} </versión> </pendency> <pendency> <proupid> org.apache.shiro </groupid> <artifactid> shiro-spring </artifactid> <version> $ {shiro.version} </versión> </version> </spendency> <MoupRid> org.apache.shiro </groupid> <artifactid> shiro-web </artifactid> <versions> $ {shiro.version} </ververion> </pendency> <ependency> <proupid> org.apache.shiro </groupid> <arifactid> shiro-ehcache </artifactid> <version>${shiro.version}</version> </dependency> <!--Integration of shiro and shiro--> <dependency> <groupId>com.github.theborakompanioni</groupId> <artifactId>thymeleaf-extras-shiro</artifactId> <version>1.2.1</version> </dependency> </dependencies></project>Método de entrada principal
importar org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.enableautoconfiguration; import org.springframework.boot.autoconfigure.springbootapplication; import org.springframe.boot.boot.weBOTEXTEXTEXT. org.springframework.context.annotation.componentscan; import org.springframework.context.annotation.configuration;/*** creado por el 2016/12/8. */@Configuration@ComponentScan@EnableautoconfigurationPublic de la aplicación de clase extiende SpringBootServletInitializer {public static void main (string [] args) {springapplication.run (app.class, args); }}Enviar código de formulario en la página de inicio de sesión,
<form de rol = "form" th: action = "@{/user/login}" th: método = "post"> <input type = "text" placeholder = "username" requerido = "requerido" name = "username"/> <input type = "contraseña" placeholder = "contraseña" requerido = "requerido" nombre = "passwprd"/> <button type = "Subt"> login </button <button <button <button " value = "Remember-me"/> Remember Me </label> </orm>Código de controlador
paquete com.study.system.contrller; import com.study.model.contrller.basecontrller; import com.study.model.po.user; import com.study.system.services.userServices; importar org.springfframework.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.springfrframework.web.bind.annotation * Gestión de usuarios * creado por el 2016/12/12. */@Controlador@requestmapping (value = "/user") public class Usercontrller extiende basecontrller {@RequestMapping (valor = "/login", método = requestmethod.post) public string login (usuario user) {try {if (ussureServices.hasUser (user)) {return "redirect:/user/° Index";; } else {return "redirect:/"; }} catch (Exception e) {logger.error ("Iniciar fallas:"+e, e); } return "redirect:/"; } @RequestMapping (value = "/index", método = requestmethod.get) public string index () {try {} catch (excepción e) {logger.error ("inicio de sesión fallido:"+e, e); } return "página/index/index"; } @AUtowired private UserServices UserServices;}Donde UserServices es una interfaz comercial. Basecontrller encapsula la clase base del controlador para sí misma.
Lo anterior es todo el contenido de este artículo. Espero que sea útil para el aprendizaje de todos y espero que todos apoyen más a Wulin.com.