Spring boot搭建web应用集成thymeleaf模板实现登陆
Springboot搭建web应用集成了thymeleaf模板实现登陆
下面是pom.xml的配置
4.0.0 exam examSystem jar 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent 1.2.7.RELEASE UTF-8 com.study.App 1.7 1.3.0 org.springframework.boot spring-boot-maven-plugin org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-thymeleaf mysql mysql-connector-java javax.ws.rs javax.ws.rs-api 2.0.1 net.bull.javamelody javamelody-core 1.53.0 com.alibaba druid 1.0.25 org.apache.shiro shiro-core ${shiro.version} org.apache.shiro shiro-spring ${shiro.version} org.apache.shiro shiro-web ${shiro.version} org.apache.shiro shiro-ehcache ${shiro.version} com.github.theborakompanioni thymeleaf-extras-shiro 1.2.1
主入口main方法
importorg.springframework.boot.SpringApplication;
importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;
importorg.springframework.boot.autoconfigure.SpringBootApplication;
importorg.springframework.boot.context.web.SpringBootServletInitializer;
importorg.springframework.context.annotation.ComponentScan;
importorg.springframework.context.annotation.Configuration;
/**
*Createdbyon2016/12/8.
*/
@Configuration
@ComponentScan
@EnableAutoConfiguration
publicclassAppextendsSpringBootServletInitializer{
publicstaticvoidmain(String[]args){
SpringApplication.run(App.class,args);
}
}
登陆页提交表单代码,
登录 记住我
Controller代码
packagecom.study.system.contrller;
importcom.study.model.contrller.BaseContrller;
importcom.study.model.po.User;
importcom.study.system.services.UserServices;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.stereotype.Controller;
importorg.springframework.web.bind.annotation.RequestMapping;
importorg.springframework.web.bind.annotation.RequestMethod;
importorg.springframework.web.bind.annotation.RestController;
importjava.util.List;
/**
*
*用户管理
*Createdbyon2016/12/12.
*/
@Controller
@RequestMapping(value="/user")
publicclassUserContrllerextendsBaseContrller{
@RequestMapping(value="/login",method=RequestMethod.POST)
publicStringlogin(Useruser){
try{
if(userServices.hasUser(user)){
return"redirect:/user/index";
}else{
return"redirect:/";
}
}catch(Exceptione){
logger.error("登陆失败:"+e,e);
}
return"redirect:/";
}
@RequestMapping(value="/index",method=RequestMethod.GET)
publicStringindex(){
try{
}catch(Exceptione){
logger.error("登陆失败:"+e,e);
}
return"page/index/index";
}
@Autowired
privateUserServicesuserServices;
}
其中UserServices为业务接口。BaseContrller为自己封装的Controller基类。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。