美文网首页
Mongodb MongoRepository操作mongo

Mongodb MongoRepository操作mongo

作者: 雪夜的星 | 来源:发表于2017-06-25 09:56 被阅读0次

    1、实体类

    public classRuleModel implements Serializable{

           @Id

           Stringid;//序号

          StringruleName;//规则名称

          StringuserGroupName;//用户群组name

          StringuserGroupCode;//用户群组code

         get,set方法略

    }


    2、继承MongoRepository

    @Repository

    public interface RuleModelRepository extends MongoRepository{

    }


    3、实现服务接口

    @Service

    public class RuleManagerServiceImpl implements RuleManagerService {

    private staticLoggerlogger= LoggerFactory.getLogger(RuleManagerServiceImpl.class);

    @Autowired

    private RuleModelRepository ruleModelRepository;

    @Override

    publicOpResult add(AddRulesVO addRulesVO) {

          RuleModel ruleModel = ObjectConvertor.toAnotherObj(addRulesVO,RuleModel.class);

          try{

               ruleModelRepository.insert(ruleModel);

               logger.info("插入规则成功"+ruleModel);

               returnOpResult.createSucResult("success");

           }catch(Exception e) {

              logger.error("[EXCEPTION]"+e.getMessage());

         }

        return OpResult.createFailResult(ErrorCodeEnum.ADD_RULE_EXCEPTION);

    }

    }

    相关文章

      网友评论

          本文标题:Mongodb MongoRepository操作mongo

          本文链接:https://www.haomeiwen.com/subject/qsblcxtx.html