當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
大数据之mongodb -- (2)java集成 MongoDB 3.2,使用Spring-data-mongodb进行集成
生活随笔
收集整理的這篇文章主要介紹了
大数据之mongodb -- (2)java集成 MongoDB 3.2,使用Spring-data-mongodb进行集成
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Java集成MongoDB有很多方式,可以直接用mongodb的java驅動程序來發送語句到mongodb服務器,也可以用第三方的工具包來做。
(1) 選擇版本
選擇的就是springdata集成的mongodb(spring-data-mongodb)
1.1 spring-data-mongodb版本
gradle坐標:
org.springframework.data:spring-data-mongodb:1.7.2.RELEASE
maven 坐標
<dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-mongodb</artifactId><version>1.7.2.RELEASE</version> </dependency>- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
1.2 java驅動器版本
gradle坐標:
org.mongodb:mongo-java-driver:3.2.0
maven 坐標
<dependency><groupId>org.mongodb</groupId><artifactId>mongo-java-driver</artifactId><version>3.2.0</version> </dependency>- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
(2) 集成
2.1 spring 配置文件
新建文件 mongodb-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:mongo="http://www.springframework.org/schema/data/mongo"xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!-- mongodb 的基本配置 --><mongo:mongo id="mongo" host="192.168.1.202" port="27017" /><!-- 權限配置 --><bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials"><constructor-arg name="username" value="root"/><constructor-arg name="password" value="root"/></bean><!-- template 配置 --><bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"><constructor-arg ref="mongo" /><!-- 數據庫名稱 --><constructor-arg value="demodb" /><!-- 權限 --><constructor-arg ref="userCredentials" /></bean></beans>- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
集成到spring的基礎配置文件中即可?
spring的主配置文件插入如下代碼
- 1
- 2
- 1
- 2
(3) 編寫基礎類
3.1 Dao 基礎操作類 MongodbDao
其他的dao類都可以繼承改類
import java.util.List;import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; import org.springframework.stereotype.Repository;import com.github.pagehelper.PageInfo;/*** mongodb 基礎操作類* @author chenpengye 2015年12月21日 下午11:33:06* @param <T>*/ @Repository public class MongodbDao<T extends IdEntity> {private static final Logger logger = LoggerFactory.getLogger(MongodbDao.class);private static final int DEFAULT_SKIP = 0;private static final int DEFAULT_LIMIT = 200;@Autowiredprotected MongoTemplate mongoTemplate;// ======= 增 ============public void save(T t) {mongoTemplate.save(t);logger.debug("save entity: {}", t);}public void insertAll(List<T> list) {mongoTemplate.insertAll(list);}// ======= 刪 ============/*** 刪除對象* * @param t*/public void delete(T t) {mongoTemplate.remove(t);}/*** 根據id 刪除對象* * @param id*/public void deleteById(String id) {Criteria criteria = Criteria.where("id").is(id);Query query = new Query(criteria);mongoTemplate.remove(query, this.getEntityClass());}/*** 根據條件刪除*/public void delete(Query query) {mongoTemplate.remove(query, this.getEntityClass());}/*** 刪除該collection 的所有的數據*/public void deleteAll() {mongoTemplate.dropCollection(this.getEntityClass());}// ======= 改 ============public void update(Query query, Update update) {mongoTemplate.findAndModify(query, update, this.getEntityClass());}// ======= 查 ============public List<T> findAll(){return mongoTemplate.findAll(this.getEntityClass());}/*** 根據查詢query 查找list* * @param query* @return*/public List<T> find(Query query) {return mongoTemplate.find(query, this.getEntityClass());}/*** 按照字段排序 - 順序 <br/>* @param query 查詢條件 <br/>* @param properties 排序字段 <br/>* @return*/public List<T> findWithOrderAsc(Query query, String... properties){Sort sort = new Sort(Direction.ASC, properties);query.with(sort);return mongoTemplate.find(query, this.getEntityClass());}/*** 按照字段排序 - 逆序 <br/>* @param query 查詢條件 <br/>* @param properties 排序字段 <br/>* @return*/public List<T> findWithOrderDesc(Query query, String... properties){Sort sort = new Sort(Direction.DESC, properties);query.with(sort);return mongoTemplate.find(query, this.getEntityClass());}/*** 根據查詢query 查找一個對象* * @param query* @return*/public T findOne(Query query) {return mongoTemplate.findOne(query, this.getEntityClass());}/*** 根據 id 查詢對象* * @param id* @return*/public T findById(String id) {return mongoTemplate.findById(id, this.getEntityClass());}/*** 根據id 和 集合名字查詢對象* * @param id* @param collectionName* @return*/public T findById(String id, String collectionName) {return mongoTemplate.findById(id, this.getEntityClass(), collectionName);}/*** 查詢分頁 tips:[不要skip 太多的頁數,如果跳過太多會嚴重影響效率。最大不要skip 20000頁]* @param page* @param query* @return*/public PageInfo<T> findPage(PageInfo<T> page, Query query) {long count = this.count(query);page.setTotal(count);int pageNumber = page.getPageNum();int pageSize = page.getPageSize();query.skip((pageNumber - 1) * pageSize).limit(pageSize);List<T> list = this.find(query);page.setList(list);return page;}public long count(Query query) {return mongoTemplate.count(query, this.getEntityClass());}/*** 獲取需要操作的實體類class <br/>* 例如: StudentScoreDao extends MongodbDao <b><StudentScore></b> <br/>* 返回的是 <b>StudentScore</b> 的Class* * @return*/private Class<T> getEntityClass() {return ReflectionUtils.getSuperClassGenricType(getClass());}/*** 獲取collection的名字,默認是dao范型T的名字 <br/>* 例如: StudentScoreDao extends MongodbDao <b><StudentScore></b> <br/>* 則返回的名字是:<b>StudentScore</b>* * @return*/private String getCollectionName() {return getEntityClass().getSimpleName();}}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
由于現行項目使用mybatis,并且分頁采用了pagehelper:pagehelper:4.0.3,因此這里的分頁類也采用里pagehelper里面的分頁類。如果要分頁,請也引入pagehelper的jar包?
gradle坐標
- 1
- 2
- 1
- 2
maven坐標
<dependency><groupId>com.github.jsqlparser</groupId><artifactId>jsqlparser</artifactId><version>0.9.4</version> </dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>4.0.3</version> </dependency>- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
3.2 工具類 ReflectionUtils
import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type;import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.Assert;/*** 反射工具類.* * 提供訪問私有變量,獲取泛型類型Class, 提取集合中元素的屬性, 轉換字符串到對象等Util函數.* */ public class ReflectionUtils {private static Logger logger = LoggerFactory.getLogger(ReflectionUtils.class);/*** 調用Getter方法.*/public static Object invokeGetterMethod(Object obj, String propertyName) {String getterMethodName = "get" + StringUtils.capitalize(propertyName);return invokeMethod(obj, getterMethodName, new Class[] {}, new Object[] {});}/*** 調用Setter方法.使用value的Class來查找Setter方法.*/public static void invokeSetterMethod(Object obj, String propertyName, Object value) {invokeSetterMethod(obj, propertyName, value, null);}/*** 調用Setter方法.* * @param propertyType 用于查找Setter方法,為空時使用value的Class替代.*/public static void invokeSetterMethod(Object obj, String propertyName, Object value, Class<?> propertyType) {Class<?> type = propertyType != null ? propertyType : value.getClass();String setterMethodName = "set" + StringUtils.capitalize(propertyName);invokeMethod(obj, setterMethodName, new Class[] { type }, new Object[] { value });}/*** 直接讀取對象屬性值, 無視private/protected修飾符, 不經過getter函數.*/public static Object getFieldValue(final Object obj, final String fieldName) {Field field = getAccessibleField(obj, fieldName);if (field == null) {throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]");}Object result = null;try {result = field.get(obj);} catch (IllegalAccessException e) {logger.error("不可能拋出的異常{}", e.getMessage());}return result;}/*** 直接設置對象屬性值, 無視private/protected修飾符, 不經過setter函數.*/public static void setFieldValue(final Object obj, final String fieldName, final Object value) {Field field = getAccessibleField(obj, fieldName);if (field == null) {throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]");}try {field.set(obj, value);} catch (IllegalAccessException e) {logger.error("不可能拋出的異常:{}", e.getMessage());}}/*** 循環向上轉型, 獲取對象的DeclaredField, 并強制設置為可訪問.* * 如向上轉型到Object仍無法找到, 返回null.*/public static Field getAccessibleField(final Object obj, final String fieldName) {Assert.notNull(obj, "object不能為空");Assert.hasText(fieldName, "fieldName");for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) {try {Field field = superClass.getDeclaredField(fieldName);field.setAccessible(true);return field;} catch (NoSuchFieldException e) {//NOSONAR// Field不在當前類定義,繼續向上轉型}}return null;}/*** 直接調用對象方法, 無視private/protected修飾符.* 用于一次性調用的情況.*/public static Object invokeMethod(final Object obj, final String methodName, final Class<?>[] parameterTypes,final Object[] args) {Method method = getAccessibleMethod(obj, methodName, parameterTypes);if (method == null) {throw new IllegalArgumentException("Could not find method [" + methodName + "] on target [" + obj + "]");}try {return method.invoke(obj, args);} catch (Exception e) {throw convertReflectionExceptionToUnchecked(e);}}/*** 循環向上轉型, 獲取對象的DeclaredMethod,并強制設置為可訪問.* 如向上轉型到Object仍無法找到, 返回null.* * 用于方法需要被多次調用的情況. 先使用本函數先取得Method,然后調用Method.invoke(Object obj, Object... args)*/public static Method getAccessibleMethod(final Object obj, final String methodName,final Class<?>... parameterTypes) {Assert.notNull(obj, "object不能為空");for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) {try {Method method = superClass.getDeclaredMethod(methodName, parameterTypes);method.setAccessible(true);return method;} catch (NoSuchMethodException e) {//NOSONAR// Method不在當前類定義,繼續向上轉型}}return null;}/*** 通過反射, 獲得Class定義中聲明的父類的泛型參數的類型.* 如無法找到, 返回Object.class.* eg.* public UserDao extends HibernateDao<User>** @param clazz The class to introspect* @return the first generic declaration, or Object.class if cannot be determined*/@SuppressWarnings({ "unchecked", "rawtypes" })public static <T> Class<T> getSuperClassGenricType(final Class clazz) {return getSuperClassGenricType(clazz, 0);}/*** 通過反射, 獲得Class定義中聲明的父類的泛型參數的類型.* 如無法找到, 返回Object.class.* * 如public UserDao extends HibernateDao<User,Long>** @param clazz clazz The class to introspect* @param index the Index of the generic ddeclaration,start from 0.* @return the index generic declaration, or Object.class if cannot be determined*/@SuppressWarnings("rawtypes")public static Class getSuperClassGenricType(final Class clazz, final int index) {Type genType = clazz.getGenericSuperclass();if (!(genType instanceof ParameterizedType)) {logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");return Object.class;}Type[] params = ((ParameterizedType) genType).getActualTypeArguments();if (index >= params.length || index < 0) {logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "+ params.length);return Object.class;}if (!(params[index] instanceof Class)) {logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");return Object.class;}return (Class) params[index];}/*** 將反射時的checked exception轉換為unchecked exception.*/public static RuntimeException convertReflectionExceptionToUnchecked(Exception e) {if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException|| e instanceof NoSuchMethodException) {return new IllegalArgumentException("Reflection Exception.", e);} else if (e instanceof InvocationTargetException) {return new RuntimeException("Reflection Exception.", ((InvocationTargetException) e).getTargetException());} else if (e instanceof RuntimeException) {return (RuntimeException) e;}return new RuntimeException("Unexpected Checked Exception.", e);} }- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
3.3 基礎實體類 IdEntity
import java.io.Serializable;/*** mongodb 基礎id類,id都是字符串型的* @author chenpengye* 2015年12月21日 下午4:53:45*/ public class IdEntity implements Serializable {private static final long serialVersionUID = 33633625616087044L;private String id;public String getId() {return id;}public void setId(String id) {this.id = id;}}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
3.4 實體類 StudentScore
import java.io.Serializable; import java.util.List;/*** 測試實體類* @author chenpengye* 2015年12月21日 下午11:59:02*/ public class StudentScore extends IdEntity implements Serializable {private static final long serialVersionUID = 8743196073520676022L;/*** 學生姓名*/private String username;/*** 學生成績*/private List<Double> scoreList;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public List<Double> getScoreList() {return scoreList;}public void setScoreList(List<Double> scoreList) {this.scoreList = scoreList;}}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
3.5 實體類的dao操作類 StudentScoreDao
import org.springframework.stereotype.Repository;/*** 繼承MongodbDao<br/>* 此類對StudentScore對增刪改查和分頁方法都已經有了<br/>* @author chenpengye* 2016年1月4日 下午10:04:25*/ @Repository public class StudentScoreDao extends MongodbDao<StudentScore> {}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
有需要的同學可以參考我的上一篇博客,關于mongodb的安裝?
---(1)在ubuntu上安裝mongodb?------
歡迎探討,如有疑問請發郵件到chenpengye1861@163.com
總結
以上是生活随笔為你收集整理的大数据之mongodb -- (2)java集成 MongoDB 3.2,使用Spring-data-mongodb进行集成的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 红魔虾生吃的时候会不会有寄生虫?
- 下一篇: 搬新家水果提前放进去吗?