文章会有【原创】或者【转载】标示,部分来自Google Baidu的学习结果 {Java/PHP/Python/Ruby/Go}

Java 在学习四十八【原创】  


Spring Framework

1IOC (配置、注解) 轻量级的控制反转

2Bean (配置、注解)

3AOP (配置、注解、AspectjAPI) 面向切面的容器框架


其他:

Spring Expression Language(SPEL)

Spring Integration

Spring Web Flow

Spring Security

Spring Data

Spring Batch


http://www.imooc.com/learn/196

博客:http://www.cnblogs.com/leiOOlei/p/3543222.html


Spring Boot

1):Spring MVC Spring Boot

2):Spring Boot 配置简单、微服务架构【Spring Cloud


运行的三种方式:

1. 直接运行在eclipse Application Run

2. mvn spring-boot:run

3. mvn install; java -jar target/xxx.jar


项目配置文件:

application.yml || yaml

server:

  port: 8098

cupSize: B

age: 18

content: "cupSize: ${cupSize}, age: ${age}"


java -jar xxx.jar —spring.profiles.active=prod


@Controller 处理Http请求 必须配合模板使用

@RestController 需要和@ResponseBody配合@Controller使用

@RequestMapping 配置URL映射


@PathVariable 获取url中的数据

@RequestParam 获取请求参数的值

@GetMapping 组合注解


Spring-Data-Jpa —> MySQL 定义了一系列对象持久化的标准,目前实现这个规范的有 Hibernate…



配置文件:

spring:

  profiles:

    active: dev


app-dev.yml

server:

  port: 8097

girl:

  cupSize: B

  age: 18

spring:

  datasource:

    driver-class-name: com.mysql.jdbc.Driver

    url: jdbc:mysql://localhost:3306/test?characterEncoding=utf8&useSSL=true

    username: root

    password: 123456

  jpa:

    hibernate:

      ddl-auto: none

    show-sql: true

    

 

package com.example.demo;


import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;


@Entity

public class Girl {


@Id

@GeneratedValue // 自增

private Integer id;

private String cupSize;

private Integer age;


public Girl() {

}


public Integer getId() {

return id;

}


public void setId(Integer id) {

this.id = id;

}


public String getCupSize() {

return cupSize;

}


public void setCupSize(String cupSize) {

this.cupSize = cupSize;

}


public Integer getAge() {

return age;

}


public void setAge(Integer age) {

this.age = age;

}

}


package com.example.demo;


import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.DeleteMapping;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.PutMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.RestController;


@RestController

public class GirlController {

@Autowired

private GirlRepository girlRepository;

/*

*  查询列表 返回JSON

*/

@GetMapping(value = "/girls")

public List<Girl> girlList() {

return girlRepository.findAll();

}

/*

* 新增一个

*/

@PostMapping(value = "/girls")

public Girl girlAdd(@RequestParam("cupSize") String cupSize, @RequestParam("age") Integer age) {

Girl girl = new Girl();

girl.setCupSize(cupSize);

girl.setAge(age);

return girlRepository.save(girl);

}

/*

*  查询一个女生

*/

@GetMapping(value = "/girls/{id}")

public Girl girlFindOne(@PathVariable("id") Integer id) {

return girlRepository.findOne(id);

}

/*

*  更新一个女生

*/

@PutMapping(value = "/girls/{id}")

public Girl girlUpdate(@PathVariable("id") Integer id, @RequestParam("cupSize") String cupSize, @RequestParam("age") Integer age) {

Girl girl = new Girl();

girl.setId(id);

girl.setCupSize(cupSize);

girl.setAge(age);

return girlRepository.save(girl);

}

/*

*  更新一个女生

*/

@DeleteMapping(value = "/girls/{id}")

public void girlDelete(@PathVariable("id") Integer id) {

girlRepository.delete(id);

}

/*

*  查询一个女生

*/

@GetMapping(value = "/girls/age/{age}")

public List<Girl> girlFindAge(@PathVariable("age") Integer age) {

return girlRepository.findByAge(age);

}

}





package com.example.demo;


import java.util.List;


import org.springframework.data.jpa.repository.JpaRepository;


public interface GirlRepository extends JpaRepository<Girl, Integer> {


// 通过年龄来查询

public List<Girl> findByAge(Integer age); 

}