Skip to content

Commit 0d30570

Browse files
committed
mongodb
1 parent 212c1f1 commit 0d30570

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+38220
-7
lines changed

core/src/main/java/info/xiaomo/core/constant/Err.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @Copyright(©) 2015 by xiaomo.
1616
*/
1717
public enum Err {
18+
SUCCESS(0, "成功"),
1819
REPEAT(992, "数据重复"),
1920
ERROR(993, "系统错误"),
2021
ADMIN_USER_REPEAT(994, "后台用户名重复"),

mongodb/pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>xiaomo</artifactId>
7+
<groupId>info.xiaomo</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>mongodb</artifactId>
13+
<dependencies>
14+
<dependency>
15+
<groupId>info.xiaomo</groupId>
16+
<artifactId>core</artifactId>
17+
<version>1.0.0-SNAPSHOT</version>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-data-mongodb</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>io.springfox</groupId>
25+
<artifactId>springfox-swagger-ui</artifactId>
26+
</dependency>
27+
</dependencies>
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-maven-plugin</artifactId>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
</project>

website/src/main/java/info/xiaomo/website/config/Swagger2Config.java renamed to mongodb/src/main/java/info/xiaomo/mongodb/MongodbMain.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
package info.xiaomo.website.config;
1+
package info.xiaomo.mongodb;
22

3+
4+
import io.swagger.annotations.ApiOperation;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
7+
import org.springframework.boot.autoconfigure.domain.EntityScan;
38
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.ComponentScan;
410
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.RequestMethod;
14+
import org.springframework.web.bind.annotation.RestController;
15+
import org.springframework.web.servlet.ModelAndView;
16+
import springfox.documentation.annotations.ApiIgnore;
517
import springfox.documentation.builders.ApiInfoBuilder;
618
import springfox.documentation.builders.PathSelectors;
719
import springfox.documentation.builders.RequestHandlerSelectors;
@@ -20,29 +32,43 @@
2032
* @github: https://github.com/qq83387856
2133
* @email: hupengbest@163.com
2234
* @QQ_NO: 83387856
23-
* @Date: 2016/11/10 10:42
24-
* @Description: 用户实体类
35+
* @Date: 2016/4/1 15:38
36+
* @Description: RabbitMq启动器
2537
* @Copyright(©) 2015 by xiaomo.
2638
**/
27-
2839
@Configuration
40+
@EnableAutoConfiguration
41+
@ComponentScan("info.xiaomo")
42+
@EntityScan("info.xiaomo.*.model")
43+
@EnableJpaRepositories("info.xiaomo.*.dao")
44+
@RestController
2945
@EnableSwagger2
30-
public class Swagger2Config {
46+
public class MongodbMain {
47+
public static void main(String[] args) throws Exception {
48+
SpringApplication.run(MongodbMain.class, args);
49+
}
50+
51+
@RequestMapping(value = "/", method = RequestMethod.GET)
52+
@ApiIgnore()
53+
@ApiOperation(value = "重定向到api首页")
54+
public ModelAndView index() {
55+
return new ModelAndView("redirect:/swagger-ui.html");
56+
}
3157

3258
@Bean
3359
public Docket createRestApi() {
3460
return new Docket(DocumentationType.SWAGGER_2)
3561
.apiInfo(apiInfo())
3662
.select()
37-
.apis(RequestHandlerSelectors.basePackage("info.xiaomo.website"))
63+
.apis(RequestHandlerSelectors.basePackage("info.xiaomo.mongodb"))
3864
.paths(PathSelectors.any())
3965
.build();
4066
}
4167

4268
private ApiInfo apiInfo() {
4369
return new ApiInfoBuilder()
4470
.title("Spring Boot中使用Swagger2构建RESTful APIs")
45-
.description("api根地址:http://api.xiaomo.info:8080/")
71+
.description("使用mongodb构建api接口")
4672
.termsOfServiceUrl("http://blog.xiaomo.info/")
4773
.contact("小莫")
4874
.version("1.0")
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package info.xiaomo.mongodb.controller;
2+
3+
import info.xiaomo.core.constant.Err;
4+
import info.xiaomo.core.controller.Result;
5+
import info.xiaomo.mongodb.model.MongoUser;
6+
import info.xiaomo.mongodb.service.MongoUserService;
7+
import io.swagger.annotations.Api;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.web.bind.annotation.*;
10+
11+
/**
12+
* 把今天最好的表现当作明天最新的起点..~
13+
* いま 最高の表現 として 明日最新の始発..~
14+
* Today the best performance as tomorrow newest starter!
15+
* Created by IntelliJ IDEA.
16+
*
17+
* @author: xiaomo
18+
* @github: https://github.com/qq83387856
19+
* @email: hupengbest@163.com
20+
* @QQ_NO: 83387856
21+
* @Date: 2016/11/15 15:49
22+
* @Copyright(©) 2015 by xiaomo.
23+
**/
24+
25+
@RestController
26+
@RequestMapping("mongodb")
27+
@Api("mongodb測試")
28+
public class MongoUserController {
29+
30+
private final MongoUserService service;
31+
32+
@Autowired
33+
public MongoUserController(MongoUserService service) {
34+
this.service = service;
35+
}
36+
37+
@RequestMapping(value = "get/{id}", method = RequestMethod.GET)
38+
public Result get(@PathVariable("id") Long id) {
39+
MongoUser mongoUser = service.findById(id);
40+
return new Result(mongoUser);
41+
}
42+
43+
@RequestMapping(value = "findAll", method = RequestMethod.GET)
44+
public Result findAll() {
45+
return new Result(service.findAll());
46+
}
47+
48+
49+
@RequestMapping(value = "add", method = RequestMethod.POST)
50+
public Result add(@RequestBody MongoUser user) {
51+
return new Result(service.add(user));
52+
}
53+
54+
@RequestMapping(value = "delete/{id}", method = RequestMethod.GET)
55+
public Result delete(@PathVariable("id") Long id) {
56+
service.delete(id);
57+
return new Result(Err.SUCCESS.getCode(), Err.SUCCESS.getMessage());
58+
}
59+
60+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package info.xiaomo.mongodb.dao;
2+
3+
import info.xiaomo.mongodb.model.MongoUser;
4+
import org.springframework.data.mongodb.repository.MongoRepository;
5+
import org.springframework.stereotype.Repository;
6+
7+
/**
8+
* 把今天最好的表现当作明天最新的起点..~
9+
* いま 最高の表現 として 明日最新の始発..~
10+
* Today the best performance as tomorrow newest starter!
11+
* Created by IntelliJ IDEA.
12+
*
13+
* @author: xiaomo
14+
* @github: https://github.com/qq83387856
15+
* @email: hupengbest@163.com
16+
* @QQ_NO: 83387856
17+
* @Date: 2016/11/15 15:42
18+
* @Description: 用户实体类
19+
* @Copyright(©) 2015 by xiaomo.
20+
**/
21+
22+
@Repository
23+
public interface MongoUserDao extends MongoRepository<MongoUser,Long>{
24+
25+
MongoUser findByUserName(String userName);
26+
27+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package info.xiaomo.mongodb.model;
2+
3+
import io.swagger.annotations.ApiModelProperty;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import lombok.ToString;
8+
import org.springframework.data.annotation.Id;
9+
10+
import javax.persistence.Column;
11+
12+
/**
13+
* 把今天最好的表现当作明天最新的起点..~
14+
* いま 最高の表現 として 明日最新の始発..~
15+
* Today the best performance as tomorrow newest starter!
16+
* Created by IntelliJ IDEA.
17+
*
18+
* @author: xiaomo
19+
* @github: https://github.com/qq83387856
20+
* @email: hupengbest@163.com
21+
* @QQ_NO: 83387856
22+
* @Date: 2016/11/15 15:39
23+
* @Description: 用户实体类
24+
* @Copyright(©) 2015 by xiaomo.
25+
**/
26+
27+
@Data
28+
@ToString(callSuper = false)
29+
@NoArgsConstructor
30+
@AllArgsConstructor
31+
public class MongoUser {
32+
33+
@Id
34+
private int id;
35+
36+
@ApiModelProperty(value = "登录用户")
37+
private String email;
38+
39+
@ApiModelProperty(value = "昵称")
40+
private String userName;
41+
42+
@ApiModelProperty(value = "密码")
43+
private String password;
44+
45+
@ApiModelProperty(value = "盐值")
46+
private String salt;
47+
48+
@ApiModelProperty(value = "激活码")
49+
@Column(name = "ValidateCode")
50+
private String validateCode;
51+
52+
@ApiModelProperty(value = "性别:1男2女0保密")
53+
private int gender = 0;
54+
55+
@ApiModelProperty(value = "电话")
56+
private Long phone = 0L;
57+
58+
@ApiModelProperty(value = "图片地址")
59+
private String imgUrl = "";
60+
61+
@ApiModelProperty(value = "地址")
62+
private String address = "";
63+
64+
@ApiModelProperty(value = "注册时间(时间戳)")
65+
private Long RegisterTime = 0L;
66+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package info.xiaomo.mongodb.service;
2+
3+
import info.xiaomo.mongodb.model.MongoUser;
4+
5+
import java.util.List;
6+
7+
/**
8+
* 把今天最好的表现当作明天最新的起点..~
9+
* いま 最高の表現 として 明日最新の始発..~
10+
* Today the best performance as tomorrow newest starter!
11+
* Created by IntelliJ IDEA.
12+
*
13+
* @author: xiaomo
14+
* @github: https://github.com/qq83387856
15+
* @email: hupengbest@163.com
16+
* @QQ_NO: 83387856
17+
* @Date: 2016/11/15 15:45
18+
* @Copyright(©) 2015 by xiaomo.
19+
**/
20+
21+
22+
public interface MongoUserService {
23+
24+
List<MongoUser> findAll();
25+
26+
MongoUser findById(Long id);
27+
28+
MongoUser findByName(String userName);
29+
30+
MongoUser add(MongoUser mongoUser);
31+
32+
void delete(Long id);
33+
34+
MongoUser update(MongoUser mongoUser);
35+
36+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package info.xiaomo.mongodb.service.impl;
2+
3+
import info.xiaomo.mongodb.dao.MongoUserDao;
4+
import info.xiaomo.mongodb.model.MongoUser;
5+
import info.xiaomo.mongodb.service.MongoUserService;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.stereotype.Service;
8+
9+
import java.util.List;
10+
11+
/**
12+
* 把今天最好的表现当作明天最新的起点..~
13+
* いま 最高の表現 として 明日最新の始発..~
14+
* Today the best performance as tomorrow newest starter!
15+
* Created by IntelliJ IDEA.
16+
*
17+
* @author: xiaomo
18+
* @github: https://github.com/qq83387856
19+
* @email: hupengbest@163.com
20+
* @QQ_NO: 83387856
21+
* @Date: 2016/11/15 15:45
22+
* @Copyright(©) 2015 by xiaomo.
23+
**/
24+
25+
@Service
26+
public class MongoUserServiceImpl implements MongoUserService {
27+
private final MongoUserDao dao;
28+
29+
@Autowired
30+
public MongoUserServiceImpl(MongoUserDao dao) {
31+
this.dao = dao;
32+
}
33+
34+
@Override
35+
public List<MongoUser> findAll() {
36+
return dao.findAll();
37+
}
38+
39+
@Override
40+
public MongoUser findById(Long id) {
41+
return dao.findOne(id);
42+
}
43+
44+
@Override
45+
public MongoUser findByName(String userName) {
46+
return dao.findByUserName(userName);
47+
}
48+
49+
@Override
50+
public MongoUser add(MongoUser mongoUser) {
51+
return dao.save(mongoUser);
52+
}
53+
54+
@Override
55+
public void delete(Long id) {
56+
dao.delete(id);
57+
}
58+
59+
@Override
60+
public MongoUser update(MongoUser mongoUser) {
61+
return dao.save(mongoUser);
62+
}
63+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
logging.config=classpath:config/logback-dev.xml
2+
server.port=8080
3+
server.session.timeout=1800
4+
server.max-http-header-size=20971520
5+
6+
#datasource
7+
#datasource
8+
spring.datasource.url=jdbc:mysql://115.29.137.34/xiaomo
9+
# ?useUnicode=true&amp;characterEncoding=UTF-8
10+
spring.datasource.username=xiaomo
11+
spring.datasource.password=123456
12+
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
13+
14+
#mongodb
15+
spring.data.mongodb.uri=mongodb://xiaomo:xiaomo@115.29.137.34:27017/admin
16+
17+
# \u914D\u7F6E\u8FD9\u4E2A\u503C\u5C31\u53EF\u4EE5\u683C\u5F0F\u5316\u65F6\u95F4
18+
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
19+
spring.jackson.time-zone=GMT+8

0 commit comments

Comments
 (0)