继续接上篇http://blog.csdn.net/javastudyr/article/details/52597621,这篇开始来搭建springboot方式的ssmm框架
思路
- 创建一个maven项目
- 配置pom.xml
- 创建application.properties文件
- 配置mybatis,事物,数据库等信息
- 配置springmvc
- 创建启动类
- 创建测试类
- 开始测试
1.创建一个maven项目
2.配置pom.xml
<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>com.study</groupId>
<artifactId>boot-study-ssmm-boot</artifactId>
<version>1.0.0</version>
<!-- springboot 父类,版本控制-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
<mybatis.version>3.3.1</mybatis.version>
<mybatis.spring.version>1.2.4</mybatis.spring.version>
<mapper.version>3.3.6</mapper.version>
<pagehelper.version>4.1.1</pagehelper.version>
</properties>
<dependencies>
<!--对全栈web开发的支持,包括Tomcat和 spring-webmvc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 对面向切面编程的支持,包括 spring-aop 和AspectJ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- 对常用测试依赖的支持,包括JUnit, Hamcrest和Mockito,还有 spring-test 模块 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- 对JDBC数据库的支持 自然也包括事务 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- 数据库连接 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- json -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.11</version>
</dependency>
<!--Mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<!--分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!--通用Mapper-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
<!--spring-boot-configuration:spring boot 配置处理器; -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- tomcat配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- servlet 依赖. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 可执行jar -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3.创建application.properties
在src/main/resources/下创建application.properties
4.配置数据库
(1). 配置数据库
####################################################
#### jdbc
####################################################
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username = root
spring.datasource.password =
spring.datasource.driverClassName = com.mysql.jdbc.Driver
(2)配置mybatis
- 配置扫描类
package com.study.springboot.config;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;
/**
* mybatis 扫描类配置
* @author like
*
*/
@Configuration
//注意,由于MapperScannerConfigurer执行的比较早,所以必须有下面的注解
@AutoConfigureAfter(MybatisConf.class)
public class MyBatisMapperScannerConfig {
@Bean
public MapperScannerConfigurer mapperScannerConfigurer() {
MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
mapperScannerConfigurer.setBasePackage("com.study.springboot.mapper");
return mapperScannerConfigurer;
}
}
- 配置jdbc,mybatis存放路径和别名
package com.study.springboot.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* JDBC 基本配置
* @author like
*
*/
@Component
@ConfigurationProperties(prefix="spring.datasource")
public class JdbcConfig {
private String url;
private String userName;
private String password;
private String driverClassName;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
}
package com.study.springboot.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
/**
* mapper 基本配置
* @author like
*
*/
@Component
@ConfigurationProperties(prefix="mybatis.prop")
public class MybatisProp {
private String mapperLocations;//mapper存放路径
private String typeAliasesPackage; //别名包
public String getMapperLocations() {
return mapperLocations;
}
public void setMapperLocations(String mapperLocations) {
this.mapperLocations = mapperLocations;
}
public String getTypeAliasesPackage() {
return typeAliasesPackage;
}
public void setTypeAliasesPackage(String typeAliasesPackage) {
this.typeAliasesPackage = typeAliasesPackage;
}
}
- mybatis基本配置
package com.study.springboot.config;
import java.util.Properties;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
import com.alibaba.druid.pool.DruidDataSource;
import com.github.pagehelper.PageHelper;
@Configuration
@EnableTransactionManagement
public class MybatisConf implements TransactionManagementConfigurer{
@Autowired
private JdbcConfig jdbcConfig;
@Autowired
private MybatisProp prop;
/**
* 配置 dataSource
相当于 xml
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driverClass}"/>
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="user" value="${user}" />
<property name="password" value="${password}"/>
</bean>
* @return
*/
@Bean(name="dataSource")
public DruidDataSource createDataSource(){
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUrl(jdbcConfig.getUrl());
druidDataSource.setDriverClassName(jdbcConfig.getDriverClassName());
druidDataSource.setUsername(jdbcConfig.getUserName());
druidDataSource.setPassword(jdbcConfig.getPassword());
return druidDataSource;
}
/**
* xml配置
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.study.bean"/>
</bean>
* @return
*/
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean(){
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(createDataSource());
//别名包
bean.setTypeAliasesPackage(prop.getTypeAliasesPackage());
//分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);
//添加插件
bean.setPlugins(new Interceptor[]{pageHelper});
//添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
try {
//设置mapper 目录,这些都可以配置到配置文件中,直接注入进来接可以了
bean.setMapperLocations(resolver.getResources(prop.getMapperLocations()));
return bean.getObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
};
/**
* 整合 spring +mybaits
* @param sqlSessionFactory
* @return
*/
@Bean
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
/*
* 配置注解事物
* 相当于xml
<!-- spring 事务 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 开启注解事务-->
<tx:annotation-driven transaction-manager="transactionManager"/>
*/
public PlatformTransactionManager annotationDrivenTransactionManager() {
return new DataSourceTransactionManager(createDataSource());
}
}
- springmvc 配置,配置jsp存放路径
server.port=8001
####################################################
#### jdbc
####################################################
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username = root
spring.datasource.password =
spring.datasource.driverClassName = com.mysql.jdbc.Driver
####################################################
#### mybatis
####################################################
mybatis.prop.mapperLocations=classpath:mapper/*.xml
mybatis.prop.typeAliasesPackage=com.study.springboot.bean
####################################################
#### jsp
####################################################
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
- springmvc 配置时间转化器,字符拦截器
package com.study.springboot.config;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.core.convert.converter.Converter;
/**
* 字符串转Date
* @author like
*
*/
public class StringToDateConverter implements Converter<String, Date> {
public Date convert(String source) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
try {
return dateFormat.parse(source);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}
package com.study.springboot.config;
import java.nio.charset.Charset;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
/**
* Spring mvc 配置
* @author like
*
*/
@Configuration
public class SpringMVCConfig extends WebMvcConfigurerAdapter{
/* 解决转码问题Spring @responseBody 问题
* @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#configureMessageConverters(java.util.List)
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(getConverter());
}
public StringHttpMessageConverter getConverter(){
StringHttpMessageConverter converter = new StringHttpMessageConverter();
converter.setDefaultCharset(Charset.forName("UTF-8"));
return converter;
}
// 局部时间配置
// @InitBinder("date")
// public void initBinder(WebDataBinder binder){
// binder.registerCustomEditor(Date.class,new CustomDateEditor(new SimpleDateFormat("yyyyMMdd"), true, 8));
// }
@Autowired
private RequestMappingHandlerAdapter handlerAdapter;
/**
* 增加字符串转日期的功能
*/
@PostConstruct
public void initEditableValidation() {
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) handlerAdapter
.getWebBindingInitializer();
if (initializer.getConversionService() != null) {
GenericConversionService genericConversionService = (GenericConversionService) initializer
.getConversionService();
genericConversionService.addConverter(new StringToDateConverter());
}
}
}
(3) 创建启动类
package com.study.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BootApp {
public static void main(String[] args) {
SpringApplication.run(BootApp.class, args);
}
}
(4)创建 测试基础类
package com.study.springboot.bean;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
public class User {
@Id
@Column(name = "Id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String email;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "User [id=" + id + ", name=" + name + ", email=" + email + "]";
}
}
package com.study.springboot.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.study.springboot.bean.User;
import com.study.springboot.mapper.UserMapper;
@Service
public class UserServiceImpl {
@Autowired
private UserMapper userMapper;
public User find(Integer id) {
return userMapper.selectByPrimaryKey(id);
}
}
package com.study.springboot.mapper;
import com.study.springboot.bean.User;
import tk.mybatis.mapper.common.Mapper;
public interface UserMapper extends Mapper<User>{
}
package com.study.springboot.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.study.springboot.bean.User;
import com.study.springboot.service.UserServiceImpl;
@RestController
public class TestController {
@Autowired
private UserServiceImpl userServiceImpl;
@RequestMapping(value="/user")
public String testMybaits(Integer id){
User user = userServiceImpl.find(id);
return user.toString();
}
@RequestMapping(value="/unicode")
public String unicode(){
return "成功";
}
}
package com.study.springboot.controller;
import java.util.Date;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class CoreController {
@RequestMapping(value="welcome")
public String toWelcome(){
return "welcome";
}
@RequestMapping(value="todate")
public String todate(){
return "date";
}
@RequestMapping(value="date")
public String date(Date date){
System.out.println(date);
return "date";
}
}
- 创建mapper
在 src/main/resources 下创建mapper 目录
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.study.springboot.mapper.UserMapper">
</mapper>
(5)创建 测试页面
在 src/main/webapp/WEB-INF/view/
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/date" method="post">
时间 :<input type="text" name="date"/><br/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
welcome!
</body>
</html>
(6)开始测试
直接运行 BootApp main方法
启动成功 ,可以看见一下内容:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.0.RELEASE)
2016-09-22 14:47:23.610 INFO 6088 --- [ main] com.study.springboot.BootApp : Starting BootApp on USER-20150824CO with PID 6088 (J:\eclipse-javaee\work\boot\boot-study-ssmm-boot\target\classes started by Administrator in J:\eclipse-javaee\work\boot\boot-study-ssmm-boot)
2016-09-22 14:47:23.617 INFO 6088 --- [ main] com.study.springboot.BootApp : No active profile set, falling back to default profiles: default
2016-09-22 14:47:23.703 INFO 6088 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@11dbed: startup date [Thu Sep 22 14:47:23 CST 2016]; root of context hierarchy
2016-09-22 14:47:24.962 WARN 6088 --- [ main] o.s.c.a.ConfigurationClassPostProcessor : Cannot enhance @Configuration bean definition 'myBatisMapperScannerConfig' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2016-09-22 14:47:25.589 INFO 6088 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'jdbcConfig' of type [class com.study.springboot.config.JdbcConfig] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-09-22 14:47:25.601 INFO 6088 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'mybatisProp' of type [class com.study.springboot.config.MybatisProp] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-09-22 14:47:25.602 INFO 6088 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'mybatisConf' of type [class com.study.springboot.config.MybatisConf$$EnhancerBySpringCGLIB$$2212bb2e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-09-22 14:47:25.744 INFO 6088 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSource' of type [class com.alibaba.druid.pool.DruidDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-09-22 14:47:25.751 INFO 6088 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration' of type [class org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$$EnhancerBySpringCGLIB$$f53b36e1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-09-22 14:47:25.826 INFO 6088 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties' of type [class org.springframework.boot.autoconfigure.jdbc.DataSourceProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-09-22 14:47:25.831 INFO 6088 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSourceInitializer' of type [class org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-09-22 14:47:25.833 INFO 6088 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$13479381] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-09-22 14:47:26.502 INFO 6088 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8001 (http)
2016-09-22 14:47:26.519 INFO 6088 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-09-22 14:47:26.520 INFO 6088 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.4
2016-09-22 14:47:27.056 INFO 6088 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2016-09-22 14:47:27.063 INFO 6088 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-09-22 14:47:27.063 INFO 6088 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3363 ms
2016-09-22 14:47:27.355 INFO 6088 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-09-22 14:47:27.362 INFO 6088 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-09-22 14:47:27.363 INFO 6088 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-09-22 14:47:27.363 INFO 6088 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-09-22 14:47:27.363 INFO 6088 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-09-22 14:47:27.873 INFO 6088 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@11dbed: startup date [Thu Sep 22 14:47:23 CST 2016]; root of context hierarchy
2016-09-22 14:47:28.551 INFO 6088 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/date]}" onto public java.lang.String com.study.springboot.controller.CoreController.date(java.util.Date)
2016-09-22 14:47:28.554 INFO 6088 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/welcome]}" onto public java.lang.String com.study.springboot.controller.CoreController.toWelcome()
2016-09-22 14:47:28.555 INFO 6088 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/todate]}" onto public java.lang.String com.study.springboot.controller.CoreController.todate()
2016-09-22 14:47:28.555 INFO 6088 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/unicode]}" onto public java.lang.String com.study.springboot.controller.TestController.unicode()
2016-09-22 14:47:28.556 INFO 6088 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user]}" onto public java.lang.String com.study.springboot.controller.TestController.testMybaits(java.lang.Integer)
2016-09-22 14:47:28.560 INFO 6088 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-09-22 14:47:28.561 INFO 6088 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-09-22 14:47:28.632 INFO 6088 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-22 14:47:28.632 INFO 6088 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-22 14:47:28.731 INFO 6088 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-22 14:47:29.325 INFO 6088 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-09-22 14:47:29.326 INFO 6088 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2016-09-22 14:47:29.335 INFO 6088 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.alibaba.druid.pool:name=dataSource,type=DruidDataSource]
2016-09-22 14:47:29.567 INFO 6088 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8001 (http)
2016-09-22 14:47:29.574 INFO 6088 --- [ main] com.study.springboot.BootApp : Started BootApp in 6.672 seconds (JVM running for 7.159)
- 访问 http://localhost:8001/unicode
返回成功,表示字符测试成功
访问 http://localhost:8001/user?id=1,这里注意下数据库SQL自己准备哈
- 下面是我的SQL
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
- 返回User [id=1, name=test, email=123456]
- 表示搭建成功
继续访问:http://localhost:8001/todate
后台打印出你输出的时间,转的的date,表示成功
如: 2016-08-08 –>Sun Dec 08 00:00:00 CST 15
成功
到此,次springboot框架搭建就完成了
今天刚刚创建学习群,可以进群一起学习java,springboot