Ⅰ 怎么将百度翻译api调用进数据库
最近项目要用到一点翻译的功能,使用网络翻译api
有使用上的限制,对我来说已经够用了接口限制
网络翻译API的使用频率默认限制为每个IP 1000次/小时。
如果该频率不能满足您的使用需求,请联系:[email protected]。
项目中使用gson来解析返回的json数据
import java.util.List;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import com.google.gson.Gson;
/**
* @author Ericlin
*
* 2013-9-25
*/
public class Bai {
private static String url ="http://openapi..com/public/2.0/bmt/translate";
private static String api_key ="****************";
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(url);
method.setQueryString(new NameValuePair[] {
new NameValuePair("from","zh"),
new NameValuePair("to","en"),
new NameValuePair("client_id", api_key),
// 多条内容用
分隔
new NameValuePair("q","【微语】任何一件无缝的天衣,都需要你一针一线认真缝合。
海天盛宴大野模,土包子眼中的白富美。") });
client.executeMethod(method);
String response = new String(method.getResponseBodyAsString());
System.out.println(response);
method.releaseConnection();
Gson gson = new Gson();
BaiTrans bt = gson.fromJson(response, BaiTrans.class);
for (TransResult tr : bt.getTrans_result()) {
System.out.println(tr.getDst());
}
}
class BaiTrans {
private String from;
private String to;
private List<TransResult> trans_result;
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public List<TransResult> getTrans_result() {
return trans_result;
}
public void setTrans_result(List<TransResult> trans_result) {
this.trans_result = trans_result;
}
}
class TransResult {
public String getSrc() {
return src;
}
public void setSrc(String src) {
this.src = src;
}
public String getDst() {
return dst;
}
public void setDst(String dst) {
this.dst = dst;
}
private String src;
private String dst;
}
}
Ⅱ javaAPI文档里的这句话怎么翻译
String greet="hello";
int cp=greet.offsetByCodePoints(1,4);
System.out.println(cp);
输出结果是5,
public int offsetByCodePoints(int index,
int codePointOffset)
返回此 String 中从给定的 index 处偏移 codePointOffset 个代码点的索引。
文本范围内由 index 和 codePointOffset 给定的未配对代理项各计为一个代码点
个人理解,就是从这个字符串,index为1的点开始,正向偏移4之后的索引号
所以就是5了……
Ⅲ 求java API 1.8的中文帮助文档
记得我回答过类似的问题,第一个链接里面有Java 1.8的,但是是英文版的,1.6有中文版的
http://javadoc.allimant.org/
JDK1.6API中文版(全)
————————-
* HTML 格式(在线英文) http://java.sun.com/javase/6/docs/
* HTML 格式(在线中文) http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/html/zh_CN/api/index.html
* zip 格式(中文) http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/html_zh_CN.zip
* CHM 格式(中文) http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/chm/JDK_API_1_6_zh_CN.CHM
JDK1.5API中文版(全)
————————-
* HTML 格式(在线英文) http://java.sun.com/javase/5/docs/
* HTML 格式(在线中文) http://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/index.html
* zip 格式(中文) http://gceclub.sun.com.cn/Java_Docs/html_zh_CN.zip
* CHM 格式(中文) http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/builds/JDK_API_1_5_zh_CN.CHM
目前在 http://developers.sun.com.cn 已正式宣布发布Java SE 6 API 中文版。
大家也可以从以下网址下载:
* HTML 格式 ( http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/html/zh_CN/api/index.html )
* zip 格式 ( http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/html_zh_CN.zip )
* CHM 格式 ( http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/chm/JDK_API_1_6_zh_CN.CHM )