Spring Boot Demo

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author tracyLi
* @create 2018-08-15 0:57
* 来标注一个主程序类,说明是一个Spring Boot应用
*/
@SpringBootApplication
public class HelloWoldApplication {
public static void main(String[] args) {
//Spring应用启动起来
SpringApplication.run(HelloWoldApplication.class,args);
}
}

Controller层

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* @author tracyLi
* @create 2018-08-15 1:03
*/
@Controller
public class HelloController {

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

}

配置文件
《?xml version=”1.0” encoding=”UTF-8”?>
《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

《groupId>com.atguigu</groupId>
《artifactId>spring-boot-01-helloword</artifactId>
《version>1.0-SNAPSHOT</version>

《parent>
    《groupId>org.springframework.boot</groupId>
    《artifactId>spring-boot-starter-parent</artifactId>
    《version>1.5.9.RELEASE</version>
《/parent>


《dependencies>
    《dependency>
        《groupId>org.springframework.boot</groupId>
        《artifactId>spring-boot-starter-web</artifactId>
        《exclusions>
            《exclusion>
                《groupId>org.springframework.boot</groupId>
                《artifactId>spring-boot-starter-logging
                《/artifactId>
            《/exclusion>
        《/exclusions>
    《/dependency>
    《dependency>
        《groupId>org.springframework.boot</groupId>
        《artifactId>spring-boot-starter-log4j2
        《/artifactId>
    《/dependency>
《/dependencies>

<!-- 这个插件,可以将应用打包成一个可执行的jar包;-->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

一个简单的Spring Boot 部署完毕!编译问题,把《替换成<,即可!谢谢!

其他配置文件(可忽略)
yml属性赋值
server:
port: 8081

person:
name: zhangsan
age: 18
boss: false
birthday: 2017/12/12
maps: {k1: v1,k2: 12}
lists:
- lisi
- zhaohao
dog:
name: 小狗
age: 2

properties文件赋值
server.port=8082
person.name=86552@qq.com
person.age=18
person.birthday=1918/12/12
person.boss=false
person.dag.name=xiaogou
person.dag.age=2
person.lists=a,s,d
person.maps.k1=liuqiang
person.maps.k2=panbo

自动注入:
import org.hibernate.validator.constraints.Email;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* @author tracyLi
* @create 2018-08-15 23:24
*/
@PropertySource(value = {“classpath:person.properties”})
@Component
//@Validated
@ConfigurationProperties(prefix = “person”)
public class Person {
@Email
// @Value(“${person.name}”)
private String name;
// @Value(“#{11*12}”)
private Integer age;
// @Value(“true”)
private boolean boss;
private Date birthday;

private Dog dag;

// @Value(“${person.maps}”)
private Map

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值