• springboot入门


    1、快速创建springboot项目

    1.1、使用spring官方SPRING INITIALIZR工具可以快速创建springboot项目。IDEA开发工具也集成了spring initializr工具

    1.2、maven项目目录结构

    project maven

    |--java目录结构(保存所有后台java代码)

    |----com.company.projectname.controller

    |----com.company.projectname.service

    |----com.company.projectname.dao

    |--resource目录结构

    |----static:保存所有的静态资源(js,css,image)

    |----template:保存所有的模板页面

    |----application.properties:spring应用配置文件

    2、SpringBootApplication注解

    /**
     *SpringBootApplication注解,应用的入口,可以启动应用
     */
    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class,args);
        }
    
    }
    

    3、springboot应用打包运行

    打包:springboot maven插件,可以将应用打包成一个可执行jar。将下面配置在pom.xml,执行idea maven:Lifecycle -> package

    <build>
    	<plugins>
    		<plugin>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-maven-plugin</artifactId>
    		</plugin>
    	</plugins>
    </build>
    

    controller编写:

    /**
     * RestController = Controller + ResponseBody
     * ResponseBody :方法返回的数据直接给浏览器
     */
    @RestController
    public class HelloController {
    
        @RequestMapping("/hello")
        public String hello(){
            return "hello world!";
        }
    }
    

    运行:java -jar spring-boot-helloword-1.0-SNAPSHOT.jar

    访问:localhost:8080/helloworld

  • 相关阅读:
    HDU 4405 Aeroplane chess (概率dp)
    条件编译符号与公布
    hdu 1722 Cake 数学yy
    电脑显示U盘,可是读取不了
    多本Web前端深度修炼书籍(提供网盘下载链接)
    HDU 5410(2015多校10)-CRB and His Birthday(全然背包)
    Servlet体验之旅(二)——Session、Cookie
    &lt;pre&gt;标签
    每天学点Python之comprehensions
    编写html经常使用而又easy忘记的语句
  • 原文地址:https://www.cnblogs.com/chenweichu/p/9998188.html
Copyright © 2020-2023  润新知