package cn.hongsong.controller;
import cn.hongsong.model.Question;
import cn.hongsong.service.mongo.IQuestionMdao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.regex.Pattern;
/**
* Created by jz on 2018/1/9.
* 参考 : http://ask.csdn.net/questions/382007?sort=id
*/
//@Controller
//@EnableAutoConfiguration
//@ComponentScan(basePackages="cn.hongsong")
@RestController
@RequestMapping("/mongoSolve")
public class MongoSolveController {
@Autowired
private IQuestionMdao questionMdao;
@RequestMapping(value = "/initMdbConllectionName", method = {RequestMethod.POST, RequestMethod.GET})
public String initMdbConllectionName(){
String collectionDbName = questionMdao.initMdbConllectionName();
return collectionDbName;
}
@RequestMapping(value = "/saveObject", method = {RequestMethod.POST, RequestMethod.GET})
public void saveObject(@RequestParam(value = "",required = false) String json){
Question question = new Question();
question.setQuestionId("101213");
question.setQuestionName("what is springboot ?");
question.setTimeMillis(System.currentTimeMillis());
String collectionDbName = questionMdao.initMdbConllectionName();
questionMdao.save(question,collectionDbName);
}
@RequestMapping(value = "/saveObjectList", method = {RequestMethod.POST, RequestMethod.GET})
public void saveObjectList(@RequestParam(value = "",required = false) String json){
List<Question> questions = new ArrayList<Question>();
Question question = new Question();
question.setQuestionId("101214");
question.setQuestionName("what is ComponentScan ?");
question.setTimeMillis(System.currentTimeMillis());
questions.add(question);
question = new Question();
question.setQuestionId("101215");
question.setQuestionName("what is SpringBootApplication ?");
question.setTimeMillis(System.currentTimeMillis());
questions.add(question);
String collectionDbName = questionMdao.initMdbConllectionName();
questionMdao.saveAll(questions,collectionDbName);
}
@RequestMapping(value = "/searchByParams", method = {RequestMethod.POST, RequestMethod.GET})
public Object searchByParams(@RequestParam(value = "",required = false) String json){
Map<String, Object> gtMap = new HashMap<String, Object>();
Map<String, Object> ltMap = new HashMap<String, Object>();
Map<String, Object> eqMap = new HashMap<String, Object>();
Map<String, Object> gteMap = new HashMap<String, Object>();
Map<String, Object> lteMap = new HashMap<String, Object>();
Map<String, String> regexMap = new HashMap<String, String>();
Map<String, Collection> inMap = new HashMap<String, Collection>();
Map<String, Object> neMap = new HashMap<String, Object>();
Criteria c = questionMdao.createCriteria(gtMap,ltMap,eqMap,gteMap,lteMap,regexMap,inMap,neMap);
List<Question> questions = questionMdao.searchByParams(c,questionMdao.initMdbConllectionName());
return questions;
}
@RequestMapping(value = "/searchByParams1", method = {RequestMethod.POST, RequestMethod.GET})
public Object searchByParams1(@RequestParam(value = "",required = false) String json){
Map<String, Object> gtMap = new HashMap<String, Object>();
Map<String, Object> ltMap = new HashMap<String, Object>();
Map<String, Object> eqMap = new HashMap<String, Object>();
eqMap.put("questionId","101213");
Map<String, Object> gteMap = new HashMap<String, Object>();
Map<String, Object> lteMap = new HashMap<String, Object>();
Map<String, String> regexMap = new HashMap<String, String>();
Map<String, Collection> inMap = new HashMap<String, Collection>();
Map<String, Object> neMap = new HashMap<String, Object>();
Criteria c = questionMdao.createCriteria(gtMap,ltMap,eqMap,gteMap,lteMap,regexMap,inMap,neMap);
List<Question> questions = questionMdao.searchByParams(c,questionMdao.initMdbConllectionName());
return questions;
}
@RequestMapping(value = "/searchByParams2", method = {RequestMethod.POST, RequestMethod.GET})
public Object searchByParams2(@RequestParam(value = "",required = false) String json){
Map<String, Object> gtMap = new HashMap<String, Object>();
Map<String, Object> ltMap = new HashMap<String, Object>();
Map<String, Object> eqMap = new HashMap<String, Object>();
Map<String, Object> gteMap = new HashMap<String, Object>();
Map<String, Object> lteMap = new HashMap<String, Object>();
Map<String, String> regexMap = new HashMap<String, String>();
String content = "SpringBootApplication";
Pattern pattern = Pattern.compile("^.*"+content.trim()+".*$",Pattern.CASE_INSENSITIVE);
regexMap.put("questionName",pattern.toString());
Map<String, Collection> inMap = new HashMap<String, Collection>();
Map<String, Object> neMap = new HashMap<String, Object>();
Criteria c = questionMdao.createCriteria(gtMap,ltMap,eqMap,gteMap,lteMap,regexMap,inMap,neMap);
List<Question> questions = questionMdao.searchByParams(c,questionMdao.initMdbConllectionName());
return questions;
}
@RequestMapping(value = "/searchByParams3", method = {RequestMethod.POST, RequestMethod.GET})
public Object searchByParams3(@RequestParam(value = "",required = false) String json){
Map<String, Object> gtMap = new HashMap<String, Object>();
Map<String, Object> ltMap = new HashMap<String, Object>();
Map<String, Object> eqMap = new HashMap<String, Object>();
Map<String, Object> gteMap = new HashMap<String, Object>();
Map<String, Object> lteMap = new HashMap<String, Object>();
Map<String, String> regexMap = new HashMap<String, String>();
Map<String, Collection> inMap = new HashMap<String, Collection>();
List<String> ids = new ArrayList<String>();
ids.add("101214");
ids.add("101215");
inMap.put("questionId", ids);
Map<String, Object> neMap = new HashMap<String, Object>();
Criteria c = questionMdao.createCriteria(gtMap,ltMap,eqMap,gteMap,lteMap,regexMap,inMap,neMap);
List<Question> questions = questionMdao.searchByParams(c,questionMdao.initMdbConllectionName());
return questions;
}
@RequestMapping(value = "/searchByQuery", method = {RequestMethod.POST, RequestMethod.GET})
public Object searchByQuery(@RequestParam(value = "",required = false) String json){
Map<String, Object> gtMap = new HashMap<String, Object>();
Map<String, Object> ltMap = new HashMap<String, Object>();
Map<String, Object> eqMap = new HashMap<String, Object>();
Map<String, Object> gteMap = new HashMap<String, Object>();
Map<String, Object> lteMap = new HashMap<String, Object>();
Map<String, String> regexMap = new HashMap<String, String>();
Map<String, Collection> inMap = new HashMap<String, Collection>();
List<String> ids = new ArrayList<String>();
ids.add("101213");
ids.add("101215");
inMap.put("questionId", ids);
Map<String, Object> neMap = new HashMap<String, Object>();
Criteria c = questionMdao.createCriteria(gtMap,ltMap,eqMap,gteMap,lt
没有合适的资源?快使用搜索试试~ 我知道了~
springboot结合mongodb
共15个文件
java:11个
xml:2个
properties:1个
需积分: 5 12 下载量 42 浏览量
2018-01-10
13:55:28
上传
评论
收藏 14KB ZIP 举报
温馨提示
springboot结合mongodb使用,对mongodb进行增删改查实例
资源推荐
资源详情
资源评论
收起资源包目录
springboot.zip (15个子文件)
springboot
pom.xml 2KB
src
test
cn
hongsong
HelloTests.java 1KB
main
resources
application.properties 309B
java
cn
hongsong
dao
Application.java 1KB
mongo
IMongoManage.java 1KB
impl
MongoManage.java 6KB
model
BaseModel.java 252B
Question.java 745B
controller
MongoSolveController.java 11KB
SampleController.java 786B
service
mongo
IQuestionMdao.java 236B
impl
QuestionMdaoImpl.java 393B
util
ReflectionUtils.java 892B
webapp
WEB-INF
web.xml 222B
index.jsp 57B
共 15 条
- 1
资源评论
scaling_heights
- 粉丝: 209
- 资源: 49
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功