Skip to content

Commit

Permalink
<li>新增Redis的操作</li>
Browse files Browse the repository at this point in the history
<li>Aop操作Redis(find ? [get redis] : [push redis and return] )</li>
<li>强大的代码生成器,部分通用代码通过配置,直接生成,方便的不要不要的</li>
<li>JSON在线序列化,基佬在也不用担心截图的JSON不整齐了</li>
<li>新浪微博,博主发帖评论的爬虫抓取,各位客官悠着点别被封IP了</li>
<li>强大的Mycat,数据库中间件,Solr搜索查询,玩命开发中.....</li>
<li>Spring大家族的SpringFOX在线文档,目前未提供生成静态的.卖命开发中...</li>
  • Loading branch information
memmsc committed Oct 18, 2016
1 parent 57bad40 commit 38cad70
Show file tree
Hide file tree
Showing 97 changed files with 40,367 additions and 24 deletions.
31 changes: 28 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<poi.version>3.10-FINAL</poi.version>
<commons-lang3.version>3.4</commons-lang3.version>
<commons-io.version>2.4</commons-io.version>
<commons-codec.version>1.8</commons-codec.version>
<commons-fileupload.version>1.3.1</commons-fileupload.version>
<commons-beanutils.version>1.8.3</commons-beanutils.version>
<commons-collections.version>3.2.2</commons-collections.version>
Expand Down Expand Up @@ -300,15 +299,41 @@
<artifactId>easypoi-annotation</artifactId>
<version>2.3.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>


<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.20</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>cn.edu.hfut.dmic.webcollector</groupId>
<artifactId>WebCollector</artifactId>
<version>2.09</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>

<build>
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/battcn/framework/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.battcn.framework;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableWebMvc
@EnableSwagger2
@ComponentScan(basePackages = {"com.battcn.platform.controller" })
public class SwaggerConfig
{
@Bean
public Docket customDocket()
{
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
}

private ApiInfo apiInfo()
{
ApiInfo apiInfo = new ApiInfo("Battcn接口文档", "Battcn是鏖战八方的一个开源项目,里面的内容包含框架,工具,适合新手以及刚工作不久的人,希望能帮助到大家",
"battcn2.0", "My Apps API terms of service",
new Contact("鏖战八方", "http://www.battcn.com", "[email protected]"), "加入我们", "http://www.battcn.com");
return apiInfo;
}
}
119 changes: 119 additions & 0 deletions src/main/java/com/battcn/framework/jsoup/sina/SinaInitMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.battcn.framework.jsoup.sina;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
* @ClassName: SinaInitMethod
* @author 唐亚峰
* @date 2016年10月17日
*/
public class SinaInitMethod
{

/**
* 接口调用 GET
*/
public static String getSinaReview(String urlStr,String cookie)
{
StringBuilder sb = new StringBuilder();
try
{
URL url = new URL(urlStr); // 把字符串转换为URL请求地址
HttpURLConnection connection = (HttpURLConnection) url.openConnection();// 打开连接
connection.setRequestProperty("Connection", "keep-alive");
connection.setRequestProperty("Cookie",cookie);
connection.connect();// 连接会话
// 获取输入流
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;

while ((line = br.readLine()) != null)
{// 循环读取流
sb.append(line);
}
br.close();// 关闭流
connection.disconnect();// 断开连接
} catch (Exception e)
{
e.printStackTrace();
System.out.println("失败!");
}
return sb.toString();
}

public static List<SinaReview> sina(String id,int page,String cookie)
{
//这里的地址,需要玩爬虫的自己去找个微博博主的微博点开就有了,为了被封号 我肯定不敢吧自己的提供给你们,Cookie会开发的都会用浏览器Copy出来O(∩_∩)O哈哈~
String url = "http://weibo.com/aj/v6/comment/big?ajwvr=6&id="+id+"&page=" + page;
String review = getSinaReview(url,cookie);
JSONObject json = JSON.parseObject(review);
JSONObject data = json.getJSONObject("data");
// System.out.println(data);
// Integer count = data.getInteger("count");
// JSONObject page = data.getJSONObject("page");
// Integer pageNum = page.getInteger("pagenum");
// Integer totalPage = page.getInteger("totalpage");
String html = data.getString("html");
Document doc = Jsoup.parse(html);
Elements ee = doc.getElementsByAttribute("comment_id");
List<SinaReview> list = new ArrayList<SinaReview>();
SinaReview sinaReview = null;
for (Element el : ee)
{
sinaReview = new SinaReview();
String commentId = Jsoup.parse(el.outerHtml()).getElementsByTag("div").attr("comment_id");
Element efl = el.getElementsByClass("W_fl").first();
String commentUrl = efl.getElementsByTag("a").attr("abs:href");
String image = efl.getElementsByTag("img").attr("src");
String userCard = efl.getElementsByTag("img").attr("usercard");
String comment = el.getElementsByClass("WB_text").first().text();
sinaReview.setBlog("邓超");
sinaReview.setCommentId(commentId);
sinaReview.setCommentUrl(commentUrl);
sinaReview.setComment(comment);
sinaReview.setImage(image);
sinaReview.setTitle("从你的全世界路过");
sinaReview.setUserCard(userCard);
list.add(sinaReview);
}
return list;
}

public void init()
{
Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
/*MybatisSqlDao mybatisSqlDao = (MybatisSqlDao) AppContextUtil.getBean("mybatisSqlDaoImpl");
for (int i = 1; i < 956; i++)
{
List<SinaReview> list = sina("1111111111111111",i,"cookie");
if (list != null && list.size() > 0)
try
{
mybatisSqlDao.batchSave("com.battcn.platform.mapper.sina.SinaMapper.batchAddSina", list);
} catch (Exception e)
{
System.out.println("[error] - [批量添加错误] - [错误信息:]"+e.getMessage());
}
}*/
}
});
thread.start();
}
}
112 changes: 112 additions & 0 deletions src/main/java/com/battcn/framework/jsoup/sina/SinaReview.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.battcn.framework.jsoup.sina;

import java.util.Date;

/**
* @ClassName: SinaReview
* @author 唐亚峰
* @date 2016年10月14日
*/
public class SinaReview
{
private Long id;
private String blog;// 博主
private String title;// 标题
private String commentId;// 公共的微博ID
private String commentUrl;// 用户微博地址
private String userCard;// 用户标示
private String image;// 微博用户的头像
private String comment;// 微博用户的留言
private Date date;

public Long getId()
{
return id;
}

public void setId(Long id)
{
this.id = id;
}

public String getBlog()
{
return blog;
}

public void setBlog(String blog)
{
this.blog = blog;
}

public String getTitle()
{
return title;
}

public void setTitle(String title)
{
this.title = title;
}

public String getCommentId()
{
return commentId;
}

public void setCommentId(String commentId)
{
this.commentId = commentId;
}

public String getCommentUrl()
{
return commentUrl;
}

public void setCommentUrl(String commentUrl)
{
this.commentUrl = commentUrl;
}

public String getUserCard()
{
return userCard;
}

public void setUserCard(String userCard)
{
this.userCard = userCard;
}

public String getImage()
{
return image;
}

public void setImage(String image)
{
this.image = image;
}

public String getComment()
{
return comment;
}

public void setComment(String comment)
{
this.comment = comment;
}

public Date getDate()
{
return date;
}

public void setDate(Date date)
{
this.date = date;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.battcn.framework.mybatis.dao;

import java.util.List;

public interface MybatisSqlDao
{

Expand All @@ -13,6 +15,9 @@ public interface MybatisSqlDao
*/
public Object save(String str, Object obj) ;


public Object batchSave(String str, List<?> list) throws Exception ;

/**
* 修改对象
* @param str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class SecondLevelCached
public static final int CACHED_DB_INDEX = 1;
public static final String SYS_MANAGER_KEY = "sys:manager:";

public static final int CACHED_DB_INDEX_CODE_GENERATOR = 2;
public static final String SYS_MANAGER_KEY_GENERATOR = "code:generator";
public static final String SYS_MANAGER_LONG_ID = "code:generator:id";

public static RedisOperator getRedisClient(){
return (RedisOperator)AppContextUtil.getBean("battcnRedisClient");
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/battcn/platform/controller/BaseController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.battcn.platform.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.battcn.platform.service.pub.MenuService;
import com.battcn.platform.service.pub.RoleOperateService;

Expand All @@ -24,7 +26,14 @@ public class BaseController
*/
public String getParameter(String key)
{
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
return request.getParameter(key);
return this.getRequest().getParameter(key);
}
/**
* 得到request对象
*/
public HttpServletRequest getRequest()
{
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
return request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import com.alibaba.fastjson.JSONObject;

import springfox.documentation.annotations.ApiIgnore;

/**
* @ClassName: SystemController
* @Description: 系统监控
Expand All @@ -24,6 +26,7 @@
*/
@Controller
@RequestMapping("/system")
@ApiIgnore
public class SystemController
{
@Autowired
Expand Down
Loading

0 comments on commit 38cad70

Please sign in to comment.