在IDEA中创建SpringBoot项目01

1.选择创建项目

2.填写项目信息

3.

4.

5.Finish后会下载,之后生成目录结构:

6.在自己的包目录结构下添加了Controllr和Entiy测试项目:

Controller:

 1 package com.hwl.graduation.controller;
 2 
 3 import com.hwl.graduation.entity.People;
 4 import org.springframework.stereotype.Controller;
 5 import org.springframework.web.bind.annotation.RequestMapping;
 6 import org.springframework.web.bind.annotation.ResponseBody;
 7 
 8 @Controller
 9 public class PersonController {
10 
11     @ResponseBody
12     @RequestMapping(value="/getPeople")
13     public People getPeople() {
14         return new People("菜鸟",20,"男");
15     }
16 }
View Code

Entity:

 1 package com.hwl.graduation.entity;
 2 
 3 public class People {
 4     private String name;
 5     private int age;
 6     private String sex;
 7 
 8     @Override
 9     public String toString() {
10         return "People [name=" + name + ", age=" + age + ", sex=" + sex + "]";
11     }
12 
13     public People() {
14         super();
15     }
16 
17     public People(String name, int age, String sex) {
18         super();
19         this.name = name;
20         this.age = age;
21         this.sex = sex;
22     }
23 
24     public String getName() {
25         return name;
26     }
27 
28     public void setName(String name) {
29         this.name = name;
30     }
31 
32     public int getAge() {
33         return age;
34     }
35 
36     public void setAge(int age) {
37         this.age = age;
38     }
39 
40     public String getSex() {
41         return sex;
42     }
43 
44     public void setSex(String sex) {
45         this.sex = sex;
46     }
47 
48 }
View Code

7.运行项目,浏览器访问成功:

猜你喜欢

转载自www.cnblogs.com/ynhwl/p/10229219.html
今日推荐