【Java 新建项目】使用程序对新项目的各个实体 创建Dao、DaoImpl、Service、ServiceImpl层的文件

简介: 优化之后的步骤:1.第一步 生成各层文件夹,并且创建GenericDao.java等基础dao【基础dao中涉及到的包名等自行更改】2.第二步 生成各个实体对应的Dao等层文件  首先给出基本Dao层代码:【将这些类保存为文件,放在固定的位置】GenericDao.

优化之后的步骤:

1.第一步 生成各层文件夹,并且创建GenericDao.java等基础dao【基础dao中涉及到的包名等自行更改】

2.第二步 生成各个实体对应的Dao等层文件

 

 

首先给出基本Dao层代码:【将这些类保存为文件,放在固定的位置】

GenericDao.java

  1 package com.agen.dao;
  2 
  3 import java.io.Serializable;
  4 import java.util.Collection;
  5 import java.util.List;
  6 import java.util.Map;
  7 
  8 import org.hibernate.Criteria;
  9 import org.hibernate.criterion.Criterion;
 10 import org.hibernate.criterion.DetachedCriteria;
 11 
 12 import com.github.pagehelper.PageInfo;
 13 
 14 
 15 public interface GenericDao<T, PK extends Serializable> {
 16     /**
 17      * 查询全部,可以排序
 18      * @param orderBy
 19      * @param isAsc
 20      * @return List<T>
 21      */
 22     public List<T> list(Criteria criteria);
 23 
 24     /**
 25      * 查询全部,可以排序
 26      * @param orderBy
 27      * @param isAsc
 28      * @return List<T>
 29      */
 30     public List<T> list(String orderBy, boolean isAsc);
 31     
 32     /**
 33      * 离线查询
 34      * @param criteria
 35      * @return List<T>
 36      */
 37     public List<T> list(DetachedCriteria criteria);
 38     
 39     /**
 40      * 根据Criteria查询条件,获取总数
 41      * @param criteria
 42      * @return int
 43      * @throws SecurityException 
 44      * @throws NoSuchFieldException 
 45      * @throws IllegalAccessException 
 46      * @throws IllegalArgumentException 
 47      */
 48     public int countAll(Criteria criteria);
 49     
 50     /**
 51      * 获取总数(默认为entityClass) 即查询总条数
 52      * @return int
 53      */
 54     public int countAll();
 55     
 56     /**
 57      * 根据I判断是否存在
 58      * @param id
 59      * @return boolean
 60      */
 61     public boolean exists(PK id);
 62     
 63     /**
 64      * 保存实体 
 65      * @param t 实体参数
 66      */
 67     public void save(T t);
 68 
 69     /**
 70      * 保存或者更新实体
 71      * @param t 实体
 72      */
 73     public void saveOrUpdate(T t);
 74 
 75     /**
 76      * 加载实体的通过load方法
 77      * @param id 实体的id
 78      * @return 查询出来的实体
 79      */
 80     public T load(PK id);
 81     
 82     /**
 83      * 合并实体 
 84      * @param entity
 85      */
 86     public void merge(T entity);
 87     
 88     /**
 89      * 查找全部
 90      */
 91     public List<T> findAll();
 92 
 93     /**
 94      * 通过get方法加载实体的
 95      * @param id 实体的id
 96      * @return 查询出来的实体
 97      */
 98     public T get(PK id);
 99 
100     /**
101      * contains
102      * @param t 实体
103      * @return 是否包含
104      */
105     public boolean contains(T t);
106 
107     /**
108      * delete
109      * @param t
110      * 删除实体
111      */
112     public void delete(T t);
113 
114     /**
115      * 根据ID删除数据
116      * @param Id 实体id
117      * @return 是否删除成功
118      */
119     public boolean deleteById(PK Id);
120 
121     /**
122      * 删除所有
123      * @param entities 实体的Collection集合
124      */
125     public void deleteAll(Collection<T> entities);
126 
127     /**
128      * 执行Hql语句 要求 hql中参数顺序与可变参数 中参数顺序相一致
129      * @param hqlString hql
130      * @param values 不定参数数组
131      */
132     public void queryHql(String hqlString, Object... values);
133 
134     /**
135      * 执行Sql语句(不建议用,影响扩展)
136      * @param sqlString sql
137      * @param values 不定参数数组
138      */
139     public void querySql(String sqlString, Object... values);
140 
141     /**
142      * 根据HQL语句查找唯一实体
143      * 
144      * @param hqlString HQL语句
145      * @param values 不定参数的Object数组
146      * @return 查询实体
147      */
148     public T getByHQL(String hqlString, Object... values);
149     
150     /**
151      * 根据SQL语句查找唯一实体(不建议用,影响扩展)
152      * @param sqlString SQL语句
153      * @param values 不定参数的Object数组
154      * @return 查询实体
155      */
156 
157     /**
158      * 根据HQL语句,得到对应的list
159      * @param hqlString HQL语句
160      * @param values 不定参数的Object数组
161      * @return 查询多个实体的List集合
162      */
163     public List<T> getListByHQL(String hqlString, Object... values);
164 
165     /**
166      * 根据SQL语句,得到对应的list(不建议用,影响扩展)
167      * @param sqlString HQL语句
168      * @param values 不定参数的Object数组
169      * @return 查询多个实体的List集合
170      */
171     public List<T> getListBySQL(String sqlString, Object... values);
172 
173     /**
174      * refresh 刷新实体,强制与数据库两步 refresh方法应该是数据库的数据更新到本地的person实体中,而不是本地person更新数据到数据库中  也就是执行refresh方法是更新了java代码中变量的数据值
175      * @param t 实体
176      */
177     public void refresh(T t);
178 
179     /**
180      * update
181      * @param t
182      * 更新的是数据库中的数据
183      */
184     public void update(T t);
185 
186     /**
187      * 根据HQL得到记录数
188      * @param hql HQL语句
189      * @param values 不定参数的Object数组
190      * @return 记录总数
191      */
192     public Long countByHql(String hql, Object... values);
193 
194     /**
195      * HQL分页查询
196      * 
197      * @param hql HQL语句
198      * @param countHql 查询记录条数的HQL语句
199      * @param pageNo 下一页
200      * @param pageSize 一页总条数
201      * @param values  不定Object数组参数
202      * @return PageResults的封装类,里面包含了页码的信息以及查询的数据List集合
203      */
204     public  PageInfo<T> findPageByHql(String hql, String countHql, int pageNo, int pageSize, Object... values);
205     
206     /**
207      * 按属性查找对象列表,匹配方式为相等
208      * @param propertyName
209      * @param value
210      * @return List<T>
211      */
212     public List<T> list(String propertyName, Object value);
213     
214     /**
215      * 根据criterion查询条件获取数据列表
216      * @param criterion
217      * @return List<T>
218      */
219     public List<T> list(Criterion criterion);
220     
221     /**
222      * 按Criteria查询对象列表
223      * @param criterions
224      * @return List<T>
225      */
226     public List<T> list(Criterion... criterions);
227     
228     /**
229      * 按属性查找唯一对象,匹配方式为相等
230      * @param propertyName
231      * @param value
232      * @return T
233      */
234     public T uniqueResult(String propertyName, Object value);
235     
236     /**
237      * 按Criteria查询唯一对象
238      * @param criterions
239      * @return T
240      */
241     public T uniqueResult(Criterion... criterions);
242     
243     /**
244      * 按Criteria查询唯一对象
245      * @param criteria
246      * @return T
247      */
248     public T uniqueResult(Criteria criteria);
249     
250     /**
251      * 按criteria查询某个Integer类型的字段
252      * @param criteria
253      * @return
254      */
255     public Integer uniqueResultInt(Criteria criteria);
256     
257     /**
258      * 为Criteria添加distinct transformer
259      * @param criteria
260      * @return Criteria
261      */
262     public Criteria distinct(Criteria criteria);
263     
264     /**
265      * 刷新session
266      */
267     public void flush();
268     
269     /**
270      * 清空session
271      */
272     public void clear();
273     
274     /**
275      * 创建Criteria实例
276      */
277     public Criteria createCriteria();
278     
279     /**
280      * 根据Criterion条件创建Criteria
281      * @param criterions
282      * @return Criteria
283      */
284     public Criteria createCriteria(Criterion... criterions);
285     
286     /**
287      * 分页查询Criteria
288      * @param criteria 
289      * @param pageNo 下页页码
290      * @param pageSize 页面数据量
291      * @return List<T>
292      */
293     public List<T> findPage(Criteria criteria, int pageNo, int pageSize);
294     
295     /**
296      * 分页查询Criteria
297      * @param criteria
298      * @param pageNo
299      * @param pageSize
300      * @return PageInfo<T>
301      * @throws SecurityException 
302      * @throws NoSuchFieldException 
303      * @throws IllegalAccessException 
304      * @throws IllegalArgumentException 
305      */
306     public PageInfo<T> findQuery(Criteria criteria, int pageNo, int pageSize);
307     
308     /**
309      * 
310      * @param hql
311      * @param pageNo
312      * @param pageSize
313      * @param map
314      * @return List<T>
315      */
316     public List<T> findQuery(String hql, int pageNo, int pageSize, Map<?, ?> map);
317 }
View Code

GenericDaoImpl.java

  1 package com.agen.dao.impl;
  2 
  3 import java.io.Serializable;
  4 import java.lang.reflect.Field;
  5 import java.util.ArrayList;
  6 import java.util.Collection;
  7 import java.util.List;
  8 import java.util.Map;
  9 import java.util.Map.Entry;
 10 
 11 import org.hibernate.Criteria;
 12 import org.hibernate.Query;
 13 import org.hibernate.QueryException;
 14 import org.hibernate.ScrollableResults;
 15 import org.hibernate.Session;
 16 import org.hibernate.SessionFactory;
 17 import org.hibernate.criterion.CriteriaSpecification;
 18 import org.hibernate.criterion.Criterion;
 19 import org.hibernate.criterion.DetachedCriteria;
 20 import org.hibernate.criterion.Order;
 21 import org.hibernate.criterion.Projections;
 22 import org.hibernate.criterion.Restrictions;
 23 import org.hibernate.internal.CriteriaImpl;
 24 import org.hibernate.internal.CriteriaImpl.Subcriteria;
 25 import org.springframework.beans.factory.annotation.Autowired;
 26 import org.springframework.transaction.annotation.Transactional;
 27 import org.springframework.util.Assert;
 28 
 29 import java.lang.reflect.ParameterizedType; 
 30 
 31 import com.agen.dao.GenericDao;
 32 import com.github.pagehelper.PageInfo;
 33 
 34 public class GenericDaoImpl<T, PK extends Serializable> implements GenericDao<T, PK> {
 35     /**
 36      * 不建议直接使用
 37      */
 38     @Autowired
 39     private SessionFactory sessionFactory;
 40     
 41     public Session getSession() {
 42         // 需要开启事物,才能得到CurrentSession
 43         return sessionFactory.getCurrentSession();
 44     }
 45     
 46     
 47     protected Class<T> entityClass;
 48 
 49     protected Class getEntityClass() {
 50         if (entityClass == null) {
 51             if(((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments().length > 0) {
 52                 entityClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
 53             }
 54         }
 55         return entityClass;
 56     }
 57 
 58     public SessionFactory getSessionFactory() {
 59         return sessionFactory;
 60     }
 61     
 62     public void setSessionFactory(SessionFactory sessionFactory) {
 63         this.sessionFactory = sessionFactory;
 64     }
 65     
 66     @Override
 67     public Criteria createCriteria() {
 68         return getSession().createCriteria(getEntityClass());
 69     }
 70 
 71     
 72     @Override
 73     public void save(T t) {
 74         this.getSession().save(t);
 75     }
 76 
 77     @Override
 78     public void saveOrUpdate(T t) {
 79         Assert.notNull(t);
 80         this.getSession().saveOrUpdate(t);
 81     }
 82     
 83     @Override
 84     public T load(PK id) {
 85         Assert.notNull(id);
 86         T load = (T) this.getSession().load(getEntityClass(), id);
 87         return load;
 88     }
 89 
 90     @Override
 91     public T get(PK id) {
 92         Assert.notNull(id);
 93         T load = (T) this.getSession().get(getEntityClass(), id);
 94         return load;
 95     }
 96 
 97     @Override
 98     public boolean contains(T t) {
 99         Assert.notNull(t);
100         return this.getSession().contains(t);
101     }
102 
103     @Override
104     public void delete(T t) {
105         Assert.notNull(t);
106         this.getSession().delete(t);
107     }
108 
109     @Override
110     public boolean deleteById(PK Id) {
111         Assert.notNull(Id);
112         T t = get(Id);
113         if (t == null) return false;
114         delete(t);
115         return true;
116     }
117 
118     @Override
119     public void deleteAll(Collection<T> entities) {
120         Assert.notNull(entities);
121         for (Object entity : entities) {
122             this.getSession().delete(entity);
123         }
124     }
125 
126     @Override
127     public void queryHql(String hqlString, Object... values) {
128         Query query = this.getSession().createQuery(hqlString);
129         if (values != null) {
130             for (int i = 0; i < values.length; i++) {
131                 query.setParameter(i, values[i]);
132             }
133         }
134         query.executeUpdate();
135     }
136     
137     /**
138      * 根据hql  和    map集合中的数据   进行相对应的 insert   update   delete操作
139      * @param hqlString
140      * @param paras
141      */
142     public void queryHql(String hqlString, Map<String, Object> paras) {
143         Query query = this.getSession().createQuery(hqlString);
144         if (paras != null) {
145             for (Entry<String, Object> en : paras.entrySet()) {
146                 query.setParameter(en.getKey(), en.getValue());
147             }
148         }
149         query.executeUpdate();
150     }
151 
152     @Override
153     public void querySql(String sqlString, Object... values) {
154         Query query = this.getSession().createSQLQuery(sqlString);
155         if (values != null) {
156             for (int i = 0; i < values.length; i++) {
157                 query.setParameter(i, values[i]);
158             }
159         }
160         query.executeUpdate();
161     }
162 
163     @Override
164     public T getByHQL(String hqlString, Object... values) {
165         Query query = this.getSession().createQuery(hqlString);
166         if (values != null) {
167             for (int i = 0; i < values.length; i++) {
168                 query.setParameter(i, values[i]);
169             }
170         }
171         return (T) query.uniqueResult();
172     }
173 
174     @Override
175     public List<T> getListByHQL(String hqlString, Object... values) {
176         Query query = this.getSession().createQuery(hqlString);
177         if (values != null) {
178             for (int i = 0; i < values.length; i++) {
179                 query.setParameter(i, values[i]);
180             }
181         }
182         return query.list();
183     }
184 
185     @Override
186     public List<T> getListBySQL(String sqlString, Object... values) {
187         Query query = this.getSession().createSQLQuery(sqlString);
188         if (values != null) {
189             for (int i = 0; i < values.length; i++) {
190                 query.setParameter(i, values[i]);
191             }
192         }
193         return query.list();
194     }
195 
196     @Override
197     public void refresh(T t) {
198         this.getSession().refresh(t);
199     }
200 
201     @Override
202     public void update(T t) {
203         this.getSession().update(t);
204     }
205 
206     @Override
207     public Long countByHql(String hql, Object... values) {
208         Query query = this.getSession().createQuery(hql);
209         if (values != null) {
210             for (int i = 0; i < values.length; i++) {
211                 query.setParameter(i, values[i]);
212             }
213         }
214         return (Long) query.uniqueResult();
215     }
216 
217     @Override
218     public PageInfo<T> findPageByHql(String hql, String countHql, int pageNo, int pageSize, Object... values) {
219         PageInfo<T> retValue = new PageInfo<T>();
220         Query query = this.getSession().createQuery(hql);
221         if (values != null) {
222             for (int i = 0; i < values.length; i++) {
223                 query.setParameter(i, values[i]);
224             }
225         }
226         int currentPage = pageNo > 1 ? pageNo : 1;
227         retValue.setPages(currentPage);
228         retValue.setPageSize(pageSize);
229         if (countHql == null) {
230             ScrollableResults results = query.scroll();
231             results.last();
232             retValue.setTotal(results.getRowNumber() + 1);
233         } else {
234             Long count = countByHql(countHql, values);
235             retValue.setTotal(count.intValue());
236         }
237         List<T> itemList = query.setFirstResult((currentPage - 1) * pageSize).setMaxResults(pageSize).list();
238         if (itemList == null) {
239             itemList = new ArrayList<T>();
240         }
241         retValue.setList(itemList);
242         return retValue;
243     }
244 
245 
246     @Override
247     public void merge(T entity) {
248         // TODO Auto-generated method stub
249         getSession().merge(entity);
250     }
251     
252     @Override
253     public boolean exists(PK id) {
254         return null != get(id);
255     }
256 
257     @Override
258     public int countAll() {
259         Criteria criteria = createCriteria();
260         return Integer.valueOf(criteria.setProjection(Projections.rowCount()).uniqueResult().toString());
261     }
262 
263     @Override
264     public int countAll(Criteria criteria) {
265         criteria.setProjection(null);
266         return Integer.valueOf(criteria.setProjection(Projections.rowCount()).uniqueResult().toString());
267     }
268     
269     @Override
270     public List<T> list(Criteria criteria) {
271         return criteria.list();
272     }
273 
274     @Override
275     public List<T> list(DetachedCriteria criteria) {
276         return (List<T>) list(criteria.getExecutableCriteria(getSession()));
277     }
278 
279     @Override
280     public List<T> list(String orderBy, boolean isAsc) {
281         Criteria criteria = createCriteria();
282         if (isAsc) {
283             criteria.addOrder(Order.asc(orderBy));
284         } else {
285             criteria.addOrder(Order.desc(orderBy));
286         }
287         return criteria.list();
288     }
289     
290     @Override
291     public List<T> list(String propertyName, Object value) {
292         Criterion criterion = Restrictions.like(propertyName, "%"+ value +"%");
293         return list(criterion);
294     }
295 
296 
297     @Override
298     public List<T> list(Criterion criterion) {
299         Criteria criteria = createCriteria();
300         criteria.add(criterion);
301         return criteria.list();
302     }
303 
304     @Override
305     public List<T> list(Criterion... criterions) {
306         return createCriteria(criterions).list();
307     }
308 
309     @Override
310     public T uniqueResult(String propertyName, Object value) {
311         Criterion criterion = Restrictions.eq(propertyName, value);
312         return (T) createCriteria(criterion).uniqueResult();
313     }
314 
315     @Override
316     public T uniqueResult(Criterion... criterions) {
317         Criteria criteria = createCriteria(criterions);
318         return uniqueResult(criteria);
319     }
320 
321     @Override
322     public T uniqueResult(Criteria criteria) {
323         return (T) criteria.uniqueResult();
324     }
325     
326     @Override
327     public Integer uniqueResultInt(Criteria criteria) {
328         return (Integer) criteria.uniqueResult();
329     }
330 
331 
332     @Override
333     public Criteria distinct(Criteria criteria) {
334         criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
335         return criteria;
336     }
337 
338     @Override
339     public void flush() {
340         getSession().flush();
341     }
342 
343     @Override
344     public void clear() {
345         getSession().clear();
346     }
347 
348 
349     @Override
350     public Criteria createCriteria(Criterion... criterions) {
351         Criteria criteria = createCriteria();
352         for (Criterion c : criterions) {
353             criteria.add(c);
354         }
355         return criteria;
356     }
357 
358     @Override
359     public List<T> findPage(Criteria criteria, int pageNo, int pageSize) {
360         criteria.setFirstResult((pageNo - 1) * pageSize);
361         criteria.setMaxResults(pageSize);
362         return list(criteria);
363     }
364 
365     @Override
366     public PageInfo<T> findQuery(Criteria criteria, int pageNo, int pageSize) {
367         try {
368             Assert.isTrue(pageNo >= 1, "pageNO should start from 1");
369             while(criteria instanceof Subcriteria){
370                 criteria = ((Subcriteria)criteria).getParent();
371             }
372             //拆分order by子句  
373             while(criteria instanceof Subcriteria){
374                 criteria = ((Subcriteria)criteria).getParent();
375             }
376             Field field = CriteriaImpl.class.getDeclaredField("orderEntries");  
377             field.setAccessible(true);  
378             List<?> orderEntrys = (List<?>) field.get(criteria);  
379             field.set(criteria, new ArrayList());  
380             //统计总数
381             long totalCount = countAll(criteria);
382             criteria.setProjection(null);
383             //统计完了再把order by子句加上 这样保证了sql语句不会出错
384             field.set(criteria, orderEntrys);
385             List<T> list = findPage(criteria, pageNo, pageSize);
386             if (totalCount < 1) {
387                 return new PageInfo<T>();
388             }
389             PageInfo<T> page = new PageInfo<T>();
390             page.setPageNum(pageNo);
391             page.setTotal(totalCount);
392             page.setPages((int) (totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1));
393             page.setPageSize(pageSize);
394             page.setList(list);
395             return page;
396         } catch (Exception e) {
397             // TODO: handle exception
398             e.printStackTrace();
399             throw new QueryException("查询出错!");
400         }
401         
402     }
403 
404     @Override
405     public List<T> findQuery(String hql, int pageNo, int pageSize, Map<?, ?> map) {
406         // TODO Auto-generated method stub
407         if(null == hql) return null;
408         Query query = getSession().createQuery(hql);
409         for (Entry<?, ?> en : map.entrySet()) {
410             query.setParameter(en.getKey().toString(), en.getValue());
411         }
412         if(pageNo > 0) query.setFirstResult(pageNo);
413         if(pageSize > 0) query.setFirstResult(pageSize);
414         return query.list();
415     }
416 
417     @Override
418     public List<T> findAll() {
419         // TODO Auto-generated method stub
420         return createCriteria().list();
421     }
422 }
View Code

GenericService.java

  1 package com.agen.service;
  2 
  3 import java.io.Serializable;
  4 import java.util.Collection;
  5 import java.util.List;
  6 import java.util.Map;
  7 
  8 import org.hibernate.Criteria;
  9 import org.hibernate.criterion.Criterion;
 10 import org.hibernate.criterion.DetachedCriteria;
 11 
 12 import com.github.pagehelper.PageInfo;
 13 
 14 public interface GenericService<T, PK extends Serializable> {
 15     /**
 16      * 查询全部,可以排序
 17      * @param orderBy
 18      * @param isAsc
 19      * @return List<T>
 20      */
 21     public List<T> list(Criteria criteria);
 22 
 23     /**
 24      * 查询全部,可以排序
 25      * @param orderBy
 26      * @param isAsc
 27      * @return List<T>
 28      */
 29     public List<T> list(String orderBy, boolean isAsc);
 30     
 31     /**
 32      * 离线查询
 33      * @param criteria
 34      * @return List<T>
 35      */
 36     public List<T> list(DetachedCriteria criteria);
 37     
 38     /**
 39      * 根据Criteria查询条件,获取总数
 40      * @param criteria
 41      * @return int
 42      * @throws SecurityException 
 43      * @throws NoSuchFieldException 
 44      * @throws IllegalAccessException 
 45      * @throws IllegalArgumentException 
 46      */
 47     public int countAll(Criteria criteria);
 48     
 49     /**
 50      * 获取总数(默认为entityClass) 即查询总条数
 51      * @return int
 52      */
 53     public int countAll();
 54     
 55     /**
 56      * 根据I判断是否存在
 57      * @param id
 58      * @return boolean
 59      */
 60     public boolean exists(PK id);
 61     
 62     /**
 63      * 保存实体 
 64      * @param t 实体参数
 65      */
 66     public void save(T t);
 67 
 68     /**
 69      * 保存或者更新实体
 70      * @param t 实体
 71      */
 72     public void saveOrUpdate(T t);
 73 
 74     /**
 75      * 加载实体的通过load方法
 76      * @param id 实体的id
 77      * @return 查询出来的实体
 78      */
 79     public T load(PK id);
 80     
 81     /**
 82      * 合并实体 
 83      * @param entity
 84      */
 85     public void merge(T entity);
 86     
 87     /**
 88      * 查找全部
 89      */
 90     public List<T> findAll();
 91 
 92     /**
 93      * 通过get方法加载实体的
 94      * @param id 实体的id
 95      * @return 查询出来的实体
 96      */
 97     public T get(PK id);
 98 
 99     /**
100      * contains
101      * @param t 实体
102      * @return 是否包含
103      */
104     public boolean contains(T t);
105 
106     /**
107      * delete
108      * @param t
109      * 删除实体
110      */
111     public void delete(T t);
112 
113     /**
114      * 根据ID删除数据
115      * @param Id 实体id
116      * @return 是否删除成功
117      */
118     public boolean deleteById(PK Id);
119 
120     /**
121      * 删除所有
122      * @param entities 实体的Collection集合
123      */
124     public void deleteAll(Collection<T> entities);
125 
126     /**
127      * 执行Hql语句 要求 hql中参数顺序与可变参数 中参数顺序相一致
128      * @param hqlString hql
129      * @param values 不定参数数组
130      */
131     public void queryHql(String hqlString, Object... values);
132 
133     /**
134      * 执行Sql语句(不建议用,影响扩展)
135      * @param sqlString sql
136      * @param values 不定参数数组
137      */
138     public void querySql(String sqlString, Object... values);
139 
140     /**
141      * 根据HQL语句查找唯一实体
142      * 
143      * @param hqlString HQL语句
144      * @param values 不定参数的Object数组
145      * @return 查询实体
146      */
147     public T getByHQL(String hqlString, Object... values);
148     
149     /**
150      * 根据SQL语句查找唯一实体(不建议用,影响扩展)
151      * @param sqlString SQL语句
152      * @param values 不定参数的Object数组
153      * @return 查询实体
154      */
155 
156     /**
157      * 根据HQL语句,得到对应的list
158      * @param hqlString HQL语句
159      * @param values 不定参数的Object数组
160      * @return 查询多个实体的List集合
161      */
162     public List<T> getListByHQL(String hqlString, Object... values);
163 
164     /**
165      * 根据SQL语句,得到对应的list(不建议用,影响扩展)
166      * @param sqlString HQL语句
167      * @param values 不定参数的Object数组
168      * @return 查询多个实体的List集合
169      */
170     public List<T> getListBySQL(String sqlString, Object... values);
171 
172     /**
173      * refresh 刷新实体,强制与数据库两步 refresh方法应该是数据库的数据更新到本地的person实体中,而不是本地person更新数据到数据库中  也就是执行refresh方法是更新了java代码中变量的数据值
174      * @param t 实体
175      */
176     public void refresh(T t);
177 
178     /**
179      * update
180      * @param t
181      * 更新的是数据库中的数据
182      */
183     public void update(T t);
184 
185     /**
186      * 根据HQL得到记录数
187      * @param hql HQL语句
188      * @param values 不定参数的Object数组
189      * @return 记录总数
190      */
191     public Long countByHql(String hql, Object... values);
192 
193     /**
194      * HQL分页查询
195      * 
196      * @param hql HQL语句
197      * @param countHql 查询记录条数的HQL语句
198      * @param pageNo 下一页
199      * @param pageSize 一页总条数
200      * @param values  不定Object数组参数
201      * @return PageResults的封装类,里面包含了页码的信息以及查询的数据List集合
202      */
203     public  PageInfo<T> findPageByHql(String hql, String countHql, int pageNo, int pageSize, Object... values);
204     
205     /**
206      * 按属性查找对象列表,匹配方式为相等
207      * @param propertyName
208      * @param value
209      * @return List<T>
210      */
211     public List<T> list(String propertyName, Object value);
212     
213     /**
214      * 根据criterion查询条件获取数据列表
215      * @param criterion
216      * @return List<T>
217      */
218     public List<T> list(Criterion criterion);
219     
220     /**
221      * 按Criteria查询对象列表
222      * @param criterions
223      * @return List<T>
224      */
225     public List<T> list(Criterion... criterions);
226     
227     /**
228      * 按属性查找唯一对象,匹配方式为相等
229      * @param propertyName
230      * @param value
231      * @return T
232      */
233     public T uniqueResult(String propertyName, Object value);
234     
235     /**
236      * 按Criteria查询唯一对象
237      * @param criterions
238      * @return T
239      */
240     public T uniqueResult(Criterion... criterions);
241     
242     /**
243      * 按Criteria查询唯一对象
244      * @param criteria
245      * @return T
246      */
247     public T uniqueResult(Criteria criteria);
248     /**
249      * 按照criteria返回类型为Integer类型的某个字段的值
250      * @param criteria
251      * @return
252      */
253     public Integer uniqueResultInt(Criteria criteria);
254     
255     
256     
257     /**
258      * 为Criteria添加distinct transformer
259      * @param criteria
260      * @return Criteria
261      */
262     public Criteria distinct(Criteria criteria);
263     
264     /**
265      * 刷新session
266      */
267     public void flush();
268     
269     /**
270      * 清空session
271      */
272     public void clear();
273     
274     /**
275      * 创建Criteria实例
276      */
277     public Criteria createCriteria();
278     
279     /**
280      * 根据Criterion条件创建Criteria
281      * @param criterions
282      * @return Criteria
283      */
284     public Criteria createCriteria(Criterion... criterions);
285     
286     /**
287      * 分页查询Criteria
288      * @param criteria 
289      * @param pageNo 下页页码
290      * @param pageSize 页面数据量
291      * @return List<T>
292      */
293     public List<T> findPage(Criteria criteria, int pageNo, int pageSize);
294     
295     /**
296      * 分页查询Criteria
297      * @param criteria
298      * @param pageNo
299      * @param pageSize
300      * @return PageInfo<T>
301      * @throws SecurityException 
302      * @throws NoSuchFieldException 
303      * @throws IllegalAccessException 
304      * @throws IllegalArgumentException 
305      */
306     public PageInfo<T> findQuery(Criteria criteria, int pageNo, int pageSize);
307     
308     /**
309      * 
310      * @param hql
311      * @param pageNo
312      * @param pageSize
313      * @param map
314      * @return List<T>
315      */
316     public List<T> findQuery(String hql, int pageNo, int pageSize, Map<?, ?> map);
317 }
View Code

GenericServiceImpl.java

  1 package com.agen.service.impl;
  2 
  3 import java.io.Serializable;
  4 import java.util.Collection;
  5 import java.util.List;
  6 import java.util.Map;
  7 
  8 import org.hibernate.Criteria;
  9 import org.hibernate.criterion.Criterion;
 10 import org.hibernate.criterion.DetachedCriteria;
 11 import org.springframework.beans.factory.annotation.Autowired;
 12 import org.springframework.stereotype.Component;
 13 import org.springframework.stereotype.Service;
 14 import org.springframework.transaction.annotation.Propagation;
 15 import org.springframework.transaction.annotation.Transactional;
 16 
 17 import com.agen.dao.impl.GenericDaoImpl;
 18 import com.agen.service.GenericService;
 19 import com.github.pagehelper.PageInfo;
 20 
 21 @Transactional
 22 public class GenericServiceImpl<T, PK extends Serializable> implements GenericService<T, PK> {
 23 
 24     
 25     private GenericDaoImpl<T, PK> dao;
 26     /**
 27      * 设值注入Dao
 28      * @param dao
 29      */
 30     @Autowired
 31     public void setDao(GenericDaoImpl<T, PK> dao) {
 32         this.dao = dao;
 33     }
 34     
 35     @Override
 36     public List<T> list(Criteria criteria) {
 37         // TODO Auto-generated method stub
 38         return dao.list(criteria);
 39     }
 40 
 41     @Override
 42     public List<T> list(String orderBy, boolean isAsc) {
 43         // TODO Auto-generated method stub
 44         return dao.list(orderBy, isAsc);
 45     }
 46 
 47     @Override
 48     public List<T> list(DetachedCriteria criteria) {
 49         // TODO Auto-generated method stub
 50         return dao.list(criteria);
 51     }
 52 
 53     @Override
 54     public int countAll(Criteria criteria) {
 55         // TODO Auto-generated method stub
 56         return dao.countAll(criteria);
 57     }
 58 
 59     @Override
 60     public int countAll() {
 61         // TODO Auto-generated method stub
 62         return dao.countAll();
 63     }
 64 
 65     @Override
 66     public boolean exists(PK id) {
 67         // TODO Auto-generated method stub
 68         return dao.exists(id);
 69     }
 70 
 71     @Override
 72     @Transactional(propagation = Propagation.REQUIRED)
 73     public void save(T t) {
 74         // TODO Auto-generated method stub
 75         dao.save(t);
 76     }
 77 
 78     @Override
 79     @Transactional(propagation = Propagation.REQUIRED)
 80     public void saveOrUpdate(T t) {
 81         // TODO Auto-generated method stub
 82         dao.saveOrUpdate(t);
 83     }
 84 
 85     @Override
 86     @Transactional(propagation = Propagation.REQUIRED)
 87     public T load(PK id) {
 88         // TODO Auto-generated method stub
 89         return dao.load(id);
 90     }
 91 
 92     @Override
 93     @Transactional(propagation = Propagation.REQUIRED)
 94     public void merge(T entity) {
 95         // TODO Auto-generated method stub
 96         dao.merge(entity);
 97     }
 98 
 99     @Override
100     public List<T> findAll() {
101         // TODO Auto-generated method stub
102         return dao.findAll();
103     }
104 
105     @Override
106     @Transactional(propagation = Propagation.REQUIRED)
107     public T get(PK id) {
108         // TODO Auto-generated method stub
109         return dao.get(id);
110     }
111 
112     @Override
113     public boolean contains(T t) {
114         // TODO Auto-generated method stub
115         return dao.contains(t);
116     }
117 
118     @Override
119     public void delete(T t) {
120         // TODO Auto-generated method stub
121         dao.delete(t);
122     }
123 
124     @Override
125     @Transactional(propagation = Propagation.REQUIRED)
126     public boolean deleteById(PK Id) {
127         // TODO Auto-generated method stub
128         return dao.deleteById(Id);
129     }
130 
131     @Override
132     public void deleteAll(Collection<T> entities) {
133         // TODO Auto-generated method stub
134         dao.deleteAll(entities);
135     }
136 
137     @Override
138     public void queryHql(String hqlString, Object... values) {
139         // TODO Auto-generated method stub
140         dao.queryHql(hqlString, values);
141     }
142 
143     @Override
144     public void querySql(String sqlString, Object... values) {
145         // TODO Auto-generated method stub
146         dao.querySql(sqlString, values);
147     }
148 
149     @Override
150     public T getByHQL(String hqlString, Object... values) {
151         // TODO Auto-generated method stub
152         return dao.getByHQL(hqlString, values);
153     }
154 
155     @Override
156     public List<T> getListByHQL(String hqlString, Object... values) {
157         // TODO Auto-generated method stub
158         return dao.getListByHQL(hqlString, values);
159     }
160 
161     @Override
162     public List<T> getListBySQL(String sqlString, Object... values) {
163         // TODO Auto-generated method stub
164         return dao.getListBySQL(sqlString, values);
165     }
166 
167     @Override
168     public void refresh(T t) {
169         // TODO Auto-generated method stub
170         dao.refresh(t);
171     }
172 
173     @Override
174     @Transactional(propagation = Propagation.REQUIRED)
175     public void update(T t) {
176         // TODO Auto-generated method stub
177         dao.update(t);
178     }
179 
180     @Override
181     public Long countByHql(String hql, Object... values) {
182         // TODO Auto-generated method stub
183         return dao.countByHql(hql, values);
184     }
185 
186     @Override
187     public PageInfo<T> findPageByHql(String hql, String countHql, int pageNo,
188             int pageSize, Object... values) {
189         // TODO Auto-generated method stub
190         return dao.findPageByHql(hql, countHql, pageNo, pageSize, values);
191     }
192 
193     @Override
194     public List<T> list(String propertyName, Object value) {
195         // TODO Auto-generated method stub
196         return dao.list(propertyName, value);
197     }
198 
199     @Override
200     public List<T> list(Criterion criterion) {
201         // TODO Auto-generated method stub
202         return dao.list(criterion);
203     }
204 
205     @Override
206     public List<T> list(Criterion... criterions) {
207         // TODO Auto-generated method stub
208         return dao.list(criterions);
209     }
210 
211     @Override
212     public T uniqueResult(String propertyName, Object value) {
213         // TODO Auto-generated method stub
214         return dao.uniqueResult(propertyName, value);
215     }
216 
217     @Override
218     public T uniqueResult(Criterion... criterions) {
219         // TODO Auto-generated method stub
220         return dao.uniqueResult(criterions);
221     }
222 
223     @Override
224     @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
225     public T uniqueResult(Criteria criteria) {
226         // TODO Auto-generated method stub
227         return dao.uniqueResult(criteria);
228     }
229     
230     @Override
231     @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
232     public Integer uniqueResultInt(Criteria criteria){
233         return dao.uniqueResultInt(criteria);
234     }
235     
236     @Override
237     public Criteria distinct(Criteria criteria) {
238         // TODO Auto-generated method stub
239         return dao.distinct(criteria);
240     }
241 
242     @Override
243     public void flush() {
244         // TODO Auto-generated method stub
245         dao.flush();
246     }
247 
248     @Override
249     public void clear() {
250         // TODO Auto-generated method stub
251         dao.clear();
252     }
253 
254     @Override
255     public Criteria createCriteria() {
256         // TODO Auto-generated method stub
257         return dao.createCriteria();
258     }
259 
260     @Override
261     public Criteria createCriteria(Criterion... criterions) {
262         // TODO Auto-generated method stub
263         return dao.createCriteria(criterions);
264     }
265 
266     @Override
267     public List<T> findPage(Criteria criteria, int pageNo, int pageSize) {
268         // TODO Auto-generated method stub
269         return dao.findPage(criteria, pageNo, pageSize);
270     }
271 
272     @Override
273     public PageInfo<T> findQuery(Criteria criteria, int pageNo, int pageSize) {
274         // TODO Auto-generated method stub
275         return dao.findQuery(criteria, pageNo, pageSize);
276     }
277 
278     @Override
279     public List<T> findQuery(String hql, int pageNo, int pageSize, Map<?, ?> map) {
280         // TODO Auto-generated method stub
281         return dao.findQuery(hql, pageNo, pageSize, map);
282     }
283 
284 }
View Code

 

我将这几个文件保存在如下:

 

我们看到实体包下的各个实体:

 

接下来  自动生成每一层的各个实体对应的相对应的代码文件:【注意在执行之前,查看基础文件位置是否正确/注意基础文件中关于工作包的代码 是否正确】

  1 package com.sxd.utils;
  2 
  3 import java.io.File;
  4 import java.io.FileWriter;
  5 import java.io.IOException;
  6 
  7 import org.junit.Test;
  8 import org.springframework.util.FileCopyUtils;
  9 /**
 10  * 生成dao 、service等代码
 11  * @author Administrator
 12  *
 13  */
 14 public class CreateJava {
 15     
 16     //包名 前半部分[java文件中内容]
 17     private String packPath = "package com.sxd";
 18     //包名  中间部分 例如:com.sxd.entity
 19     private String middlePath = "sxd";
 20     //项目名 用于生成文件的路径
 21     private String productName = "shiro-first";
 22     //dao service等基础的文件存放的路径
 23     private String DaoServicePath = "F:/workspace2/DaoService";
 24     
 25     
 26     
 27     @Test
 28     public void mainTest() throws IOException{
 29         createFiles();//第一步 生成各层文件夹,并从固定位置copy 基础dao,service文件
 30         justCreateJava();//第二步 生成各个实体对应的Dao等层文件
 31     }
 32     
 33     
 34     public void justCreateJava() throws IOException{
 35         File file = new File("F:/workspace2/"+productName+"/src/main/java/com/"+middlePath+"/entity");
 36         File []list = file.listFiles();
 37         for (File file2 : list) {
 38             String fileName = file2.getName().substring(0,file2.getName().lastIndexOf("."));
 39             createDao(fileName);
 40             createDaoImpl(fileName);
 41             createService(fileName);
 42             createServiceImpl(fileName);
 43         }
 44     }
 45     /**
 46      * 创建Dao层
 47      * @param fileName
 48      * @throws IOException 
 49      */
 50     public void createDao(String fileName) throws IOException{
 51         //拼接 DaoImpl内容
 52                 String content = packPath+".dao;\r\n"
 53                         + "\r\n"
 54                         + "import com."+middlePath+".entity."+fileName+";\r\n"
 55                         + "public interface "+fileName+"Dao extends GenericDao<"+fileName+", String> {\r\n"
 56                                 + "\r\n"
 57                                 + "}";
 58                 
 59                 //指定将Dao文件生成到对应的指定位置
 60                 FileWriter writer = new FileWriter(new File("F:/workspace2/"+productName+"/src/main/java/com/"+middlePath+"/dao/"+fileName+"Dao.java"));
 61                 writer.write(content);
 62                 writer.close();
 63     }
 64     
 65     /**
 66      * 创建DaoImpl层
 67      */
 68     public void createDaoImpl(String fileName) throws IOException{
 69         //拼接 DaoImpl内容
 70         String content = packPath+".dao.Impl;\r\n"
 71                 + "\r\n"
 72                 + "import org.springframework.stereotype.Repository;\r\n"
 73                 + "import com."+middlePath+".dao."+fileName+"Dao;\r\n"
 74                 + "import com."+middlePath+".entity."+fileName+";\r\n"
 75                 + "@Repository \r\n"
 76                 + "public class "+fileName+"DaoImpl extends GenericDaoImpl<"+fileName+", String> implements "+fileName+"Dao {\r\n"
 77                         + "\r\n"
 78                 + "}";
 79         
 80         //指定将DaoImpl文件生成到对应的指定位置
 81         FileWriter writer = new FileWriter(new File("F:/workspace2/"+productName+"/src/main/java/com/"+middlePath+"/dao/impl/"+fileName+"DaoImpl.java"));
 82         writer.write(content);
 83         writer.close();
 84     }
 85     
 86     /**
 87      * 创建 Service层
 88      * @param fileName
 89      * @throws IOException
 90      */
 91     public void createService(String fileName) throws IOException{
 92         //拼接Service内容
 93         String content = packPath+".service;\r\n"
 94                 + "import com."+middlePath+".entity."+fileName+";\r\n"
 95                 + "public interface "+fileName+"Service extends GenericService<"+fileName+", String> {\r\n"
 96                         + "\r\n"
 97                         + "}";
 98         
 99         FileWriter writer = new FileWriter(new File("F:/workspace2/"+productName+"/src/main/java/com/"+middlePath+"/service/"+fileName+"Service.java"));
100         writer.write(content);
101         writer.close();
102     }
103     
104     /**
105      * 创建ServiceImpl
106      * @throws IOException 
107      */
108     public void createServiceImpl(String fileName) throws IOException{
109         //拼接Service内容
110                 String content = packPath+".service.Impl;\r\n"
111                         + "import org.springframework.beans.factory.annotation.Autowired;\r\n"
112                         + "import org.springframework.stereotype.Service;\r\n"
113                         + "import com."+middlePath+".dao."+fileName+"Dao;\r\n"
114                         + "import com."+middlePath+".entity."+fileName+";\r\n"
115                         + "import com."+middlePath+".service."+fileName+"Service;\r\n"
116                         + "@Service \r\n"
117                         + "public class "+fileName+"ServiceImpl extends GenericServiceImpl<"+fileName+", String> implements "+fileName+"Service {\r\n"
118                                 + "\r\n"
119                                 + "@Autowired\r\n"
120                                 + "private "+fileName+"Dao dao;\r\n"
121                                 + "}";
122                 FileWriter writer = new FileWriter(new File("F:/workspace2/"+productName+"/src/main/java/com/"+middlePath+"/service/impl/"+fileName+"ServiceImpl.java"));
123                 writer.write(content);
124                 writer.close();
125     }
126     
127     
128     
129     /**
130      * 有了entity之后,创建各层文件夹,同时将 GenericDao等基础类和接口实现
131      * @throws IOException 
132      */
133     public void createFiles() throws IOException{
134         String daoPath = "F:/workspace2/"+productName+"/src/main/java/com/"+middlePath+"/dao";
135         String servicePath = "F:/workspace2/"+productName+"/src/main/java/com/"+middlePath+"/service";
136         /**
137          * 上来先删除掉 如果存在的话
138          */
139         delFolder(daoPath);
140         delFolder(servicePath);
141         
142         /**
143          * 创建文件夹
144          */
145         File file = new File(daoPath);
146         file.mkdirs();
147         File file2 = new File(servicePath);
148         file2.mkdirs();
149         File file3 = new File(daoPath+"/Impl");
150         file3.mkdirs();
151         File file4 = new File(servicePath+"/Impl");
152         file4.mkdirs();
153         copyDaoAndServiceFile(daoPath,servicePath);
154         
155     }
156     
157     //删除文件夹
158     //param folderPath 文件夹完整绝对路径
159 
160          public  void delFolder(String folderPath) {
161          try {
162             delAllFile(folderPath); //删除完里面所有内容
163             String filePath = folderPath;
164             filePath = filePath.toString();
165             java.io.File myFilePath = new java.io.File(filePath);
166             myFilePath.delete(); //删除空文件夹
167          } catch (Exception e) {
168            e.printStackTrace(); 
169          }
170     }
171 
172     //删除指定文件夹下所有文件
173     //param path 文件夹完整绝对路径
174        public  boolean delAllFile(String path) {
175            boolean flag = false;
176            File file = new File(path);
177            if (!file.exists()) {
178              return flag;
179            }
180            if (!file.isDirectory()) {
181              return flag;
182            }
183            String[] tempList = file.list();
184            File temp = null;
185            for (int i = 0; i < tempList.length; i++) {
186               if (path.endsWith(File.separator)) {
187                  temp = new File(path + tempList[i]);
188               } else {
189                   temp = new File(path + File.separator + tempList[i]);
190               }
191               if (temp.isFile()) {
192                  temp.delete();
193               }
194               if (temp.isDirectory()) {
195                  delAllFile(path + "/" + tempList[i]);//先删除文件夹里面的文件
196                  delFolder(path + "/" + tempList[i]);//再删除空文件夹
197                  flag = true;
198               }
199            }
200            return flag;
201          }
202     
203        //将dao等基础文件 拷贝到 项目下固定包中
204        public void copyDaoAndServiceFile(String daoPath,String servicePath) throws IOException{
205            File file1 = new File(daoPath+"/GenericDao.java");
206            if(!file1.exists()){
207                file1.createNewFile();
208            }
209            File file2 = new File(daoPath+"/Impl/GenericDaoImpl.java");
210            if(!file2.exists()){
211                file2.createNewFile();
212            }
213            File file3 = new File(servicePath+"/GenericService.java");
214            if(!file3.exists()){
215                file3.createNewFile();
216            }
217            File file4 = new File(servicePath+"/Impl/GenericServiceImpl.java");
218            if(!file4.exists()){
219                file4.createNewFile();
220            }
221            FileCopyUtils.copy(new File(DaoServicePath+"/GenericDao.java"), file1);
222            FileCopyUtils.copy(new File(DaoServicePath+"/GenericDaoImpl.java"), file2);
223            FileCopyUtils.copy(new File(DaoServicePath+"/GenericService.java"), file3);
224            FileCopyUtils.copy(new File(DaoServicePath+"/GenericServiceImpl.java"), file4);
225            
226        }
227 }
View Code

 

 

生成完刷新

效果如下:

 

相关文章
|
7天前
|
分布式计算 DataWorks Java
DataWorks操作报错合集之在使用MaxCompute的Java SDK创建函数时,出现找不到文件资源的情况,是BUG吗
DataWorks是阿里云提供的一站式大数据开发与治理平台,支持数据集成、数据开发、数据服务、数据质量管理、数据安全管理等全流程数据处理。在使用DataWorks过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
22 0
|
3天前
|
Oracle Java 关系型数据库
windows 下 win11 JDK17安装与环境变量的配置(配置简单详细,包含IJ中java文件如何使用命令运行)
本文介绍了Windows 11中安装JDK 17的步骤,包括从官方网站下载JDK、配置环境变量以及验证安装是否成功。首先,下载JDK 17的安装文件,如果没有Oracle账户,可以直接解压缩文件到指定目录。接着,配置系统环境变量,新建`JAVA_HOME`变量指向JDK安装路径,并在`Path`变量中添加。然后,通过命令行(cmd)验证安装,分别输入`java -version`和`javac -version`检查版本信息。最后,作者分享了如何在任意位置运行Java代码,包括在IntelliJ IDEA(IJ)中创建的Java文件,只需去掉包声明,就可以通过命令行直接运行。
25 0
|
4天前
|
Java Maven
Maven 构建 Java 项目
使用Maven的`maven-archetype-quickstart`插件在C:\MVN下创建Java应用,命令包括`groupId`, `artifactId`, 和 `archetypeArtifactId`参数。生成的项目包含src/main/java和src/test/java目录,分别用于存放源代码和测试代码,还有src/main/resources用于资源文件。默认提供App.java主类和AppTest.java测试类。按照预设结构组织文件,Maven将自动管理构建过程。
|
5天前
|
设计模式 存储 前端开发
18:JavaBean简介及其在表单处理与DAO设计模式中的应用-Java Web
18:JavaBean简介及其在表单处理与DAO设计模式中的应用-Java Web
22 4
|
5天前
|
存储 监控 Java
如何在Java中实现等待文件修改后再读取数据的功能?
如何在Java中实现等待文件修改后再读取数据的功能?
11 0
|
5天前
|
存储 Java 数据格式
Java实战:轻松掌握文件重命名与路径提取技巧
Java实战:轻松掌握文件重命名与路径提取技巧
12 0
|
5天前
|
Java
如何解决使用若依前后端分离打包部署到服务器上后主包无法找到从包中的文件的问题?如何在 Java 代码中访问 jar 包中的资源文件?
如何解决使用若依前后端分离打包部署到服务器上后主包无法找到从包中的文件的问题?如何在 Java 代码中访问 jar 包中的资源文件?
24 0
|
5天前
|
存储 网络协议 Java
本地MinIO存储服务通过Java程序结合cpolar实现远程连接上传文件
本地MinIO存储服务通过Java程序结合cpolar实现远程连接上传文件
|
6天前
|
Java
IDEA云行项目提示Error: java: OutOfMemoryError
IDEA云行项目提示Error: java: OutOfMemoryError
|
7天前
|
存储 Java 开发工具
【Java探索之旅】用面向对象的思维构建程序世界
【Java探索之旅】用面向对象的思维构建程序世界
9 0