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.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>exam</groupId> <artifactId>examSystem</artifactId> <Cackaging> jar </packaging> <sersion> 1.0-snapshot </version> <!-Базовая конфигурация пружины Boot-> <parent> <groupid> org.springframework.boot </GroupId> <artifactid> Spring-boot-starter-parent </artifactid> <serse>, reverse, reverse, versemy, reversy, reversy, reversy, reving> <! <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> </propeserties> <shiro.version> 1.3.0 </shiro.version> <plugins> <groupid> org.springframework.boot </GroupId> <ArtifactId> пружина-разбирайтесь в Maven-plugin </artifactid> <depertiencies> </dependencies> </plugin> </plugins> </build> <deyedindions> <depertive> <groupid> org.spramework.boot </Group> <DegyDinencies> <groupid> org.spramework.boot </group> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--jpa's jar package, which operates the database, is similar to hibernate--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!--thymeleaf 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> <!-- Добавить поддержку RESTFULL-> <Depected> <groupid> javax.ws.rs </groupid> <artifactid> javax.ws.rs-api </artifactid> <sersion> 2.0.1 </version> </artepactid> <dependency> <groupid> net.bull.javamelody </artifactid> javamelododody-core-cored.1 <sersion> 1.53.0 </version> </dependency> <!-Добавить пул соединений источника данных Data Data-> <Degestending> <groupid> com.alibaba </GroupId> <strifactId> Druid </artifactid> <sersive> 1.0.25 </version> </depertive> <!-Добавить аутентику <artifactid> shiro-core </artifactid> <sersive> $ {shiro.version} </version> </depervice> <deyedency> <groupid> org.apache.shiro </GroupId> <ratifactid> shiro-spring </artifactid> <sersion> $ {Shiro.version} </версия> </artifactid> <sersion> {shiro.version} </resspernency> </resemend> </resemend> </artifactid> <serse> {shiro.version} </artifactid> <sersive> $ <groupId> org.apache.shiro </GroupId> <ArtifactId> shiro-web </artifactid> <seriation> $ {shiro.version} </version> </argefact> <dehyederience> <groupid> org.apache.shiro </GroupD> <ratifactid> shiro-ehcache </artifactid> </Groupid> <ratifactid> shiro-ehcache </artifachid> <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>Основной метод входа
Импорт org.springframework.boot.springapplication; импорт org.springframework.boot.autoconfigure.enableautoconfiguration; импорт org.springframework.boot.autoconfigure.springbootapplication; импорт org.spramework.bootpextrize org.springframework.context.annotation.componentscan; import org.springframework.context.annotation.configuration;/***, созданный на 2016/12/18. */@Configuration@componentscan@eNableAutoConfigurationPublic Class App Extends SpringbootServletinitialize {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" required="required" name="userName" /> <input type="password" placeholder="password" required="required" name="passwprd" /> <button type="submit">Login</button> <label> <input type="checkbox" value = "momply-me"/> Помните меня </label> </form>Код контроллера
пакет com.study.system.contrller; import com.study.model.contrller.basecontrller; import com.study.model.po.user; import com.study.system.services.UserServices; импорт org.spramework.beans.Annotation.Autowrifition; org.springframework.stereotype.controller; import org.springframework.web.bind.nantation.requestmapping; импорт org.springframework.web.bindtation.Requestmethod; import org.spramework.web.bindtation.restControler; Управление пользователями* Создано на 2016/12/12. */@Controller@requestmapping (value = "/user") открытый класс usercontrller extends basecontrller {@requestmapping (value = "/login", method = requestMethod.post) public String login (пользователь пользователь) {try {if userservices.hasuser (user)) {return "redirect:/user/index"; } else {return "redirect:/"; }} catch (Exception e) {logger.error ("login не удастся:"+e, e); } вернуть "redirect:/"; } @RequestMapping (value = "/index", method = requestMethod.get) public String index () {try {} catch (Exception e) {logger.error ("login не удастся:"+e, e); } return "page/index/index"; } @Autowired private userservices userservices;}Где пользовательские услуги - это бизнес -интерфейс. BaseContrller инкапсулирует базовый класс контроллера для себя.
Выше всего содержание этой статьи. Я надеюсь, что это будет полезно для каждого обучения, и я надеюсь, что все будут поддерживать Wulin.com больше.