spring boot 使用demo

Spring Boot Maven配置与日期转换
本文介绍如何使用Maven进行Spring Boot项目的配置,并演示了简单的应用实例。此外,还详细说明了如何实现日期格式的转换。

官方指引

一. Spring boot maven配置及使用

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
1. 需要使用某一个模块,引入就行,比如web
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
2. 新建配置文件和程序入口类

通用配置项 application.yml

server:
  port: 8080
  address: 0.0.0.0
  compression:
  enabled: true
  connection-timeout: 5000
  context-path: /
  tomcat:
    accept-count: 5000
    max-connections: 2000
    max-threads: 2000
    min-spare-threads: 100
    uri-encoding: UTF-8
spring:
    http:
      encoding:
        force: true
logging:
  file: xxx.log
  level:
    root: info

程序入口类和demo

package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@RestController
@SpringBootApplication
public class SpringApplication {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
         //启动
        SpringApplication.run(SampleController.class, args);
    }
}

然后输入http://localhost:8080

二. 日期转换

/**
 * 日期转换
 * @param binder
 */
@InitBinder
protected void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtil.YYYY_MM_DD_HH_MM_SS);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值