java学习总结 学java的心得
bigegpt 2024-10-12 06:11 8 浏览
SpringBoot简介
https://spring.io/guides
http://www.spring4all.com/article/246
http://www.spring4all.com/article/558
http://www.ityouknow.com/spring-boot.html
Spring 官方网站本身使用Spring 框架开发,随着功能以及业务逻辑的日益复杂,应用伴随着大量的XML配置文件以及复杂的Bean依赖关系。
随着Spring 3.0的发布,Spring IO团队主键开始摆脱XML配置文件,并且在开发过程中大量使用“约定优先配置”(convention over configuration)的思想来摆脱Spring框架中各种复杂的配置,衍生了Java Config。
Spring Boot正是在这样的一个背景下被抽象出来的开发框架,它本身并不提供Spring框架的核心特性以及扩展功能,只是用于快速、敏捷地开发新一代基于Spring框架的应用程序。也就是说,它并不是用来替代Spring的解决方案,而是和Spring框架紧密结合用于提升Spring开发者体验的工具。同时它集成了大量常用的第三方库配置(例如Jackson, JDBC, Mongo, Redis, Mail等等),Spring Boot应用中这些第三方库几乎可以零配置的开箱即用(out-of-the-box),大部分的Spring Boot应用都只需要非常少量的配置代码,开发者能够更加专注于业务逻辑。
该项目旨在帮助开发者更容易地创建基于Spring的应用程序和服务,使得现有的和新的Spring开发者能够最快速地获得所需要的Spring功能。
Spring Boot不生成代码,且完全不需要XML配置。其主要目标如下:
- 为所有的Spring开发工作提供一个更快、更广泛的入门经验。
- 开箱即用,你也可以通过修改默认值来快速满足你的项目的需求。
- 提供了一系列大型项目中常见的非功能性特性,如嵌入式服务器、安全、指标,健康检测、外部配置等。
下面我们创建一个 HelloController.java 定义3个方法
package org.springboot.sample.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/hello")
public class HelloController {
@RequestMapping
public String hello() {
return "Hello Spring-Boot";
}
@RequestMapping("/info")
public Map<String, String> getInfo(@RequestParam String name) {
Map<String, String> map = new HashMap<>();
map.put("name", name);
return map;
}
@RequestMapping("/list")
public List<Map<String, String>> getList() {
List<Map<String, String>> list = new ArrayList<>();
Map<String, String> map = null;
for (int i = 1; i <= 5; i++) {
map = new HashMap<>();
map.put("name", "Shanhy-" + i);
list.add(map);
}
return list;
}
}
然后现在可以直接运行 SpringBootSampleApplication 的main方法,和执行普通java程序一样。
然后可以看到spring-boot 内置server容器(默认为Tomcat),这一切spring-boot 都帮我们做好了。
控制台输出内容 Started SpringBootSampleApplication in 7.358 seconds (JVM running for 9.154) 表示服务已经启动。
在浏览器输入我们3个请求便可看到结果。
http://localhost:8080/hello
输出:Hello Spring-Boot
http://localhost:8080/hello/info?name=shanhy
输出:{“name”:”shanhy”}
http://localhost:8080/hello/list
输出:[{“name”:”Shanhy-1”},{“name”:”Shanhy-2”},{“name”:”Shanhy-3”},{“name”:”Shanhy-4”},{“name”:”Shanhy-5”}]
通过我们的Hello实例,相信大家一目了然,可谓spring-boot创建一个项目如此简单,完全可以在几分钟内将服务启动。
spring-boot抛弃繁琐的配置,让开发人员更专注与业务逻辑的实现。后面几篇文章将会对spring-boot的多个方面通过实例的方式呈现给大家。
依赖库
https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter
https://github.com/prometheus/prometheus
https://github.com/netdata/netdata
https://github.com/OpenFeign/feign
Spring Boot JDBC
https://www.yiibai.com/springjdbc/create_query.html
https://juejin.im/post/5aa38906f265da239147b95e
Spring Boot 配置使用 HTTPS
https://zhuanlan.zhihu.com/p/31385073
http://blog.wxcsdb88.com/2017/08/29/spring-boot-https/
https://zhuanlan.zhihu.com/p/32545108
springboot多环境配置(yml)
https://www.jianshu.com/p/3b1ba2158f5b
MyBatis教程
从两个钟变成2天,是什么原因导致?
第一天上午看如下教程:
https://www.cnblogs.com/ityouknow/p/6037431.html
https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-mybatis-annotation
实现该教程,然后看如下教程
https://www.yiibai.com/mybatis/install_configure.html
漏了一句话导致浪费时间:3个小时左右
下午4点半开始正式写代码,选择了下面的模型移植到fusionmind:
https://www.jianshu.com/p/5cd772c07041
https://blog.csdn.net/Winter_chen001/article/details/78622141
19点移植完,但是问题很多开始定位
22:55完成可以在dls数据库下发数据到数据库
各种配置问题
第二天上午添加delete接口,传入参数Integer的问题,上午11点问题解决,耗时3个小时
但是发现json下发post到数据库为NULL,这个问题到晚上8点解决,耗时8个小时
https://www.bysocket.com/?p=1627
添加注解方式的mybatis,发现空指针问题(java.lang.NullPointerException),共花时间4小时
Mybatis多表联合查询的方法:
https://my.oschina.net/u/2278977/blog/866608
https://www.cnblogs.com/shengulong/p/8385966.html
https://blog.csdn.net/wfq784967698/article/details/78786001
数据库教程
MySql:
启动与关闭:
windows操作系统下
启动服务
???mysqldadmin start 或 net start mysql
关闭服务
mysqladmin -uroot shutdown
net stop mysql
Linux操作系统下
启动服务
service mysqld start
关闭服务
service mysqld stop
重启服务
service mysqld restart
mysql –u root -p
https://blog.csdn.net/ithomer/article/details/5131863
https://blog.csdn.net/HXChuangxiaochuan/article/details/79000881
https://blog.csdn.net/hopyGreat/article/details/80526993
PostgreSQL:
http://3ms.huawei.com/hi/group/2952325/thread_5756407.html?mapId=7131187
http://3ms.huawei.com/km/blogs/details/5661201
postgreSQL常用命令
https://www.jianshu.com/p/8515a02492f1
https://www.yiibai.com/html/postgresql/2013/080436.html
/usr/local/postgresql10.6/data
pg_ctl restart
Python连接mysql或postgres(sqlalchemy)
https://my.oschina.net/u/2245781/blog/665075
Linux安装Redis
https://blog.csdn.net/u011669700/article/details/79566713
https://www.jianshu.com/p/bc84b2b71c1c
Java Json相关
https://blog.csdn.net/xiazdong/article/details/7059573
JSONArray转list
https://blog.csdn.net/qq_36306340/article/details/78732203
public static void main(String[] args) {
JSONArray jsonArray=new JSONArray();
jsonArray.add("1");
jsonArray.add("2");
jsonArray.add("3");
jsonArray.add("4");
jsonArray.add("5");
jsonArray.add("6");
System.err.println(jsonArray);
//把json数据放入到list中
List list = new ArrayList<>();
for(Object jstr:jsonArray){
list.add(jstr);
}
System.out.println(list);
}
Java解析Json数据的两种方式
https://blog.csdn.net/chenfengdejuanlian/article/details/52190462
java——读取JSON文件
https://blog.csdn.net/ALemon_Y/article/details/71436194
Java解析JSON文件的方法
https://blog.csdn.net/mingtianhaiyouwo/article/details/51336381
java中使用json- JSONObject、JSONArray相互嵌套
https://blog.csdn.net/flyliuweisky547/article/details/19172133
java封装多层json
https://blog.csdn.net/pan12jian/article/details/25987505
java中string与json互相转化
https://blog.csdn.net/u011575570/article/details/47863337
java中json字符串移除指定属性
https://blog.csdn.net/DUDUfine/article/details/52218463
Java文件读取
在Java中加入路径
https://codeday.me/bug/20171122/98549.html
Java判断文件、文件夹是否存在
https://blog.csdn.net/itmyhome1990/article/details/51243997
反斜杠(\)则不然,它和紧跟着它的那个字符构成转义字符,如“\n”(表示换行)、“\””(表示字符‘”’)等,所以在字符串中要表示字符'\'要用“\\”来表示,例:如果你这样定义一个字符串String s = “name\sex”是错误的,要这样定义String s = “name\\sex”;
Java数据类型
Java|Map、List与Set的区别
https://www.jianshu.com/p/f7365230dcf2
Java中List和ArrayList的区别
https://blog.csdn.net/erlian1992/article/details/51298276
https://www.jianshu.com/p/a6a708350743
Java中遍历Map的各种方式
https://blog.csdn.net/da_caoyuan/article/details/79819221
https://www.jianshu.com/p/3d1fb84b2b63
http://www.trinea.cn/android/hashmap-loop-performance/
hashmap判断是否存在key时,使用get(key)==null判断还是containsKey?
https://blog.csdn.net/fofabu2/article/details/78964079
IoC
Ioc和java反射技术的关系?
Ioc和依赖注入的关系?
https://www.cnblogs.com/weiyinfu/p/6835301.html
https://blog.csdn.net/HEYUTAO007/article/details/5981555
反射
https://blog.csdn.net/gdutxiaoxu/article/details/68947735
https://juejin.im/post/598ea9116fb9a03c335a99a4
https://www.sczyh30.com/posts/Java/java-reflection-1/#%E4%B8%80%E3%80%81%E5%9B%9E%E9%A1%BE%EF%BC%9A%E4%BB%80%E4%B9%88%E6%98%AF%E5%8F%8D%E5%B0%84%EF%BC%9F
mysql 按指定id排序
https://blog.csdn.net/pengone/article/details/49816131
https://blog.csdn.net/ylforever/article/details/79191182
How to return the ID of the inserted object under Postgres?
http://mybatis-user.963551.n3.nabble.com/How-to-return-the-ID-of-the-inserted-object-under-Postgres-td1926959.html
Java 8 Stream
http://www.runoob.com/java/java8-streams.html
接口引用指向实现类的对象
经常见List<?> list= new ArrayList<?>
Map<?,?> map = new HashMap<?,?>
但是发现list只是ArrayList的接口不是它的父类 ,不是父类引用指向子类对象
如果是应该是AbstractLIst ablist= new ArraryList(); 或者直接写为ArrayList<?> list= new ArrayList<?>
为什么要用接口引用指向实现类的对象
这种写法其实Java多态的表现形式
多态的定义:指允许不同类的对象对同一消息做出响应。即同一消息可以根据发送对象的不同而采用多种不同的行为方式。(发送消息就是函数调用)
List list;是在栈区开辟一个空间放list引用,并没有创建对象所以不知道ArrayList还是LinkedList当你list= new ArrayList(); 就创建了ArrayList对象。并且把开始创建的list引用指向这个对象ArrayList和LinkedList都是List的实现类。
为什么一般都使用 List list = new ArrayList() ,而不用 ArrayList alist = new ArrayList()呢?
问题就在于List有多个实现类,如 LinkedList或者Vector等等,现在你用的是ArrayList,也许哪一天你需要换成其它的实现类呢?,这时你只要改变这一行就行了:List list = new LinkedList(); 其它使用了list地方的代码根本不需要改动。假设你开始用 ArrayList alist = new ArrayList(), 这下你有的改了,特别是如果你使用了 ArrayList特有的方法和属性。 ,如果没有特别需求的话,最好使用List list = new LinkedList(); ,便于程序代码的重构. 这就是面向接口编程的好处
注意事项
list只能使用ArrayList中已经实现了的List接口中的方法,ArrayList中那些自己的、没有在List接口定义的方法是不可以被访问到的
list.add()其实是List接口的方法
但是调用ArrayList的方法如 clone()方法是调用不到的
接口的灵活性就在于“规定一个类必须做什么,而不管你如何做”。我们可以定义一个接口类型的引用变量来引用实现接口的类的实例,当这个引用调用方法时,它会根据实际引用的类的实例来判断具体调用哪个方法,这和上述的超类对象引用访问子类对象的机制相似。
//定义接口InterA
interface InterA
{
void fun();
}
//实现接口InterA的类B
class B implements InterA
{
public void fun()
{
System.out.println(“This is B”);
}
}
//实现接口InterA的类C
class C implements InterA
{
public void fun()
{
System.out.println(“This is C”);
}
}
class Test
{
public static void main(String[] args)
{
InterA a;
a= new B();
a.fun();
a = new C();
a.fun();
}
}
输出结果为:
This is B
This is C
上例中类B和类C是实现接口InterA的两个类,分别实现了接口的方法fun(),通过将类B和类C的实例赋给接口引用a,实现了方法在运行时的动态绑定,充分利用了“一个接口,多个方法”,展示了Java的动态多态性。
需要注意的一点是:Java在利用接口变量调用其实现类的对象的方法时,该方法必须已经在接口中被声明,而且在接口的实现类中该实现方法的类型和参数必须与接口中所定义的精确匹配。
Java设计模式代理模式
https://blog.csdn.net/carson_ho/article/details/54910472
线程池
Java里面线程池的顶级接口是Executor,但是严格意义上讲Executor并不是一个线程池,而只是一个执行线程的工具。真正的线程池接口是ExecutorService。下面这张图完整描述了线程池的类体系结构。
研究Java类加载机制
https://zyjustin9.iteye.com/blog/2092131
https://blog.csdn.net/lkforce/article/details/80253426
http://xiamianyu.github.io/2017/06/28/Java-%E5%90%AF%E5%8A%A8%E5%8F%82%E6%95%B0/
java命令行添加外部文件到classpath,从而实现读取外部配置文件
https://blog.csdn.net/gx304419380/article/details/80265720
https://www.cnblogs.com/xiaoqi/p/6955288.html
Linux jar包 后台运行 并生成log文件
https://blog.csdn.net/u012613251/article/details/80331994
Spring日志
https://code.skyheng.com/post/34603.html
https://www.cnblogs.com/keeya/p/10101547.html
https://www.jianshu.com/p/46b530446d20
https://blog.51cto.com/11931236/2058708
SpringBoot可执行包结构
https://blog.csdn.net/west_609/article/details/74906495
https://www.cnblogs.com/lmk-sym/p/6554382.html
证书:
https://www.cnblogs.com/littleatp/p/5922362.html
https://blog.csdn.net/liuchunming033/article/details/48470575
去包
https://www.cnblogs.com/yang-wu/p/3262499.html
https://ningyu1.github.io/site/post/93-maven-depenpency-analyze/
https://blog.csdn.net/qq_27093465/article/details/69226949
java定时任务
https://zhuanlan.zhihu.com/p/40785962
https://yq.aliyun.com/articles/2368
https://juejin.im/post/5b31b9eff265da598826c200
https://segmentfault.com/a/1190000013077817
Spring之RequestBody的使用姿势小结
https://juejin.im/post/5b5efff0e51d45198469acea
https://blog.csdn.net/qq_32423845/article/details/81199854
https://blog.csdn.net/qq_27603235/article/details/51604584
http://www.voidcn.com/article/p-kbigwhhu-bey.html
相关推荐
- Go语言泛型-泛型约束与实践(go1.7泛型)
-
来源:械说在Go语言中,Go泛型-泛型约束与实践部分主要探讨如何定义和使用泛型约束(Constraints),以及如何在实际开发中利用泛型进行更灵活的编程。以下是详细内容:一、什么是泛型约束?**泛型...
- golang总结(golang实战教程)
-
基础部分Go语言有哪些优势?1简单易学:语法简洁,减少了代码的冗余。高效并发:内置强大的goroutine和channel,使并发编程更加高效且易于管理。内存管理:拥有自动垃圾回收机制,减少内...
- Go 官宣:新版 Protobuf API(go pro版本)
-
原文作者:JoeTsai,DamienNeil和HerbieOng原文链接:https://blog.golang.org/a-new-go-api-for-protocol-buffer...
- Golang开发的一些注意事项(一)(golang入门项目)
-
1.channel关闭后读的问题当channel关闭之后再去读取它,虽然不会引发panic,但会直接得到零值,而且ok的值为false。packagemainimport"...
- golang 托盘菜单应用及打开系统默认浏览器
-
之前看到一个应用,用go语言编写,说是某某程序的windows图形化客户端,体验一下发现只是一个托盘,然后托盘菜单的控制面板功能直接打开本地浏览器访问程序启动的webserver网页完成gui相关功...
- golang标准库每日一库之 io/ioutil
-
一、核心函数概览函数作用描述替代方案(Go1.16+)ioutil.ReadFile(filename)一次性读取整个文件内容(返回[]byte)os.ReadFileioutil.WriteFi...
- 文件类型更改器——GoLang 中的 CLI 工具
-
我是如何为一项琐碎的工作任务创建一个简单的工具的,你也可以上周我开始玩GoLang,它是一种由Google制作的类C编译语言,非常轻量和快速,事实上它经常在Techempower的基准测...
- Go (Golang) 中的 Channels 简介(golang channel长度和容量)
-
这篇文章重点介绍Channels(通道)在Go中的工作方式,以及如何在代码中使用它们。在Go中,Channels是一种编程结构,它允许我们在代码的不同部分之间移动数据,通常来自不同的goro...
- Golang引入泛型:Go将Interface「」替换为“Any”
-
现在Go将拥有泛型:Go将Interface{}替换为“Any”,这是一个类型别名:typeany=interface{}这会引入了泛型作好准备,实际上,带有泛型的Go1.18Beta...
- 一文带你看懂Golang最新特性(golang2.0特性)
-
作者:腾讯PCG代码委员会经过十余年的迭代,Go语言逐渐成为云计算时代主流的编程语言。下到云计算基础设施,上到微服务,越来越多的流行产品使用Go语言编写。可见其影响力已经非常强大。一、Go语言发展历史...
- Go 每日一库之 java 转 go 遇到 Apollo?让 agollo 来平滑迁移
-
以下文章来源于GoOfficialBlog,作者GoOfficialBlogIntroductionagollo是Apollo的Golang客户端Apollo(阿波罗)是携程框架部门研...
- Golang使用grpc详解(golang gcc)
-
gRPC是Google开源的一种高性能、跨语言的远程过程调用(RPC)框架,它使用ProtocolBuffers作为序列化工具,支持多种编程语言,如C++,Java,Python,Go等。gR...
- Etcd服务注册与发现封装实现--golang
-
服务注册register.gopackageregisterimport("fmt""time"etcd3"github.com/cor...
- Golang:将日志以Json格式输出到Kafka
-
在上一篇文章中我实现了一个支持Debug、Info、Error等多个级别的日志库,并将日志写到了磁盘文件中,代码比较简单,适合练手。有兴趣的可以通过这个链接前往:https://github.com/...
- 如何从 PHP 过渡到 Golang?(php转golang)
-
我是PHP开发者,转Go两个月了吧,记录一下使用Golang怎么一步步开发新项目。本着有坑填坑,有错改错的宗旨,从零开始,开始学习。因为我司没有专门的Golang大牛,所以我也只能一步步自己去...
- 一周热门
- 最近发表
- 标签列表
-
- mybatiscollection (79)
- mqtt服务器 (88)
- keyerror (78)
- c#map (65)
- xftp6 (83)
- bt搜索 (75)
- c#var (76)
- xcode-select (66)
- mysql授权 (74)
- 下载测试 (70)
- linuxlink (65)
- pythonwget (67)
- androidinclude (65)
- libcrypto.so (74)
- linux安装minio (74)
- ubuntuunzip (67)
- vscode使用技巧 (83)
- secure-file-priv (67)
- vue阻止冒泡 (67)
- jquery跨域 (68)
- php写入文件 (73)
- kafkatools (66)
- mysql导出数据库 (66)
- jquery鼠标移入移出 (71)
- 取小数点后两位的函数 (73)