mirror of https://gitee.com/stylefeng/roses
mongodb基本接口封装
parent
215ea52f8b
commit
9f0df66419
|
@ -0,0 +1,19 @@
|
|||
<?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">
|
||||
<parent>
|
||||
<artifactId>kernel-d-mongodb</artifactId>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<version>7.0.2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mongodb-api</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,46 @@
|
|||
package cn.stylefeng.roses.kernel.mongodb.api;
|
||||
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author huziyang
|
||||
* @create 2021-03-20 16:24
|
||||
*/
|
||||
public interface MongodbApi<T,ID> {
|
||||
|
||||
/**
|
||||
* 新增操作
|
||||
* @param gunsMapEntity
|
||||
* @return
|
||||
*/
|
||||
T insert(T gunsMapEntity);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param gunsMapEntity
|
||||
* @return
|
||||
*/
|
||||
T update(T gunsMapEntity);
|
||||
|
||||
/**
|
||||
* 根据id删除
|
||||
* @param id
|
||||
*/
|
||||
void deleteById(ID id);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Optional<T> findById(ID id);
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
* @return
|
||||
*/
|
||||
List<T> findAll();
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.stylefeng.roses.kernel.mongodb.api.constants;
|
||||
|
||||
/**
|
||||
* @author huziyang
|
||||
* @create 2021-03-20 16:24
|
||||
*/
|
||||
public interface MongodbConstants {
|
||||
|
||||
|
||||
/**
|
||||
* mongodb模块的名称
|
||||
*/
|
||||
String MONGODB_MODULE_NAME = "kernel-d-mongodb";
|
||||
|
||||
/**
|
||||
* 异常枚举的步进值
|
||||
*/
|
||||
String MONGODB_EXCEPTION_STEP_CODE = "70";
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.stylefeng.roses.kernel.mongodb.api.exception;
|
||||
|
||||
import cn.stylefeng.roses.kernel.mongodb.api.constants.MongodbConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
|
||||
/**
|
||||
* 系统配置表的异常
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/13/17 23:59
|
||||
*/
|
||||
public class MongodbException extends ServiceException {
|
||||
|
||||
public MongodbException(AbstractExceptionEnum exception) {
|
||||
super(MongodbConstants.MONGODB_MODULE_NAME, exception);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?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">
|
||||
<parent>
|
||||
<artifactId>kernel-d-mongodb</artifactId>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<version>7.0.2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mongodb-sdk-springboot</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--MongoDB模块的api-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>mongodb-api</artifactId>
|
||||
<version>7.0.2</version>
|
||||
</dependency>
|
||||
|
||||
<!--SpringBoot 与 MongoDB 整合-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,27 @@
|
|||
package cn.stylefeng.roses.kernel.mongodb.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author huziyang
|
||||
* @create 2021-03-20 16:24
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Document(collection = "guns_map")
|
||||
public class GunsMapEntity {
|
||||
|
||||
@Id
|
||||
private String _id;
|
||||
|
||||
private Map<String,Object> data = new HashMap<>();
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package cn.stylefeng.roses.kernel.mongodb.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.mongodb.entity.GunsMapEntity;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
/**
|
||||
* @author huziyang
|
||||
* @create 2021-03-20 16:24
|
||||
*/
|
||||
@Configuration
|
||||
public interface GunsMapRepository extends MongoRepository<GunsMapEntity,String> {
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package cn.stylefeng.roses.kernel.mongodb.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.mongodb.entity.GunsMapEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author huziyang
|
||||
* @create 2021-03-20 16:24
|
||||
*/
|
||||
public interface GunsMapService {
|
||||
|
||||
/**
|
||||
* 新增操作
|
||||
* @param gunsMapEntity
|
||||
* @return
|
||||
*/
|
||||
GunsMapEntity insert(GunsMapEntity gunsMapEntity);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param gunsMapEntity
|
||||
* @return
|
||||
*/
|
||||
GunsMapEntity update(GunsMapEntity gunsMapEntity);
|
||||
|
||||
/**
|
||||
* 根据id删除
|
||||
* @param id
|
||||
*/
|
||||
void deleteById(String id);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Optional<GunsMapEntity> findById(String id);
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
* @return
|
||||
*/
|
||||
List<GunsMapEntity> findAll();
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package cn.stylefeng.roses.kernel.mongodb.service.impl;
|
||||
|
||||
import cn.stylefeng.roses.kernel.mongodb.api.MongodbApi;
|
||||
import cn.stylefeng.roses.kernel.mongodb.entity.GunsMapEntity;
|
||||
import cn.stylefeng.roses.kernel.mongodb.mapper.GunsMapRepository;
|
||||
import cn.stylefeng.roses.kernel.mongodb.service.GunsMapService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author huziyang
|
||||
* @create 2021-03-20 16:24
|
||||
*/
|
||||
@Service
|
||||
public class GunsMapServiceImpl implements GunsMapService, MongodbApi<GunsMapEntity,String> {
|
||||
|
||||
|
||||
@Resource
|
||||
private GunsMapRepository gunsMapRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public GunsMapEntity insert(GunsMapEntity gunsMapEntity){
|
||||
return gunsMapRepository.insert(gunsMapEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GunsMapEntity update(GunsMapEntity gunsMapEntity){
|
||||
return gunsMapRepository.save(gunsMapEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(String id){
|
||||
gunsMapRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GunsMapEntity> findById(String id){
|
||||
return gunsMapRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GunsMapEntity> findAll(){
|
||||
return gunsMapRepository.findAll();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?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">
|
||||
<parent>
|
||||
<artifactId>kernel-d-mongodb</artifactId>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<version>7.0.2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mongodb-spring-boot-starter</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--MongoDB模块的sdk-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>mongodb-sdk-springboot</artifactId>
|
||||
<version>7.0.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,23 @@
|
|||
package cn.stylefeng.roses.kernel.mongodb.starter;
|
||||
|
||||
import cn.stylefeng.roses.kernel.mongodb.api.MongodbApi;
|
||||
import cn.stylefeng.roses.kernel.mongodb.service.impl.GunsMapServiceImpl;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author huziyang
|
||||
* @create 2021-03-20 16:24
|
||||
*/
|
||||
@Configuration
|
||||
public class GunsMongodbAutoConfiguration {
|
||||
|
||||
|
||||
@Bean
|
||||
public MongodbApi mongodbApi() {
|
||||
return new GunsMapServiceImpl();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.stylefeng.roses.kernel.mongodb.starter.GunsMongodbAutoConfiguration
|
|
@ -0,0 +1,36 @@
|
|||
<?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">
|
||||
<parent>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<version>7.0.2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>kernel-d-mongodb</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>mongodb-api</module>
|
||||
<module>mongodb-sdk-springboot</module>
|
||||
<module>mongodb-spring-boot-starter</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 开发规则 -->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-a-rule</artifactId>
|
||||
<version>7.0.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue