提交 2108daae 编写于 作者: Y Yiming

Add m2 database dependency

上级 0138e78f
......@@ -24,5 +24,19 @@
<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>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
spring.datasource.url = jdbc:h2:file:~/fxapolloconfigdb
spring.datasource.username = sa
spring.datasource.password = sa
......@@ -24,5 +24,18 @@
<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>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
package com.ctrip.apollo.portal.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.apollo.portal.entities.App;
import com.ctrip.apollo.portal.repository.AppRepository;
@RestController
@RequestMapping("/apps")
public class AppController {
@Autowired
private AppRepository appRepository;
@RequestMapping("")
public Page<App> list() {
Pageable pageable = new PageRequest(0, 10);
return appRepository.findAll(pageable);
}
@RequestMapping(value = "", method = RequestMethod.POST)
public App create() {
App ramdomApp = new App();
return appRepository.save(ramdomApp);
}
}
......@@ -4,9 +4,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/")
public class SampleController {
@RequestMapping("/")
@RequestMapping("")
public String home() {
return "Hello World!";
}
......
package com.ctrip.apollo.portal.entities;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import lombok.Data;
@Entity
@Data
public class App implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7348554309210401557L;
@Id
private String id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String owner;
@Column
private String ownerPhone;
@Column
private String ownerMail;
@Column
private Date createTimestamp;
@Column
private Date lastUpdatedTimestamp;
}
package com.ctrip.apollo.portal.repository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.CrudRepository;
import com.ctrip.apollo.portal.entities.App;
public interface AppRepository extends CrudRepository<App, String> {
Page<App> findAll(Pageable pageable);
}
spring.datasource.url = jdbc:h2:file:~/fxapolloportaldb
spring.datasource.username = sa
spring.datasource.password = sa
spring.datasource.driver-class-name = org.h2.Driver
spring.datasource.url = jdbc:h2:file:~/fxapolloportaldb
spring.datasource.username = sa
spring.datasource.password = sa
spring.h2.console.enabled = true
\ No newline at end of file
......@@ -57,7 +57,6 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.191</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
......@@ -65,12 +64,22 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.source}</source>
<target>${java.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册