JavaEx博客广场

BigDecimal比较大小BigDecimal a = new BigDecimal("10");BigDecimal b = new BigDecimal("100");// 使用compareTo方法比较if (a.compareTo(b)==-1) { System.out.println("ab");}if (a.compareTo(b)==0) { System.out.println("a==b");}if (a.compareTo(b)==1) { System.out.println("ab");}BigDecimal加减乘除BigDecimal num1 = new BigDecimal("10");BigDecimal num2 = new BigDecimal("100");BigDecimal num3 = null;// 加法num3 = num1.add(num2);System.out.println("加法,和 是:" + num3); // 加法,和 是:110// 减法num3 = num1.subtract(num2);System.out.println("减法,差是:" + num3); // 减法,差是:-90// 乘法num3 = num1.multiply(num2);System.out.println("乘法,积是:" + num3); // 乘法,积是:1000// 除法num3 = num1.divide(num2);System.out.println("除法,商是:" + num3); // 除法,商是:0.1
1、官方文档:https://market.aliyun.com/products/57002002/cmapi014969.html2、添加Maven依赖!-- httpclient --dependency groupIdorg.apache.httpcomponents/groupId httpclient version4.2.1/version/dependency3、获取HttpUtils类地址:https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.javapackage cn.javaex.hgo.util;import java.io.UnsupportedEncodingException;import java.net.URLEncoder;import java.security.KeyManagementException;import java.security.NoSuchAlgorithmException;import java.security.cert.X509Certificate;import java.util.ArrayList;import java.util.List;import java.util.Map;import javax.net.ssl.SSLContext;import javax.net.ssl.TrustManager;import javax.net.ssl.X509TrustManager;import org.apache.commons.lang.StringUtils;import org.apache.http.HttpResponse;import org.apache.http.NameValuePair;import org.apache.http.client.HttpClient;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpDelete;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.client.methods.HttpPut;import org.apache.http.conn.ClientConnectionManager;import org.apache.http.conn.scheme.Scheme;import org.apache.http.conn.scheme.SchemeRegistry;import org.apache.http.conn.ssl.SSLSocketFactory;import org.apache.http.entity.ByteArrayEntity;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.message.BasicNameValuePair;public class HttpUtils { /** * get * * @param host * @param path * @param method * @param headers * @param querys * @return * @throws Exception */ public static HttpResponse doGet(String host, String path, String method, MapString, String headers, MapString, String querys) throws Exception { HttpClient httpClient = wrapClient(host); HttpGet request = new HttpGet(buildUrl(host, path, querys)); for (Map.EntryString, String e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } return httpClient.execute(request); } /** * post form * * @param host * @param path * @param method * @param headers * @param querys * @param bodys * @return * @throws Exception */ public static HttpResponse doPost(String host, String path, String method, MapString, String headers, MapString, String querys, MapString, String bodys) throws Exception { HttpClient httpClient = wrapClient(host); HttpPost request = new HttpPost(buildUrl(host, path, querys)); for (Map.EntryString, String e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (bodys != null) { ListNameValuePair nameValuePairList = new ArrayListNameValuePair(); for (String key : bodys.keySet()) { nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key))); } UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8"); formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); request.setEntity(formEntity); } return httpClient.execute(request); } /** * Post String * * @param host * @param path * @param method * @param headers * @param querys * @param body * @return * @throws Exception */ public static HttpResponse doPost(String host, String path, String method, MapString, String headers, MapString, String querys, String body) throws Exception { HttpClient httpClient = wrapClient(host); HttpPost request = new HttpPost(buildUrl(host, path, querys)); for (Map.EntryString, String e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (StringUtils.isNotBlank(body)) { request.setEntity(new StringEntity(body, "utf-8")); } return httpClient.execute(request); } /** * Post stream * * @param host * @param path * @param method * @param headers * @param querys * @param body * @return * @throws Exception */ public static HttpResponse doPost(String host, String path, String method, MapString, String headers, MapString, String querys, byte[] body) throws Exception { HttpClient httpClient = wrapClient(host); HttpPost request = new HttpPost(buildUrl(host, path, querys)); for (Map.EntryString, String e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (body != null) { request.setEntity(new ByteArrayEntity(body)); } return httpClient.execute(request); } /** * Put String * @param host * @param path * @param method * @param headers * @param querys * @param body * @return * @throws Exception */ public static HttpResponse doPut(String host, String path, String method, MapString, String headers, MapString, String querys, String body) throws Exception { HttpClient httpClient = wrapClient(host); HttpPut request = new HttpPut(buildUrl(host, path, querys)); for (Map.EntryString, String e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (StringUtils.isNotBlank(body)) { request.setEntity(new StringEntity(body, "utf-8")); } return httpClient.execute(request); } /** * Put stream * @param host * @param path * @param method * @param headers * @param querys * @param body * @return * @throws Exception */ public static HttpResponse doPut(String host, String path, String method, MapString, String headers, MapString, String querys, byte[] body) throws Exception { HttpClient httpClient = wrapClient(host); HttpPut request = new HttpPut(buildUrl(host, path, querys)); for (Map.EntryString, String e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (body != null) { request.setEntity(new ByteArrayEntity(body)); } return httpClient.execute(request); } /** * Delete * * @param host * @param path * @param method * @param headers * @param querys * @return * @throws Exception */ public static HttpResponse doDelete(String host, String path, String method, MapString, String headers, MapString, String querys) throws Exception { HttpClient httpClient = wrapClient(host); HttpDelete request = new HttpDelete(buildUrl(host, path, querys)); for (Map.EntryString, String e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } return httpClient.execute(request); } private static String buildUrl(String host, String path, MapString, String querys) throws UnsupportedEncodingException { StringBuilder sbUrl = new StringBuilder(); sbUrl.append(host); if (!StringUtils.isBlank(path)) { sbUrl.append(path); } if (null != querys) { StringBuilder sbQuery = new StringBuilder(); for (Map.EntryString, String query : querys.entrySet()) { if (0 sbQuery.length()) { sbQuery.append(""); } if (StringUtils.isBlank(query.getKey()) !StringUtils.isBlank(query.getValue())) { sbQuery.append(query.getValue()); } if (!StringUtils.isBlank(query.getKey())) { sbQuery.append(query.getKey()); if (!StringUtils.isBlank(query.getValue())) { sbQuery.append("="); sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8")); } } } if (0 sbQuery.length()) { sbUrl.append("?").append(sbQuery); } } return sbUrl.toString(); } private static HttpClient wrapClient(String host) { HttpClient httpClient = new DefaultHttpClient(); if (host.startsWith("https://")) { sslClient(httpClient); } return httpClient; } private static void sslClient(HttpClient httpClient) { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] xcs, String str) { } public void checkServerTrusted(X509Certificate[] xcs, String str) { } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = httpClient.getConnectionManager(); SchemeRegistry registry = ccm.getSchemeRegistry(); registry.register(new Scheme("https", 443, ssf)); } catch (KeyManagementException ex) { throw new RuntimeException(ex); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } }}4、代码调试package cn.javaex.hgo.util;import java.util.HashMap;import java.util.Map;import javax.annotation.PostConstruct;import javax.servlet.ServletContext;import org.apache.http.HttpResponse;import org.apache.http.util.EntityUtils;import org.json.JSONObject;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;/** * 经纬度地址解析 * https://market.aliyun.com/products/57002002/cmapi014969.html * * @author 陈霓请 */public class AddressUtils { /** * 获取市 * @param latlng * @return */ public static String getCity(String latlng) { String host = "http://getlocat.market.alicloudapi.com"; String path = "/api/getLocationinfor"; String method = "POST"; String appcode = "你自己的AppCode"; MapString, String headers = new HashMapString, String(); //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105 headers.put("Authorization", "APPCODE " + appcode); MapString, String querys = new HashMapString, String(); querys.put("latlng", latlng); querys.put("type", "2"); MapString, String bodys = new HashMapString, String(); String str = ""; try { /** * 重要提示如下: * HttpUtils请从 * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java * 下载 * * 相应的依赖请参照 * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml */ HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);// System.out.println(response.toString()); // 获取response的body JSONObject jsonObject = new JSONObject(EntityUtils.toString(response.getEntity()));// System.out.println(jsonObject); JSONObject jsonObject2 = jsonObject.getJSONObject("result"); str = jsonObject2.get("city").toString(); } catch (Exception e) { e.printStackTrace(); } return str; } public static void main(String[] args) { String str = getCity("41.93554,118.44361"); System.out.println(str); }}
1、进入tomcat的logs目录cd /opt/tomcat/apache-tomcat-9.0.20/logs2、查看日志tail -f catalina.outCtrl+C 是退出tail命令
1、打开settings.xml配置文件2、找到mirrors/mirrors标签对,添加如下代码mirror idalimaven/id namealiyun maven/name urlhttp://maven.aliyun.com/nexus/content/groups/public//url mirrorOfcentral/mirrorOf/mirror
IFNULL(collect_restrict, 0) AS collect_restrict
DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s') AS create_time
以下记录修改mysql时区的几种方法。具体:方法一:通过mysql命令行模式下动态修改1.1 查看mysql当前时间,当前时区 select curtime(); #或select now()也可以+-----------+| curtime() |+-----------+| 15:18:10 |+-----------+ show variables like "%time_zone%";+------------------+--------+| Variable_name | Value |+------------------+--------+| system_time_zone | CST || time_zone | SYSTEM |+------------------+--------+2 rows in set (0.00 sec)#time_zone说明mysql使用system的时区,system_time_zone说明system使用CST时区 1.2 修改时区 set global time_zone = '+8:00'; ##修改mysql全局时区为北京时间,即我们所在的东8区 set time_zone = '+8:00'; ##修改当前会话时区 flush privileges; #立即生效 方法二:通过修改my.cnf配置文件来修改时区# vim /etc/my.cnf ##在[mysqld]区域中加上default-time_zone = '+8:00'# /etc/init.d/mysqld restart ##重启mysql使新时区生效 方法三:如果不方便重启mysql,又想临时解决时区问题,可以通过php或其他语言在初始化mysql时初始化mysql时区
mysqlCONCAT('doc/', dti.id, '/', dmi.id) AS hrefAND CONCAT(',', tag, ',') LIKE '%,1,%'sql serverAND ','+tag+',' LIKE '%,1,%'
rpm包安装的rpm -q 软件名或者包名例如:rpm -q httpdrpm -qa | grep httpdyum方法安装的yum list installed | grep 软件名或者包名例如yum list installed | grep httpd
将service.bat文件中的--StdOutput auto ^删除
回到顶部