Spring boot 搭建web应用集成了thymeleaf模板实现登陆
下面是pom.xml的配置
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://.study.system.services.UserServices;import org.springframework.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.springframework.web.bind.annotation.RestController;import java.util.List;/** * * 用户管理 * Created by on 2016/12/12. */@Controller@RequestMapping(value = "/user")public class UserContrller extends BaseContrller { @RequestMapping(value="/login",method= RequestMethod.POST) public String login(User user){ try{ if(userServices.hasUser(user)){ return "redirect:/user/index"; }else{ return "redirect:/"; } }catch (Exception e){ logger.error("登陆失败:"+e,e); } return "redirect:/"; } @RequestMapping(value="/index",method= RequestMethod.GET) public String index(){ try{ }catch (Exception e){ logger.error("登陆失败:"+e,e); } return "page/index/index"; } @Autowired private UserServices userServices;}
其中 UserServices 为业务接口。BaseContrller为自己封装的Controller基类。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。