分类整理了150个比较好的Android开源项目,已汇总到AndroidOpenProject@Github,欢迎Star和Fork^_*
目前包括:
Android开源项目第一篇——个性化控件(View)篇
包括ListView、ActionBar、Menu、ViewPager、Gallery、GridView、ImageView、ProgressBar等等
Android开源项目第二篇——工具库篇
包括依赖注入框架、图片缓存、网络相关、数据库ORM建模、Android公共库、高版本向低版本兼容库、多媒体等等
Android开源项目第三篇——优秀项目篇
比较有意思的完整的Android项目
Android开源项目第四篇——开发及测试工具篇
包括开发自测、自动化测试、编译打包相关工具
Android开源项目第五篇——优秀个人和团体篇
乐于分享并且有一些很不错的开源项目的个人和组织,包括JakeWharton、Chris Banes、Koushik Dutta等大牛
在SQL语句中如要做统计一般是这种方式:
SELECT ..,SUM(1)
FROM ..
WHERE ..
GROUP BY ..
HAVING ..
SORT ..
在MONGODB中的架构图
在SPRING DATA MONGODB中是这样写的:
public class VideoRepositoryImpl implements VideoRepositoryCustom{
private static Logger logger = LoggerFactory.getLogger(VideoRepositoryImpl.class);
@Autowired
private MongoTemplate mongoTemplate;
public List<Cat1UpdateCount> getVideoWithUpdateFrag(List<String> importantCat1List) {
logger.info(new Date().toString());
/**
* db.videos.aggregate(
[
{ $match: { "frags.isnew" : true } },
{ $unwind: "$frags" },
{ $match: { "frags.isnew" : true } },
{ $group: {
_id: {cat1:"$cat1"},
count: { $sum: 1 },
publishdate2: { $max: "$publishdate"}
}
}
]
)
*/
Aggregation agg = newAggregation(
project("frags","cat1","publishdate"),//挑选所需的字段
match(
Criteria.where("frags.isnew").is(Boolean.TRUE)
.and("cat1").in(importantCat1List)
),//筛选符合条件的记录
unwind("frags"),//如果有MASTER-ITEM关系的表,需同时JOIN这两张表的,展开子项LIST,且是内链接,即如果父和子的关联ID没有的就不会输出
match(Criteria.where("frags.isnew").is(Boolean.TRUE)),
group("cat1")//设置分组字段
.count().as("updateCount")//增加COUNT为分组后输出的字段
.last("publishdate").as("publishDate"),//增加publishDate为分组后输出的字段
project("publishDate","cat1","updateCount")//重新挑选字段
.and("cat1").previousOperation()//为前一操作所产生的ID FIELD建立别名
);
AggregationResults<Cat1UpdateCount> results = mongoTemplate.aggregate(agg, Video.COLLECTION_NAME, Cat1UpdateCount.class);
List<Cat1UpdateCount> cat1UpdateCountList = results.getMappedResults();
return cat1UpdateCountList;
}
}
其中frags的数据类型是LIST
Cat1UpdateCount.java
import java.io.Serializable;
public class Cat1UpdateCount implements Serializable{
private static final long serialVersionUID = 4240876746984930098L;
private String cat1;
private int updateCount;
private String publishDate;
public String getCat1() {
return cat1;
}
public void setCat1(String cat1) {
this.cat1 = cat1;
}
public int getUpdateCount() {
return updateCount;
}
public void setUpdateCount(int updateCount) {
this.updateCount = updateCount;
}
public String getPublishDate() {
return publishDate;
}
public void setPublishDate(String publishDate) {
this.publishDate = publishDate;
}
public String toString() {
return "Cat1UpdateCount [cat1=" + cat1 + ", updateCount=" + updateCount
+ ", publishDate=" + publishDate + "]";
}
}
参考:
http://docs.spring.io/spring-data/data-mongodb/docs/current/reference/htmlsingle/#mongo.grouphttp://docs.mongodb.org/manual/reference/operator/aggregation/group/http://docs.mongodb.org/manual/reference/sql-aggregation-comparison/
自从用了SPRING DATA MONGODB后,增删改查的实现方法都不用自己写了,只需声明方法名称,SPRING会自动添加代码,但用时候SPRING自带的方法不够,难免要添加的,因此如何在原有的方法上叠加自定义的方法呢?
定义自定义的接口
public interface VideoRepositoryCustom {
public List<Cat1UpdateCount> getVideoWithUpdateFrag(List<String> importantCat1List);
}
添加自定义的实现
import static org.springframework.data.mongodb.core.aggregation.Aggregation.group;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.match;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.project;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.unwind;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import program.video.aggregation.valueobject.Cat1UpdateCount;
import program.video.valueobject.Video;
public class VideoRepositoryImpl implements VideoRepositoryCustom{
private static Logger logger = LoggerFactory.getLogger(VideoRepositoryImpl.class);
@Autowired
private MongoTemplate mongoTemplate;
public List<Cat1UpdateCount> getVideoWithUpdateFrag(List<String> importantCat1List) {
logger.info(new Date().toString());
/**
* db.videos.aggregate(
[
{ $match: { "frags.isnew" : true } },
{ $unwind: "$frags" },
{ $match: { "frags.isnew" : true } },
{ $group: {
_id: {cat1:"$cat1"},
count: { $sum: 1 },
publishdate2: { $max: "$publishdate"}
}
}
]
)
*/
Aggregation agg = newAggregation(
project("frags","cat1","publishdate"),
match(
Criteria.where("frags.isnew").is(Boolean.TRUE)
.and("cat1").in(importantCat1List)
),
unwind("frags"),//展开子项LIST,且是内链接,即如果父和子的关联ID没有的就不会输出
match(Criteria.where("frags.isnew").is(Boolean.TRUE)),
group("cat1")//设置分组字段
.count().as("updateCount")//增加COUNT为分组字段
.last("publishdate").as("publishDate"),//增加publishDate为分组字段
project("publishDate","cat1","updateCount")//重新挑选字段
.and("cat1").previousOperation()//为前一操作所产生的ID FIELD建立别名
);
AggregationResults<Cat1UpdateCount> results = mongoTemplate.aggregate(agg, Video.COLLECTION_NAME, Cat1UpdateCount.class);
List<Cat1UpdateCount> cat1UpdateCountList = results.getMappedResults();
return null;
}
}
原先的接口实现多重继承
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import program.video.valueobject.Video;
public interface VideoRepository extends PagingAndSortingRepository<Video, String>,VideoRepositoryCustom {
@Query("{ title : {$regex : ?0 } }")
public Page<Video> findVideosByKeyword(@Param("title") String keyword, Pageable page);
@Query("{ pid : ?0 }")
public Video findByVideoId(String id);
@Query(value="{ pid : ?0 , ver: { $gt : ?1 }}")
public Video findByIdAndVersion(String id, int ver);
public Page<Video> findByTitleLike(String title, Pageable pageable);
@Query("{ title : {$regex : ?0}, cat1 : ?1}")
public Page<Video> findVideosByTitleAndCat1(String title, String cat1, Pageable pageable);
@Query("{ cat1 : ?0}")
public Page<Video> findVideosByCat1(String cat1, Pageable pageable);
@Query("{ title : {$regex : ?0}, cat1 : ?1, status : ?2}")
public Page<Video> findVideosByTitleAndCat1AndStatus(String title, String cat1, int status, Pageable pageable);
@Query("{ title : {$regex : ?0}, cat1 : ?1, status : { $in : [ ?2, null]}}")
public Page<Video> findVideosByTitleAndCat1AndStatusExist(String title, String cat1, int status, Pageable pageable);
@Query("{ title : {$regex : ?0}, status : ?1}")
public Page<Video> findVideosByTitleAndStatus(String title, int status, Pageable pageable);
@Query("{ title : {$regex : ?0}, status : { $in : [ ?1, null]}}")
public Page<Video> findVideosByTitleAndStatusExist(String title, int status, Pageable pageable);
@Query("{ cat1 : ?0, status : ?1}")
public Page<Video> findVideosByCat1AndStatus(String cat1, int status, Pageable pageable);
@Query("{ cat1 : ?0, status : { $in : [ ?1, null]}}")
public Page<Video> findVideosByCat1AndStatusExist(String cat1, int status, Pageable pageable);
@Query("{ status : ?0}")
public Page<Video> findVideosByStatus(int status, Pageable pageable);
@Query("{status : { $in : [ ?0, null]}}")
public Page<Video> findVidesByStatusExist(int status, Pageable pageable);
}
SPRING DATA 配置文件
<?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.3.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- To translate any MongoExceptions thrown in @Repository annotated classes -->
<context:annotation-config />
<context:property-placeholder location="classpath*:/properties/mongodb/mongo.properties"/>
<!-- Default bean name is 'mongo' -->
<mongo:mongo host="${mongo.host}" port="${mongo.port}">
<mongo:options connections-per-host="${mongo.connectionsPerHost}"
threads-allowed-to-block-for-connection-multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}"
connect-timeout="${mongo.connectTimeout}" max-wait-time="${mongo.maxWaitTime}"
auto-connect-retry="${mongo.autoConnectRetry}" socket-keep-alive="${mongo.socketKeepAlive}"
socket-timeout="${mongo.socketTimeout}" slave-ok="${mongo.slaveOk}"
write-number="1" write-timeout="0" write-fsync="true" />
</mongo:mongo>
<!-- <mongo:db-factory
dbname="${mongo.dbname}"
username="${mongo.username}"
password="${mongo.password}"
mongo-ref="mongo" /> -->
<mongo:db-factory
dbname="${mongo.dbname}"
mongo-ref="mongo" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
</bean>
<mongo:repositories base-package="com.tcl.project7.boss.**.repository" />
</beans>
注意的是,自定义的实现类要以IMPL后缀,则SPRING可以自动识别的,无需再指定了。
调用REPOSITORY
@Autowired
private VideoRepository videoRepository;
第一步:找到C:\WINDOWS\system32\drivers\etc里面的hosts文件,双击打开,选用记事本打开。
第二步:把下面的代码复制到文件中并保存
#优酷
127.0.0.1 atm.youku.com
127.0.0.1 Fvid.atm.youku.com
127.0.0.1 html.atm.youku.com
127.0.0.1 valb.atm.youku.com
127.0.0.1 valf.atm.youku.com
127.0.0.1 valo.atm.youku.com
127.0.0.1 valp.atm.youku.com
127.0.0.1 lstat.youku.com
127.0.0.1 speed.lstat.youku.com
127.0.0.1 urchin.lstat.youku.com
127.0.0.1 stat.youku.com
127.0.0.1 static.lstat.youku.com
127.0.0.1 valc.atm.youku.com
127.0.0.1 vid.atm.youku.com
127.0.0.1 walp.atm.youku.com
#百度:
127.0.0.1 a.baidu.com
127.0.0.1 baidutv.baidu.com
127.0.0.1 bar.baidu.com
127.0.0.1 c.baidu.com
127.0.0.1 cjhq.baidu.com
127.0.0.1 cpro.baidu.com
127.0.0.1 drmcmm.baidu.com
127.0.0.1 e.baidu.com
127.0.0.1 eiv.baidu.com
127.0.0.1 hc.baidu.com
127.0.0.1 hm.baidu.com
127.0.0.1 ma.baidu.com
127.0.0.1 nsclick.baidu.com
127.0.0.1 spcode.baidu.com
127.0.0.1 tk.baidu.com
127.0.0.1 union.baidu.com
127.0.0.1 ucstat.baidu.com
127.0.0.1 utility.baidu.com
127.0.0.1 utk.baidu.com
127.0.0.1 focusbaiduafp.allyes.com
#奇艺
127.0.0.1 afp.qiyi.com
127.0.0.1 focusbaiduafp.allyes.com
#CNTV
127.0.0.1 a.cctv.com
127.0.0.1 a.cntv.cn
127.0.0.1 ad.cctv.com
127.0.0.1 d.cntv.cn
127.0.0.1 adguanggao.eee114.com
127.0.0.1 cctv.adsunion.com
#新浪视频
127.0.0.1 dcads.sina.com.cn
#pptv
127.0.0.1 pp2.pptv.com
#乐视
127.0.0.1 pro.letv.com
#搜狐高清
127.0.0.1 images.sohu.com
@HostsX 国内站点广告/视频类网站
#CNTV
127.0.0.1 a.cctv.com
127.0.0.1 a.cntv.cn
127.0.0.1 ad.cctv.com
127.0.0.1 d.cntv.cn
127.0.0.1 adguanggao.eee114.com
127.0.0.1 cctv.adsunion.com
#我乐网
127.0.0.1 acs.56.com
127.0.0.1 acs.agent.56.com
127.0.0.1 acs.agent.v-56.com
127.0.0.1 bill.agent.56.com
127.0.0.1 bill.agent.v-56.com
127.0.0.1 stat.56.com
127.0.0.1 stat2.corp.56.com
127.0.0.1 union.56.com
127.0.0.1 uvimage.56.com
127.0.0.1 v16.56.com
#6间房
127.0.0.1 pole.6rooms.com
127.0.0.1 shrek.6.cn
127.0.0.1 simba.6.cn
127.0.0.1 union.6.cn
#土豆网
127.0.0.1 adextensioncontrol.tudou.com
127.0.0.1 iwstat.tudou.com
127.0.0.1 nstat.tudou.com
127.0.0.1 stats.tudou.com
127.0.0.1 *.p2v.tudou.com*
127.0.0.1 at-img1.tdimg.com
127.0.0.1 at-img2.tdimg.com
127.0.0.1 at-img3.tdimg.com
127.0.0.1 adplay.tudou.com
127.0.0.1 adcontrol.tudou.com
127.0.0.1 stat.tudou.com
#酷6网
127.0.0.1 1.allyes.com.cn
127.0.0.1 analytics.ku6.com
127.0.0.1 gug.ku6cdn.com
127.0.0.1 ku6.allyes.com
127.0.0.1 ku6afp.allyes.com
127.0.0.1 pq.stat.ku6.com
127.0.0.1 st.vq.ku6.cn
127.0.0.1 stat0.888.ku6.com
127.0.0.1 stat1.888.ku6.com
127.0.0.1 stat2.888.ku6.com
127.0.0.1 stat3.888.ku6.com
127.0.0.1 static.ku6.com
127.0.0.1 v0.stat.ku6.com
127.0.0.1 v1.stat.ku6.com
127.0.0.1 v2.stat.ku6.com
127.0.0.1 v3.stat.ku6.com
#激动网
127.0.0.1 86file.megajoy.com
127.0.0.1 86get.joy.cn
127.0.0.1 86log.joy.cn
#天线视频
127.0.0.1 casting.openv.com
127.0.0.1 m.openv.tv
127.0.0.1 uniclick.openv.com
#迅雷看看屏蔽:
127.0.0.1 mcfg.sandai.net
127.0.0.1 biz5.sandai.net
127.0.0.1 server1.adpolestar.net
127.0.0.1 advstat.xunlei.com
127.0.0.1 mpv.sandai.net
从Maven仓库中导出jar包:
进入工程pom.xml 所在的目录下,输入以下命令:
mvn dependency:copy-dependencies -DoutputDirectory=lib
lib为导出的目标文件夹