forked from sdksdk0/taotaoMalls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
459 additions
and
10 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
taotao-common/src/main/java/cn/tf/taotao/common/utils/ExceptionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cn.tf.taotao.common.utils; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
|
||
public class ExceptionUtil { | ||
|
||
/** | ||
* 获取异常的堆栈信息 | ||
* | ||
* @param t | ||
* @return | ||
*/ | ||
public static String getStackTrace(Throwable t) { | ||
StringWriter sw = new StringWriter(); | ||
PrintWriter pw = new PrintWriter(sw); | ||
|
||
try { | ||
t.printStackTrace(pw); | ||
return sw.toString(); | ||
} finally { | ||
pw.close(); | ||
} | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
taotao-common/src/main/java/cn/tf/taotao/common/utils/HttpClientUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package cn.tf.taotao.common.utils; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.http.NameValuePair; | ||
import org.apache.http.client.entity.UrlEncodedFormEntity; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.client.utils.URIBuilder; | ||
import org.apache.http.entity.ContentType; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.message.BasicNameValuePair; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
public class HttpClientUtil { | ||
|
||
public static String doGet(String url, Map<String, String> param) { | ||
|
||
// 创建Httpclient对象 | ||
CloseableHttpClient httpclient = HttpClients.createDefault(); | ||
|
||
String resultString = ""; | ||
CloseableHttpResponse response = null; | ||
try { | ||
// 创建uri | ||
URIBuilder builder = new URIBuilder(url); | ||
if (param != null) { | ||
for (String key : param.keySet()) { | ||
builder.addParameter(key, param.get(key)); | ||
} | ||
} | ||
URI uri = builder.build(); | ||
|
||
// 创建http GET请求 | ||
HttpGet httpGet = new HttpGet(uri); | ||
|
||
// 执行请求 | ||
response = httpclient.execute(httpGet); | ||
// 判断返回状态是否为200 | ||
if (response.getStatusLine().getStatusCode() == 200) { | ||
resultString = EntityUtils.toString(response.getEntity(), "UTF-8"); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} finally { | ||
try { | ||
if (response != null) { | ||
response.close(); | ||
} | ||
httpclient.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return resultString; | ||
} | ||
|
||
public static String doGet(String url) { | ||
return doGet(url, null); | ||
} | ||
|
||
public static String doPost(String url, Map<String, String> param) { | ||
// 创建Httpclient对象 | ||
CloseableHttpClient httpClient = HttpClients.createDefault(); | ||
CloseableHttpResponse response = null; | ||
String resultString = ""; | ||
try { | ||
// 创建Http Post请求 | ||
HttpPost httpPost = new HttpPost(url); | ||
// 创建参数列表 | ||
if (param != null) { | ||
List<NameValuePair> paramList = new ArrayList<>(); | ||
for (String key : param.keySet()) { | ||
paramList.add(new BasicNameValuePair(key, param.get(key))); | ||
} | ||
// 模拟表单 | ||
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList); | ||
httpPost.setEntity(entity); | ||
} | ||
// 执行http请求 | ||
response = httpClient.execute(httpPost); | ||
resultString = EntityUtils.toString(response.getEntity(), "utf-8"); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} finally { | ||
try { | ||
response.close(); | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
return resultString; | ||
} | ||
|
||
public static String doPost(String url) { | ||
return doPost(url, null); | ||
} | ||
|
||
public static String doPostJson(String url, String json) { | ||
// 创建Httpclient对象 | ||
CloseableHttpClient httpClient = HttpClients.createDefault(); | ||
CloseableHttpResponse response = null; | ||
String resultString = ""; | ||
try { | ||
// 创建Http Post请求 | ||
HttpPost httpPost = new HttpPost(url); | ||
// 创建请求内容 | ||
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); | ||
httpPost.setEntity(entity); | ||
// 执行http请求 | ||
response = httpClient.execute(httpPost); | ||
resultString = EntityUtils.toString(response.getEntity(), "utf-8"); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} finally { | ||
try { | ||
response.close(); | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
return resultString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
taotao-manager/taotao-manager-web/src/main/resources/resource/db.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
jdbc.driver=com.mysql.jdbc.Driver | ||
jdbc.url=jdbc:mysql://qdm11501120.my3w.com:3306/qdm11501120_db?characterEncoding=utf-8 | ||
jdbc.username=qdm11501120 | ||
jdbc.password=admin123 | ||
jdbc.url=jdbc:mysql://localhost:3306/taotao?characterEncoding=utf-8 | ||
jdbc.username=zp | ||
jdbc.password=a |
2 changes: 1 addition & 1 deletion
2
...manager-web/src/main/webapp/META-INF/maven/cn.tf.taotao/taotao-manager-web/pom.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 24 additions & 1 deletion
25
taotao-portal/src/main/java/cn/tf/taotao/portal/controller/IndexController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
package cn.tf.taotao.portal.controller; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import cn.tf.taotao.common.utils.TaotaoResult; | ||
import cn.tf.taotao.portal.service.ContentService; | ||
|
||
|
||
@Controller | ||
public class IndexController { | ||
|
||
@Autowired | ||
private ContentService contentService; | ||
|
||
|
||
@RequestMapping("/index") | ||
public String showIndex(){ | ||
public String showIndex(Model model){ | ||
String adResult = contentService.getContentList(); | ||
model.addAttribute("ad1", adResult); | ||
|
||
return "index"; | ||
} | ||
|
||
//模拟post请求 | ||
@RequestMapping(value="/httpclient/post",method=RequestMethod.POST) | ||
@ResponseBody | ||
public String tesePost(String username,String password){ | ||
return username+"_"+password; | ||
} | ||
|
||
|
||
|
||
} |
6 changes: 6 additions & 0 deletions
6
taotao-portal/src/main/java/cn/tf/taotao/portal/service/ContentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package cn.tf.taotao.portal.service; | ||
|
||
public interface ContentService { | ||
String getContentList(); | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
taotao-portal/src/main/java/cn/tf/taotao/portal/service/impl/ContentServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cn.tf.taotao.portal.service.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import cn.tf.taotao.common.utils.HttpClientUtil; | ||
import cn.tf.taotao.common.utils.JsonUtils; | ||
import cn.tf.taotao.common.utils.TaotaoResult; | ||
import cn.tf.taotao.po.TbContent; | ||
import cn.tf.taotao.portal.service.ContentService; | ||
|
||
@Service | ||
public class ContentServiceImpl implements ContentService{ | ||
|
||
|
||
@Value("${REST_BASE_URL}") | ||
private String REST_BASE_URL; | ||
@Value("${REST_INDEX_AD_URL}") | ||
private String REST_INDEX_AD_URL; | ||
|
||
|
||
|
||
@Override | ||
public String getContentList() { | ||
String result = HttpClientUtil.doGet(REST_BASE_URL + REST_INDEX_AD_URL); | ||
//把json数据转换成对象 | ||
TaotaoResult taotaoResult = TaotaoResult.formatToList(result, TbContent.class); | ||
List<TbContent> list = (List<TbContent>) taotaoResult.getData(); | ||
List<Map> resultList=new ArrayList<>(); | ||
|
||
try { | ||
for (TbContent tbContent : list) { | ||
Map map = new HashMap<>(); | ||
map.put("src", tbContent.getPic()); | ||
map.put("height", 240); | ||
map.put("width", 670); | ||
map.put("srcB", tbContent.getPic2()); | ||
map.put("widthB", 550); | ||
map.put("height", 240); | ||
map.put("href", tbContent.getUrl()); | ||
map.put("alt", tbContent.getSubTitle()); | ||
resultList.add(map); | ||
} | ||
return JsonUtils.objectToJson(resultList); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
Empty file.
2 changes: 2 additions & 0 deletions
2
taotao-portal/src/main/resources/resource/resource.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
REST_BASE_URL=http://localhost:8084/rest | ||
REST_INDEX_AD_URL=/content/list/89 |
2 changes: 1 addition & 1 deletion
2
taotao-portal/src/main/webapp/META-INF/maven/cn.tf.taotao/taotao-portal/pom.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.