博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第一个SpringBoot项目
阅读量:4230 次
发布时间:2019-05-26

本文共 1646 字,大约阅读时间需要 5 分钟。

springBoot去除了spring复杂的配置,我们终于可以安心的写业务代码了。话不多说,直接开干。这里使用thymeleaf作为视图。

1.实体类

public class Person {    private String name;    private Integer age;    public Person(){        super();    }    public Person(String name,Integer age){        super();        this.name=name;        this.age=age;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public Integer getAge() {        return age;    }    public void setAge(Integer age) {        this.age = age;    }}
2.控制器:

@Controller@SpringBootApplicationpublic class FirstSpringBootApplication {    @RequestMapping("/")    public String index(Model model) {        Person single = new Person("aa", 11);        List
people = new ArrayList<>(); Person p1 = new Person("xx", 11); Person p2 = new Person("yy", 22); Person p3 = new Person("zz", 33); people.add(p1); people.add(p2); people.add(p3); model.addAttribute("singlePerson", single); model.addAttribute("people", people); return "index"; } public static void main(String[] args) { SpringApplication.run(FirstSpringBootApplication.class, args); }}

3.视图:(需按约定放在templates目录下)

    
Title

访问model

列表

= =好吧,已经完成了,运行main函数,在浏览器中输入localhost:8080就获取到数据了

转载地址:http://imjqi.baihongyu.com/

你可能感兴趣的文章
Agile Project Management: How to Succeed in the Face of Changing Project Requirements
查看>>
MySQL Bible
查看>>
Palm OS Programming Bible
查看>>
XSLT Quickly
查看>>
Inside XSLT
查看>>
Python & XML
查看>>
Java Cryptography
查看>>
J2EE Best Practices: Java Design Patterns, Automation, and Performance
查看>>
Mastering AspectJ: Aspect-Oriented Programming in Java
查看>>
Mastering Jakarta Struts
查看>>
Java and XSLT
查看>>
Learning PHP 5
查看>>
Building Java Enterprise Applications Volume I: Architecture
查看>>
Microsoft SQL Server 2000 Weekend Crash Course
查看>>
Struts: The Complete Reference
查看>>
Complex IT Project Management: 16 Steps to Success
查看>>
Project Risk Management Guidelines : Managing Risk in Large Projects and Complex Procurements
查看>>
SQL for Microsoft Access
查看>>
Visual Basic 2005 Express: Now Playing
查看>>
Jakarta Struts Cookbook
查看>>