Spring boot 搭建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方法
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* Created by on 2016/12/8.
*/
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class App extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
登陆页提交表单代码,
Controller 代码
package com.study.system.contrller;
import com.study.model.contrller.BaseContrller;
import com.study.model.po.User;
import com.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基类。
洋果子店rose最新版本
洋果子店最新版是一款十分容易让人垂涎的开店经营类手游。游戏玩
明日大亨最新版
明日大亨手游,一个非常经典有趣的模拟经营类型的商战手游,在游
早安我的少年日服最新版2024
早安我的少年日服是一款治愈恋爱手游,清新明亮的游戏画面,让你
我的世界基岩版1.16正式版
我的世界基岩版是一款模拟经营手游,游戏采用的是经典像素玩法,
早安我的少年最新版2024
早安我的少年是一款养成恋爱手游,在这款游戏中,玩家们将可以体