package com.springbootdemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args)
{
SpringApplication.run(DemoApplication.class, args);
}
}
package com.springbootdemo.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* Created by Administrator on 2017/6/29.
*/
@Entity
public class GirlInf {
@Id
@GeneratedValue
private Integer id;
private String name;
private Integer age;
private String cupSize;
public GirlInf() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getCupSize() {
return cupSize;
}
public void setCupSize(String cupSize) {
this.cupSize = cupSize;
}
}
package com.springbootdemo.service;
import com.springbootdemo.entity.GirlInf;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* Created by Administrator on 2017/6/30.
*/
public interface GirlRepository extends JpaRepository<GirlInf, Integer> {
}
package com.springbootdemo.controller;
import com.springbootdemo.entity.GirlInf;
import com.springbootdemo.service.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Created by Administrator on 2017/6/29.
*/
@RestController
@RequestMapping("/hello")
public class helloController {
@Autowired
GirlRepository girlRepository;
@GetMapping("/showGirls")
public List<GirlInf> showGirls() {
List<GirlInf> list = girlRepository.findAll();
return list;
}
@PostMapping("/addGirl")
public void AddGirl(@RequestParam Integer id, String name, Integer age, String cupSize) {
GirlInf girlInf = new GirlInf();
girlInf.setName(name);
girlInf.setAge(age);
girlInf.setCupSize(cupSize);
if (id != null) {
girlInf.setId(id);
girlRepository.save(girlInf);
} else {
girlRepository.save(girlInf);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.springbootdemo</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
server:
port: 8081
address: 127.0.0.1
spring.datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/bootdemo
username: root
spring.data.jpa:
hibernate:
ddl-auto: create
show-sql: true