Commit 2108daae by Yiming

Add m2 database dependency

parent 0138e78f
...@@ -24,5 +24,19 @@ ...@@ -24,5 +24,19 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </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> </dependencies>
</project> </project>
spring.datasource.url = jdbc:h2:file:~/fxapolloconfigdb
spring.datasource.username = sa
spring.datasource.password = sa
...@@ -24,5 +24,18 @@ ...@@ -24,5 +24,18 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </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> </dependencies>
</project> </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; ...@@ -4,9 +4,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/")
public class SampleController { public class SampleController {
@RequestMapping("/") @RequestMapping("")
public String home() { public String home() {
return "Hello World!"; 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 @@ ...@@ -57,7 +57,6 @@
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<version>1.4.191</version> <version>1.4.191</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
...@@ -65,13 +64,23 @@ ...@@ -65,13 +64,23 @@
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration> <configuration>
<source>${java.source}</source> <source>${java.source}</source>
<target>${java.target}</target> <target>${java.target}</target>
</configuration> </configuration>
</plugin> </plugin>
<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> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.3.RELEASE</version> <version>1.3.3.RELEASE</version>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment