使用NoSQL数据库(二):MongoDB
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.didispace;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.didispace.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
/**
|
||||
* @author 程序猿DD
|
||||
* @version 1.0.0
|
||||
* @date 16/4/27 下午10:04.
|
||||
* @blog http://blog.didispace.com
|
||||
*/
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String username;
|
||||
private Integer age;
|
||||
|
||||
public User(Long id, String username, Integer age) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.didispace.domain;
|
||||
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
/**
|
||||
* @author 程序猿DD
|
||||
* @version 1.0.0
|
||||
* @date 16/4/27 下午10:16.
|
||||
* @blog http://blog.didispace.com
|
||||
*/
|
||||
public interface UserRepository extends MongoRepository<User, Long> {
|
||||
|
||||
User findByUsername(String username);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
spring.data.mongodb.uri=mongodb://name:pass@localhost:27017/test
|
||||
|
||||
|
||||
Reference in New Issue
Block a user