Spring Boot学习(一)
来源:互联网 发布:地下交通站知乎 编辑:程序博客网 时间:2024/05/16 16:10
<?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.imooc</groupId> <artifactId>girl</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>girl</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.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>
package com.imooc.girl;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Component;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;@Entitypublic class Girl { @Id @GeneratedValue private Integer id; private String cupSize; private Integer age; 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; }// public Girl() {// }}package com.imooc.girl;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.*;import java.util.List;@RestControllerpublic class GirlController { @Autowired private GirlRepository girlRepository; @RequestMapping("/findAll" ) public List<Girl> findAll(){ return girlRepository.findAll(); } @PostMapping("/add") public Girl add(@RequestParam("cupSize")String cupSize,@RequestParam("age")Integer age){ Girl girl=new Girl(); girl.setCupSize(cupSize); girl.setAge(age); return girlRepository.save(girl); } @GetMapping("/query/{id}") public Girl query(@PathVariable("id") Integer id){ return girlRepository.findOne(id); } @PutMapping("/update/{id}/{cupSize}/{age}") public Girl update(@PathVariable("id") Integer id,@PathVariable("cupSize")String cupSize, @PathVariable("age")Integer age){ Girl girl = new Girl(); girl.setId(id); girl.setAge(age); girl.setCupSize(cupSize); return girlRepository.save(girl); } @DeleteMapping("/update/{id}") public void delete(@PathVariable("id") Integer id){ girlRepository.delete(id); }}
application.yml配置
spring: profiles: active: dev datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://192.168.1.178:3306/girl password: root username: root jpa: hibernate: ddl-auto: update show-sql: trueapplication-dev.ymlserver: port: 8080
阅读全文
0 0
- Spring Boot 学习(一)
- Spring Boot学习(一)
- Spring Boot学习一
- Spring Boot学习(一)
- Spring Boot学习(一)
- Spring Boot学习(一)
- Spring Boot学习(一)
- Spring Boot学习(一)
- spring boot 学习(一)
- Spring Boot学习(一)
- Spring Boot 学习笔记(一)
- spring boot零基础学习 spring boot简介(一)
- spring boot 学习一之基础构建
- Spring-Boot学习笔记一:Hello World
- Spring Boot学习记录(一)--环境搭建
- Spring Boot 学习一、搭建初步环境
- spring boot 学习笔记(一)
- 学习笔记一:Spring Boot快速入门
- hdu-5926
- Linux的system()和popen()差异
- JEESZ RestFul服务介绍
- hdu4781构造法
- Java中ArrayList和LinkedList区别
- Spring Boot学习(一)
- SpringMvc面试题
- 解决Connection to https://dl-ssl.google.com refused
- stm32定时器的各项参数解释
- JavaSE 常用类 之 String Part1
- jsp或者html导入jquery文件问题(1)
- Spring五个事务隔离级别和七个事务传播行为
- 用hibernate+struts2+easyUI进行增删查改
- 使用UGUI实现数字变化,可以在前后加图片