慕课网2小时学会Spring Boot第一讲笔记

在启动类中启动项目需用@SpringBootApplication这个注解

第二种启动项目的方式:找到项目存放路径下,使用命令mvn spring-boot:run

第三种启动方式:(1)mvn install (2)cd target (3)java -jar xxx.jar

SpringBoot项目不用配置tomcat、xml等等等等,直接通过方法启动项目,可以配置项目的一些属性:开发环境、生产环境

1、Springboot访问路径:server.servlet.context-path=/girl为这个
    Spring boot默认是/,这样直接通过http://ip:port/就可以访问到index页面
    如果要修改为http://ip:port/path/访问的话,那么需要在Application.properties文件中加入
    server.context-path= /你的path
    比如:spring-boot,那么访问地址就是http://ip:port/spring-boot路径。

2、SpringBoot Application配置:.yml格式文件
    server:
          port: 8082
          servlet:
                path: /girl

3、
    通过注解把.yml文件的值注入到属性中
            @Value("${cupSize}")
            private String cupSize;
    通过注解把.yml文件的值注入到类中
        @ConfigurationProperties(prefix = "girl")

4、解决开发环境、生产环境的不同的配置问题
    创建多个 Application-*.yml文件
    Spring:
      profiles:
           active: * //改变环境

    多种启动方式、启动不同环境

5、Controller的使用
     @pathVariable 获取url中数据           
        @RequestMapping(value = {"/{id}/hello"}, method = RequestMethod.GET)
            public String say(@PathVariable("id") Integer id)
     @RequestParam 获取请求参数的值
        @RequestParam(value="",required=false,defaultValue=0)
    @GetMapping   组合注解
        代替@RequestMapping的get请求

6、Spring-Data-Jpa
    JPA(Java Persistence API)定义一系列对象持久化的标准
    目前实行这一规范的产品有Hibernate、TopLink


     datasource:
            driver-class-name: com.mysql.jdbc.Driver
            url: jdbc:mysql://127.0.0.1:3306/dbgirl
            username: root
            password: 123
       jqa:
            hibernate:
                ddl-auto: create
          show-sql: true

    /*
      这个类代表数据库一张表
     */
    @Entity

7、Jpa的使用
    //接口继承JpaRepository
    public interface GirlRepository extends JpaRepository<Girl,Integer>{

        //通过年龄来查询
        public List<Girl> findByAge(Integer age);

    }
    
    //使用
    girlRepository.save(girl);
    girlRepositoryfindByAge(age);


8、
    /**
     * 事务管理
     */
    @Transactional














 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值