zoukankan      html  css  js  c++  java
  • SpringBoot学习笔记<一>入门与基本配置

    毕业实习项目技术学习笔记

    参考文献

      学习视频

        2小时学会Spring Boot:https://www.imooc.com/learn/767

      学习资料

       SpringBoot入门:https://blog.csdn.net/Phapha1996/article/details/78515865

         【推荐】Spring boot <一>入门篇:https://www.cnblogs.com/ityouknow/p/5662753.html

        Spring Boot中文官方文档:https://www.breakyizhan.com/springboot/3028.html

        SpringBoot—访问关系型数据库—SpringData JPA:https://blog.csdn.net/phapha1996/article/details/78712597

         【推荐】Spring Boot 参考指南(翻译中):

          http://oopsguy.com/documents/springboot-docs/1.5.4/index.html#boot-features-spring-mvc

        【推荐】Spring Boot + Jpa(Hibernate) 架构基本配置:

          https://blog.csdn.net/javahighness/article/details/53055149
    属性配置
      spring.datasource.url:jdbc:mysql://127.0.0.1:3306
      spring.datasource.username:root
      spring.datasource.password:123456
      spring.datasource.driver-class-name:com.mysql.jdbc
    配置文件

      目录:(src/main/resources)
      application.properties:(src/main/resources)
      server.port:8081
      server.context-path:/projectname
      

      application.yml:

    server:
      port: 8080
      context-path: /demo
      tomcat:
        uri-encoding: UTF-8
    
    spring:
      datasource:
        url : jdbc:mysql://xxxx:3306/xxxxx
        username : xxxx
        password : xxxxx
        driverClassName : com.mysql.jdbc.Driver
      jpa:
        database : MYSQL
        show-sql : true
        hibernate:
          ddl-auto : update
          naming-strategy : org.hibernate.cfg.ImprovedNamingStrategy
        properties:
          hibernate:
            dialect : org.hibernate.dialect.MySQL5Dialect
    

      


    注解
    @Controller //处理http请求,默认返回resources/templates下的html模板(view),返回参数为String类型。
    @RequestMapping("/users")
    public class XX{
    }

    @RestConroller //Spring4之后新加的注解,原来返回json需要@ResponseBody配合@Controller
    public class XXX{
      @Autowired
      private GirlProperties girlProperties;
    }

    @Value("${cupSize}")
    private String cupSize;

    @RequestMapping(value="/user/", method=RequestMethod.GET) //配置URL映射
    public String say(){
      return cupSize;
    }

    @Component
    @ConfigurationProperties(prefix="girl")
    public class GirlProperties{
      private String cupSize;
      public String getCupSize(){
        return cupSize;
      }
    }


    Controller的使用
    @PathVariable:获取url中的数据
    @RequestParam:获取请求参数的值,属性有value,required,defaultValue
    @GetMapping:组合注解Get
    @PostMapping:组合注解Post
    ===========================================
    【数据库】
    Spring-Data-Jpa
    JPA:Java Persistence API,定义了一系列对象持久化的标准,实现规范的产品有:Hibernate、TopLink等
    @Entity
    public class Girl{
      @Id
      @GenerateValue //自增
      private Integer id;
      private String cupSize;
      //setter or getter methods
    }
    @Transactional //添加事务

    Spring Boot 参考指南(翻译中)

  • 相关阅读:
    为什么这年头蓝牙功能越来越差
    猜数字-暴力枚举
    怎么使用PHPMailer实现邮件的发送??
    实现windows操作系统和VB下Linux虚拟操作系统相互传取文件方式总结
    第一篇 对Javascript中原型的深入理解
    每天进步一点点——关于SSD写入放大问题
    两步改动CentOS主机名称
    [CentOs7]搭建ftp服务器
    Another app is currently holding the yum lock
    [CentOs7]安装mysql(2)
  • 原文地址:https://www.cnblogs.com/johnnyzen/p/9696358.html
Copyright © 2011-2022 走看看