Java中的DO、TO、DTO、DAO等含义
1、PO即persistant Object 持久对象: 在O/R 映射(即ORM-ObjectRelationMapping)中出现的概念,通常对应数据模型(数据库),是与数据库汇总的表想影射的java对象,最简单的PO就是对应数据库中某个表中的一条记录,多个记录则用PO的集合。PO中不应该包含任何对数据库的操作。 2、DO即Domain Object 领域对象: 是从现实世界中抽象出来的有形或无形的业务实体。 3、TO即Transfer Object数据传输对象: 不同应用程序之间传输的对象 4、DTO即Data Transfer Object:数据传输对象: 泛指用于展示层与服务层之间的数据传输对象 5、VO即value Object: 通常用于业务层之间的数据传递,和PO一样仅包含数据,但是抽象出的业务对象,可以和表对应,用new 关键字创建,GC回收 6、BO即Business Object 业务对象: 主要是将业务逻辑封装为一个对象,这个对象可以包含一个或多个其他对象,如一个简历中包含教育经历、工作经历、社会关系等,可以将一个教育经历对应一个PO、工作经历对应一个PO、设计关系对应一个PO,然后简历一个对应简历的BO兑现处理简历,每个BO包含这个PO这样处理业务逻辑是,可以针对BO去处理。封装业务逻辑的java对象,通过调用DAO方法,结合PO,VO进行业务操作。 7、POJO即Plain Ordinary Java Object: 简单无规则的java对性,即在一些O/R 映射工具中,能做到维护数据库表记录的PO完全是一个符合Java Bean规范的纯java对象 from:https://blog.csdn.net/weixin_44122921/article/details/85038513
View Details解决 fastjson toJSON方法日期类型字段 由时间戳转换成自定义类型格式的问题 JSON.toJSONStringWithDateFormat
将map集合转为json对象时遇到一个问题。map中 updateTime的value为日期格式如"2001-01-01",在使用 JSONObject.toJSON(map).toString() 的时候, 得到的结果 updateTime 的值为 时间戳 解决方法: 使用fastjson 的 JSON.toJSONStringWithDateFormat(Object,dateformat,SerializerFeature.WriteDateUseDateFormat) 方法即可将时间戳转换为自定义格式类型的值 from:https://blog.csdn.net/qq_39564789/article/details/105176845
View DetailsCentOS7 离线安装MySQL
1.删除原有的mariadb 不然安装报错
1 |
rpm -qa|grep mariadb |
1 |
rpm -e --nodeps mariadb-libs |
2. 下载RPM安装包 在https://dev.mysql.com/downloads/mysql/选择为Red Hat Enterprise Linux 7 / Oracle Linux 7 ,把os的版本选择为all。 直接下载mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar,所有的rpm包都在里面,然后rpm命令安装。
1 2 3 4 5 6 7 8 9 10 11 |
rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm |
至此,mysql5.7所有文件安装完毕,接下来就是开启服务测试了 3. 启动mysql服务 查看mysql服务是否启动
1 |
service mysqld status |
启动服务:
1 |
systemctl start mysqld |
4. 重置root密码 MySQL5.7会在安装后为root用户生成一个随机密码,而不是像以往版本的空密码。 可以安全模式修改root登录密码或者用随机密码登录修改密码。下面用随机密码方式 MySQL为root用户生成的随机密码通过mysqld.log文件可以查找到:
1 |
grep 'temporary password' /var/log/mysqld.log |
5. 修改root用户密码 (MySQL的密码策略比较复杂,过于简单的密码会被拒绝)
1 2 3 4 |
1 mysql -u root -p 2 mysql> Enter password: (输入刚才查询到的随机密码) 3 mysql> SET PASSWORD FOR 'root'@'localhost'= "qaz-123"; 4 mysql> exit |
6. 用root新密码登录
1 |
mysql -u root -pqaz-123 |
如果上面的方式不能修改可以使用下面安全模式修改root: 关闭服务,修改mysql配置文件:
1 2 |
1 systemctl stop mysqld.service 2 vi /etc/my.cnf |
mysqld下面添加skip-grant-tables 保存退出启动服务。
1 |
systemctl start mysqld.service |
1 2 3 4 5 6 7 |
mysql -u root #不用密码直接回车 use mysql update user set authentication_string=password('qaz-123') where user='root' and host='localhost'; flush privileges; exit; vi /etc/my.cnf #把 skip-grant-tables 一句删除保存退出重启mysql服务 systemctl restart mysqld.service |
再次登录即可
1 |
mysql -uroot -pqaz123 |
如果进行操作出现下面的提示:
1 |
You must reset your password using ALTER USER statement before executing this statement. |
就重新设置密码(mysql默认密码策略比较复杂,如果设置简单密码,需修改默认安全策略,可以参考另外一篇文章:MYSQL57密码策略修改)
1 |
set password = password('qaz-123'); |
7.开放3306端口
1 2 3 |
1 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'qaz-123' WITH GRANT OPTION; 2 mysql>FLUSH PRIVILEGES; 3 mysql>exit; |
开启防火墙mysql 3306端口的外部访问:
1 2 |
1 firewall-cmd --zone=public --add-port=3306/tcp --permanent 2 firewall-cmd --reload |
from:https://www.cnblogs.com/mymelody/p/9253551.html
View Detailscentos7下使用mysql离线安装包安装mysql5.7
服务器环境: centos7 x64 需要安装mysql5.7+ 一、卸载CentOS7系统自带mariadb
1 2 3 4 5 6 7 |
# 查看系统自带的Mariadb [root@CDH-141 ~]# rpm -qa|grep mariadb mariadb-libs-5.5.44-2.el7.centos.x86_64 # 卸载系统自带的Mariadb [root@CDH-141 ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64 # 删除etc目录下的my.cnf [root@CDH-141 ~]# rm /etc/my.cnf |
二、检查mysql是否存在
1 2 3 |
# 检查mysql是否存在 [root@CDH-141 ~]# rpm -qa | grep mysql [root@CDH-141 ~]# |
三、查看用户和组是否存在 1)检查mysql组合用户是否存在
1 2 3 |
# 检查mysql组和用户是否存在,如无则创建 [root@CDH-141 ~]# cat /etc/group | grep mysql [root@CDH-141 ~]# cat /etc/passwd | grep mysql |
# 查询全部用户(只是做记录,没必要执行)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@CDH-141 ~]# cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F ":" '{print $1 "|" $3 "1" $4}' | more root|010 sync|510 flume|9921989 hdfs|9911988 zookeeper|9891986 llama|9881985 httpfs|9871984 mapred|9861983 sqoop|9851982 yarn|9841981 kms|9831980 hive|9821979 oozie|9801977 hbase|9781975 impala|9761973 hue|9741971 wlaqzc2018|100111001 [root@CDH-141 mysql]# |
2)若不存在,则创建mysql组和用户
1 2 3 4 5 6 7 8 9 10 11 |
# 创建mysql用户组 [root@CDH-141 ~]# groupadd mysql # 创建一个用户名为mysql的用户,并加入mysql用户组 [root@CDH-141 ~]# useradd -g mysql mysql # 制定password 为111111 [root@CDH-141 ~]# passwd mysql Changing password for user mysql. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully. |
四、下载mysql离线安装包tar文件 官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 版本选择,可以选择一下两种方式: 1)使用Red Hat Enterprise Linux Select Version:5.7.25 Select Operating System:Red Hat Enterprise Linux / Oracle Linux Select OS Version:Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit) 列表中下载: Compressed TAR Archive:(mysql-5.7.25-el7-x86_64.tar.gz) 2)使用Linux – Generic Select Version:5.7.25 Select Operating System:Linux – Generic Select OS Version:Linux – Generic (glibc 2.12) (x86, 64-bit) 列表中下载: Compressed TAR Archive:(mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz)【本文中使用的是这个版本】 注意:上边两种方式找mysql离线安装包的方式都可以。 五、上传第四步下载的mysql TAR包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 进入/usr/local/文件夹 [root@CDH-141 ~]# cd /usr/local/ # 上传mysql TAR包 [root@CDH-141 local]# rz # 解压mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz [root@CDH-141 local]# ls bin full-path-to-mysql-VERSION-OS include lib64 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz share etc games lib libexec sbin src [root@CDH-141 local]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz mysql-5.7.25-lin ... mysql-5.7.25-linux-glibc2.12-x86_64/share/install_rewriter.sql mysql-5.7.25-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql mysql-5.7.25-linux-glibc2.12-x86_64/support-files/magic mysql-5.7.25-linux-glibc2.12-x86_64/support-files/mysql.server mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_BIN mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_SRC [root@CDH-141 local]# ls bin full-path-to-mysql-VERSION-OS include lib64 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz share etc games lib libexec mysql-5.7.25-linux-glibc2.12-x86_64 sbin src # 进入/usr/local下,修改为mysql [root@CDH-141 local]# mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql [root@CDH-141 local]# ls bin etc full-path-to-mysql-VERSION-OS games include lib lib64 libexec mysql mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz sbin share src |
六、更改所属的组和用户
1 2 3 4 5 6 7 |
# 更改所属的组和用户 [root@CDH-141 ~]# cd /usr/local/ [root@CDH-141 local]# chown -R mysql mysql/ [root@CDH-141 local]# chgrp -R mysql mysql/ [root@CDH-141 local]# cd mysql/ [root@CDH-141 mysql]# mkdir data [root@CDH-141 mysql]# chown -R mysql:mysql data |
七、在/etc下创建my.cnf文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 进入/usr/local/mysql文件夹下 [root@CDH-141 ~]# cd /usr/local/mysql # 创建my.cnf文件 [root@CDH-141 mysql]# touch my.cnf #或者cd ''>my.conf # 编辑my.cnf [root@CDH-141 mysql]# vi my.conf [mysql] socket=/var/lib/mysql/mysql.sock # set mysql client default chararter default-character-set=utf8 [mysqld] socket=/var/lib/mysql/mysql.sock # set mysql server port port = 3323 #默认是3306,这里发现3306已经被占用,因此防止这种情况发生,可以避免使用3306mysql默认端口 # set mysql install base dir basedir=/usr/local/mysql # set the data store dir datadir=/usr/local/mysql/data # set the number of allow max connnection max_connections=200 # set server charactre default encoding character-set-server=utf8 # the storage engine default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M explicit_defaults_for_timestamp=true [mysql.server] user=mysql basedir=/usr/local/mysql [root@CDH-141 mysql]# |
八、进入mysql文件夹,并安装mysql
1 2 3 4 5 6 7 |
# 进入mysql [root@CDH-141 local]# cd /usr/local/mysql # 安装mysql [root@CDH-141 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 2019-03-08 18:11:07 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2019-03-08 18:11:24 [WARNING] The bootstrap log isn't empty: 2019-03-08 18:11:24 [WARNING] 2019-03-08T10:11:07.208602Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead |
设置文件及目录权限:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@CDH-141 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld [root@CDH-141 mysql]# chown 777 my.cnf [root@CDH-141 mysql]# ls bin COPYING data docs include lib man my.cnf README share support-files [root@CDH-141 mysql]# ls -l total 60 drwxr-xr-x 2 root root 4096 Mar 8 15:56 bin -rw-r--r-- 1 7161 31415 17987 Dec 21 18:39 COPYING drwxr-x--- 5 mysql mysql 4096 Mar 8 16:21 data drwxr-xr-x 2 root root 4096 Mar 8 15:56 docs drwxr-xr-x 3 root root 4096 Mar 8 15:56 include drwxr-xr-x 5 root root 4096 Mar 8 15:56 lib drwxr-xr-x 4 root root 4096 Mar 8 15:56 man -rw-r--r-- 1 777 root 516 Mar 8 16:19 my.cnf -rw-r--r-- 1 7161 31415 2478 Dec 21 18:39 README drwxr-xr-x 28 root root 4096 Mar 8 15:56 share drwxr-xr-x 2 root root 4096 Mar 8 15:56 support-files [root@CDH-141 mysql]# chmod +x /etc/init.d/mysqld [root@CDH-141 mysql]# [root@CDH-141 mysql]# mkdir data [root@CDH-141 mysql]# [root@CDH-141 mysql]# chown -R mysql:mysql data [root@CDH-141 mysql]# |
九、启动mysql
1 2 3 4 5 6 |
# 启动mysql [root@CDH-141 mysql]# /etc/init.d/mysqld restart MySQL server PID file could not be found![FAILED] Starting MySQL.Logging to '/usr/local/mysql/data/CDH-141.err'. ..The server quit without updating PID file (/usr/local/mysql/data/CDH-141.pid).[FAILED] [root@CDH-141 mysql]# |
出现错误,解决方案如下: […]
View DetailsJAVA中使用alibaba fastjson实现JSONObject、Object、Json字符串的转换
Object转JSON字符串: String jsonStr = JSONObject.toJSONString(object); JSON字符串转JSONObject: JSONObject jsonObject = JSONObject.parseObject(jsonStr); JSON字符串转Object对象 T t = JSON.parseObject(jsonStr,T.class); —–注:JSON字符串是有格式要求的,必须为键值对形式,不是任意的字符串。—– ——————— 作者:KnifeBlade 来源:CSDN 原文:https://blog.csdn.net/qq_29468573/article/details/82190005
View Details使用fastjson时,对象转json遇到的首字母大小写问题
在使用fastjson进行数据类型转换时发现,pojo类里面的属性首字母大写,在转成json之后,变成了小写。导致数据存储一直有问题。 转换之后结果为: 导致数据存储失败。(使用json传值进行持久化操作。) 解决方法: 在pojo类的属性get方法上加上你需要的key。 这样转换的json,对应的key就改变为你注解对应的属性名。 from:https://blog.csdn.net/cuuuc233/article/details/80983486
View Detailsfastjson包JSONObject.toJSON导致部分属性丢失问题
JSONObject.toJSONString(Object object, SerializerFeature… features) Fastjson的SerializerFeature序列化属性 QuoteFieldNames———-输出key时是否使用双引号,默认为true WriteMapNullValue——–是否输出值为null的字段,默认为false WriteNullNumberAsZero—-数值字段如果为null,输出为0,而非null WriteNullListAsEmpty—–List字段如果为null,输出为[],而非null WriteNullStringAsEmpty—字符类型字段如果为null,输出为”“,而非null WriteNullBooleanAsFalse–Boolean字段如果为null,输出为false,而非nul
1 2 3 4 5 6 7 8 9 |
Map < String , Object > jsonMap = new HashMap< String , Object>(); jsonMap.put("a",1); jsonMap.put("b",""); jsonMap.put("c",null); jsonMap.put("d","dddddddddd"); String str = JSONObject.toJSONString(jsonMap,SerializerFeature.WriteMapNullValue); System.out.println(str); //输出结果:{"a":1,"b":"","c":null,"d":"dddddddddd"} |
from:http://www.voidcn.com/article/p-ebkhpvlq-bqh.html
View DetailsSpringboot — 用更优雅的方式发HTTP请求(RestTemplate详解)
RestTemplate是Spring提供的用于访问Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效率。
我之前的HTTP开发是用apache的HttpClient开发,代码复杂,还得操心资源回收等。代码很复杂,冗余代码多,稍微截个图,这是我封装好的一个post请求工具:
本教程将带领大家实现Spring生态内RestTemplate的Get请求和Post请求还有exchange指定请求类型的实践和RestTemplate核心方法源码的分析,看完你就会用优雅的方式来发HTTP请求。
View Detailsjava发送http的get、post请求
Http请求类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
package wzh.Http; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; import java.util.List; import java.util.Map; public class HttpRequest { /** * 向指定URL发送GET方法的请求 * * @param url * 发送请求的URL * @param param * 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 * @return URL 所代表远程资源的响应结果 */ public static String sendGet(String url, String param) { String result = ""; BufferedReader in = null; try { String urlNameString = url + "?" + param; URL realUrl = new URL(urlNameString); // 打开和URL之间的连接 URLConnection connection = realUrl.openConnection(); // 设置通用的请求属性 connection.setRequestProperty("accept", "*/*"); connection.setRequestProperty("connection", "Keep-Alive"); connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 建立实际的连接 connection.connect(); // 获取所有响应头字段 Map<String, List<String>> map = connection.getHeaderFields(); // 遍历所有的响应头字段 for (String key : map.keySet()) { System.out.println(key + "--->" + map.get(key)); } // 定义 BufferedReader输入流来读取URL的响应 in = new BufferedReader(new InputStreamReader( connection.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("发送GET请求出现异常!" + e); e.printStackTrace(); } // 使用finally块来关闭输入流 finally { try { if (in != null) { in.close(); } } catch (Exception e2) { e2.printStackTrace(); } } return result; } /** * 向指定 URL 发送POST方法的请求 * * @param url * 发送请求的 URL * @param param * 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 * @return 所代表远程资源的响应结果 */ public static String sendPost(String url, String param) { PrintWriter out = null; BufferedReader in = null; String result = ""; try { URL realUrl = new URL(url); // 打开和URL之间的连接 URLConnection conn = realUrl.openConnection(); // 设置通用的请求属性 conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 发送POST请求必须设置如下两行 conn.setDoOutput(true); conn.setDoInput(true); // 获取URLConnection对象对应的输出流 out = new PrintWriter(conn.getOutputStream()); // 发送请求参数 out.print(param); // flush输出流的缓冲 out.flush(); // 定义BufferedReader输入流来读取URL的响应 in = new BufferedReader( new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("发送 POST 请求出现异常!"+e); e.printStackTrace(); } //使用finally块来关闭输出流、输入流 finally{ try{ if(out!=null){ out.close(); } if(in!=null){ in.close(); } } catch(IOException ex){ ex.printStackTrace(); } } return result; } } |
调用方法:
1 2 3 4 5 6 7 8 9 |
public static void main(String[] args) { //发送 GET 请求 String s=HttpRequest.sendGet("http://localhost:6144/Home/RequestString", "key=123&v=456"); System.out.println(s); //发送 POST 请求 String sr=HttpRequest.sendPost("http://localhost:6144/Home/RequestPostString", "key=123&v=456"); System.out.println(sr); } |
from:https://www.cnblogs.com/zhuawang/archive/2012/12/08/2809380.html
View DetailsSpringboot获取配置文件属性的方法
pom配置 html内容 1 通过注解 1.1 在properties文件下配置属性 1.2 利用@Value注解将对应的属性注入到field上 1.3 请求结果如下 2 通过PropertiesLoaderUtils 利用org.springframework.core.io.support包下的PropertiesLoaderUtils读取配置文件从而获得对应的配置信息 PropertiesLoaderUtils.loadProperties(new EncodedResource(new ClassPathResource(location), "UTF-8")); 将对应配置文件的信息填入location即可 2.1 在properties文件下配置属性 2.2 创建工具类 2.3 读取配置信息 2.4 请求结果如下 3 通过@PropertySource将属性映射给类的属性 3.1 配置属性 3.2 属性映射 3.3 请求结果 4 利用Environment (org.springframework.core.env.Environment) 4.1 配置属性 4.2 引入Environment 4.3 请求结果 from:https://www.cnblogs.com/zad27/p/10483484.html
View Details