SpringBoot基本套路

<1> 学习SpringBoot,得了解它的优势所在,这也是为啥用它的原因;

        (1).SpringBoot对Spring框架做了封装

        (2).SpringBoot内置Tomcat服务器,启动时会自动将程序发布到Tomcat服务器

        (3).SpringBoot具有自动配置功能,去除了XML配置,完全采用Java配置(注解)

        (4).SpringBoot内置自动创建很多对象,例如连接池\JdbcTemplate\DispatcherServlet等,需要使用可以直接注入应用

        (5).SpringBoot提供了一系列的工具包集合,便于开发引入

  • 基础包:spring-boot-starter-parent
    IOC包:spring-boot-starter
    MVC:spring-boot-starter-web
    DAO:spring-boot-starter-jdbc
    AOP:spring-boot-starter-aop
    mybatis: mybatis-spring-boot-starter


<2>SpringBoot基本套路

      例:用SpringBoot实现hello案例

  1. 创建maven project,在pom.xml添加boot包

    <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.4.7.RELEASE</version>
    </parent>
    <!--添加mvc包--根据层级原因,其中包含IOC包 -->
    <dependencies>
        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    
  2. 编写HelloController

    @RestController //等价于@Controller+@ResponseBody
    public class HelloController {
    
        @RequestMapping("/hello.do")
        public Map<String,Object> execute(){
            Map<String,Object> data = new HashMap<String, Object>();
            data.put("msg", "Hello Boot");
            return data;
        }
    }
    
  3. 编写启动Boot应用的类

    @SpringBootApplication
    public class BootApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(BootApplication.class, args);
        }
    }
    
  4. 修改tomcat端口号和请求项目名(application.properties)——<防止出现与tomcat的端口号一致而导致项目无法运行>

    server.port=8888
    server.context-path=/boot

  5.编写JSP页面

        

     <h1>#{msg}<h1>

        以上即为springboot的基本套路应用;






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值