springboot2.0 entry (two) - infrastructure projects built with plug +

A, idea in the first new HelloWorld project

 

 Click next:

 The next step

Here you can choose our need to rely on third-party software libraries, including spring-boot-web, mysql driver, mybatis and so on. We do not add any here being the first dependent, dependent on the text manually add maven after we

 

 

 The following delete these files after the project is built, these files are version controlled maven related files. We combine IDEA management maven, generally less than these documents

 

 

 The properties files instead yml file, function and properties of this file is the same file, the file structure yml more clear, the need to change the default startup port 8090

 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
 </dependency>

 

Into the web-starter in the xml file  

@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String hello(String name) {
        return "hello world, " +name;
    }
}

新建一个HelloController,并创建一个接口:

 

 

 点击debug运行

 

 

 2.48秒启动成功

 

 

 输入地址,后面接上参数,屏幕上显示后台返回的内容

二、lombok插件的引入和使用:

使用lombok有以下几个功能,更多功能可百度 :

  • 根据成员变量生成get和set方法
  • 根据成员变量生成类的构造函数
  • 重写toString()和hashCode方法
  • 引入日志框架logFactory,用来打印日志

Settings  -->Plugins-->Marketplace 

下载插件:

 <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
</dependency>

下载好 插件后,还需要在pom.xml中引入相关依赖才可以继续使用:

 

 

 新建一个Person 类,在测试新建Person的实例对象,在是指set的时候,自动提示出属性的set方法;

 

 

使用@Slf4j注解,可以在方法下直接使用log打印日志;

 

 

 使用@Builder 注解可以进对象的构建,但是,继承的属性name是不能进行构建的,有全参构造函数注解,自然就有无参构造函数注解:NoArgsConstructor注解。

三、项目的热部署

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
        <!-- optional=true,依赖不会传递,该项目依赖devtools;之后依赖myboot项目的项目如果想要使用devtools,需要重新引入 -->
      <optional>true</optional>
</dependency>

 

引入热部署的maven依赖:

 <!-- 热部署插件-->
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>

在 plugin 中配置另外一个属性 fork,并且配置为 true。

 

 

打开自从 编译

 

 

 组合键:“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running” 。

 

 

 修改返回结果,刷新页面,看到结果已经改变;

3、GeoFormat:可以快速的将JSON转换为实体类,在插件中搜索下载后,在使用

 
 
/**
* id : 1
* author : zimug
* title : 手摸手教你开发spring boot
* content : c
* createTime :
* reader : [{"name":"zimug","age":18},{"name":"kobe","age":37}]
*/
//先定义一个空的实体类,快捷键Alt + S,相信后面你就都会了.这是根据JSON生成出来的对应的java bean的代码。
private int id;
private String author;
private String title;
private String content;
private String createTime;
private List<ReaderBean> reader;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getCreateTime() {
return createTime;
}

public void setCreateTime(String createTime) {
this.createTime = createTime;
}

public List<ReaderBean> getReader() {
return reader;
}

public void setReader(List<ReaderBean> reader) {
this.reader = reader;
}

public static class ReaderBean {
/**
* name : zimug
* age : 18
*/

private String name;
private int age;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
}

 

准备工作完成!!!

 

Guess you like

Origin www.cnblogs.com/liweiweicode/p/11621977.html
Recommended