Spring Boot erstellt Webanwendungen und integriert die Thymeleaf -Vorlage, um Anmeldung zu erreichen. Folgendes ist die Konfiguration von pom.xml
<? 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> <Packages> jar </packaging> <version> 1.0-Snapshot </Version> <!-Grundlegende Konfiguration von Spring Boot-> <spräparat> <gruppe> org.springFramework.Boot </GroupID> <Artifactid> Spring-Boot-Starter-Parent </artifactId> <ScharnitId> coding. Version-> <Properties> <project.build.SourceEncoding> UTF-8 </project.build.SourceEnDing> <Start-Class> com.study.App </startklasse> <Java.Version> 1.7 </java.version> <Shiro.version> 1.3.0 </Shiro. <PLUGINS> <GruppeId> org.springFramework.boot </GroupId> <artifactId> Spring-Boot-Maven-Plugin </artifactId> <Depecies> </Abhängigkeiten> </plugin> </plugins> </build> <dEapporcies> </GroupID> org.SPRAMEWRAME. <artifactId> Spring-Boot-Starter-Web </artifactId> </abhängig> <!-JPAs JAR-Paket, das die Datenbank betreibt, ähnelt dem Hibernate-> <De vorangetrieben> <Groupid> org.springFramework.boot </GroupId> <artifactid> Spring-boot-starter-data-jpa </artifactid> <!-Thymeleaf Template JAR-> <De vorstellen> <gruppe> org.springFramework.boot </Groupid> <artifactID> Spring-Boot-Starter-Thymeleaf </artifactID> </abhängig> <!-Mysql Treiber-> <Deponcy> <Gruppe> mySQL </gruppe> </gruppe> </gruppe> </gruppe> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- Add restfull support--> <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> <!-- Add druid data source connection pool --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.25</version> </abhängig> <!-Berechtigungsauthentifizierung hinzufügen-> <Depopentcy> <gruppe> org.apache.shiro </gruppeId> <artifactId> shiro-core </artifactid> <version> $ {shiro.version} </Version> </abhängig> <Depopentcy> <gruppe> org.apache.shiro </gruppe <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> <gruppeId> org.apache.shiro </Groupid> <artifactId> shiro-EHCache </artifactId> <version> $ {shiro.version} </Version> </abhängig> <!-Integration von Shiro und Shiro-> <Diefency> <gruppe> com.github. <artifactId> thymeleaf-extras-shiro </artifactId> <version> 1.2.1 </Version> </abhängig> </abhängig> </project>Haupteingangsmethode
import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.enableAutoconfiguration; import org.springframework.boot.autoconfigure.springbootAplication; org.springframework.boot.context.web.springbootServletinitializer; import org.springFramework.context.annotation.comPonentscan; */@Configuration@componentscan@EnableAutoConfigurationPublic Class App erweitert SpringbootServletInitializer {public static void main (String [] args) {Springapplication.run (App.Class, Args); }}Formularcode auf der Anmeldeseite einreichen,
<Formrolle = "Form" th: action = "@{/user/login}" th: methode = "post"> <Eingabe type = "text" placeholder = "userername" fordert = "forders" name = "userername"/> <Eingabetyp = "Passwort" placeholder = "Passwort" erfordert "erforderlich". value = "relain-me"/> remember me </label> </form>Controller -Code
Paket com.study.system.contrller; import com.study.model.contrller.basecontrler; import com.study.model org.springFramework.stereotype.controller; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.RequestMethod; java.util.list;/**** Benutzerverwaltung* Erstellt von 2016/12/12. */@Controller@requestMapping (value = "/user") public class userContrller erweitert BaseConTrller {@RequestMapPing (value = "/login", method = requestMethod.post) public String login (Benutzer Benutzer) {Try {if (userSerces.hasuser)) {{{{user edirect:/user. } else {return "recirect:/"; }} catch (Ausnahme e) {logger.Error ("Login fehlgeschlagen:"+e, e); } return "recirect:/"; } @RequestMapping (value = "/index", method = requestMethod.get) public String index () {try {} catch (exception e) {logger.Error ("Login fehlgeschlagen:"+e, e); } return "Seite/Index/Index"; } @Autowired private userservices userservices;}Wo Userservices eine Geschäftsschnittstelle ist. BaseConTrller verkauft die Controller -Basisklasse für sich.
Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.