码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot

时间:2018-05-11 20:44:44      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:public   规范   类型   程序   reader   ble   round   必须   ack   

Spring Boot

特性

         Spring Boot四大核心:    (每个特性都是为了简化Spring)

  1. 自动配置:        
  2. 起步依赖:        
  3. 命令行界面:
  4. Actuator  

简而言之,Spring Boot就是Spring,他做了那些没有他也会去写的Spring Bean配置.

 

项目目录

  1. Build.gradle||pom.xml
    Gradle构建说明文件   若是使用Maven则为pom.xml(Project object model)
  2. Src/main/java/xxxxApplication.java
    程序的启动引导类 主要的Spring配置类    @SpringBootApplication(开启组件扫描和自动配置) @SpringBootApplication=(@Configuration + @CompanentScan + @EnableAutoConfiguration)
  3. Src/main/resources/application.properties
    配置应用程序和Spring Boot的属性
  4. Application与其他层的包属于同一级别
    技术分享图片

     

 

 

 

步骤

  1. 定义领域模型(定义实体 @Entity)
  2. 定义仓库接口,实现(@Repository,继承了Jpa的接口不需要使用标注?)
  3. 定义业务接口,实现(@Service)
  4. Web前端(@Controller)

 

 

@Entity

@Repository

  1. JpaRepository有两个参数:仓库操作的领域类型(Entity),与Id的类型

public interface Test extends JpaRepository<Entity,Long>(){

List<Entity> findById(Long id);

}

 

@Service

@Controller

  1. @Controller 返回视图名,在templates中寻找html

@ControllerRest返回json

 

  1. @Controller

(@Autowired Repository)

@RequestMapping(value = “/{test}” , method = RequestMethod.GET)

public String func(@PathVariable(“test”) String test , Model model){

                   //@PathVariable      使用Mapping中{}中的值并给参数赋值

         List<Entity> list = repository,findById(test);

         model.addAttribute(“test”,list);

                  //将list装入模型,键为test

         return “testView”;

                   //返回的testView为视图的逻辑名称,即在templates中找html

}

 

 

 

配置

application.properties  或者 创建 application.yml

properties

         spring.datasource.first.username = xxxx

 

yml规范

         spring:

                   datasource:

                            first:

                                     username:

                                     url:

添加依赖

maven xxxx   然后写入pom         <dependcy>

 

配置数据源

 技术分享图片

 

配置错误页

         查找error的视图,找不到就用”白标”代替,(自定义error.html)

 

测试

Grails

GORM

Grails object Relational Mapping   Grails对象关系映射

 

import grails.persistence.*

 

@Entity

Class Book{

         Reader reader

         String isbn

         String title

}

         没有分号,没有修饰符,setter\getter方法,

Grails的@Entity注解使该类变为GORM实体

         GORM要求实体类必须为Groovy来写

spring boot

标签:public   规范   类型   程序   reader   ble   round   必须   ack   

原文地址:https://www.cnblogs.com/cyx-garen/p/9025949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!