目录 一、主方法 二、Java实现hello world 三、用static修饰的方法就是静态方法 四、编译java文件 1、通过javac编译java文件 2、执行编译后的java文件 3、如何运行class文件中的main方法 五、数据类型 1、四种整型 2、浮点型 3、char 4、boolean 六、数据类型默认值 1、基础数据类型默认值 2、代码实例 七、大数值 八、装箱与拆箱 九、特殊的转义字符 一、主方法
1 2 3 |
public static void main(String[] args) { } |
在main中使用了两个修饰符public和static,public修饰符使它可以从应用程序的任何地方访问被访问,静态修饰符使它成为一个类方法,可以直接用类名进行调用。 返回值为void,因为这个访问不需要返回值。 它的名字是main,参数是String[] args。 二、Java实现hello world 需要插图 三、用static修饰的方法就是静态方法 需要插图
1 2 3 4 5 6 7 8 9 10 11 |
package com.nezha.javase; public class Test { private void test(){ System.out.println("你好,我是哪吒"); } public static void main(String[] args) { Test.test(); } } |
可以使用类名.方法名的形式访问static方法,但是不能访问非静态方法。 四、编译java文件 1、通过javac编译java文件
1 |
javac Test.java |
编译后的文件Test.class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.nezha.javase; public class Test { public Test() { } public static void main(String[] var0) { System.out.println("hello world"); } } |
2、执行编译后的java文件
1 |
java Test |
输出结果:hello world 3、如何运行class文件中的main方法 假设如下目录有个class文件,并且里面有main方法: E:\nezha\JavaseProject\com\nezha\javase\Test.class 首先进入cmd命令行:
1 2 3 |
cd /d E:\nezha\JavaseProject java com\nezha\javase.Test |
也可以带参数运行:
1 |
java com.nezha.javase.Test com.nezha.javase.Test nezha |
五、数据类型 Java是一种强类型的语言,有8种基本类型,其中4种整型,2种浮点型,1种用于表示Unicode编码的字符单元的字符类型char、1种boolean型。 1、四种整型 int 4字节 -2147483648~2147483647 short 2字节 -32768~32767 long 8字节 很大很大 byte 1字节 -128~127 通常情况下int最常用,byte和short类型用于特定的应用场合,例如底层的文件处理或需要控制占用存储空间量的大数组。 长整型有一个后缀L或l(如123456789L)。十六进制数值有一个前缀0x或0X(如0xFFFF)。 八进制有一个前缀0,例如010表示八进制中的8。 2、浮点型 double 8字节 float 4字节 double的数值精度是float的两倍,double一般也可称作双精度浮点型。 一般都使用double,不使用float。 3、char char类型表示单个字符。 char类型的字面量值要用单引号括起来。 例如’A’是编码值为65所对应的字符常量。它与"A"不同,"A"表示一个字符串A。 char类型可以表示为十六进制值,范围从\u0000到\Uffff。 4、boolean boolean类型只有两个值,true和false。 […]
View Details在springcloudconfig的集群项目中,内网的服务器不能访问外网,搭建一个外网代理服务器,内网下的项目需要找云服务器上的配置文件时可能会出现寻找配置文件时出不了外网的情况。这时需要在项目中配置http的正向代理。
View Details编译Spigotmc服务端时,由于网络原因总是失败,git和shell也均配置了代理,实际编译过程中还是遇到各种网络问题报错,如:java.net.SocketTimeoutException: Connect timed out之类的,怀疑是BuildTools.jar包执行过程中并没有走代理导致,因此尝试给jar包指定代理。亲测可用,jar包也走了代理,所有网络访问畅通无阻。 命令:
1 |
java -Dhttp.proxyHost={IP} -Dhttp.proxyPort={PORT} -Dhttps.proxyHost={IP} -Dhttps.proxyPort={PORT} -jar BuildTools.jar |
例如:
1 |
java -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=1081 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=1081 -jar BuildTools.jar |
from:https://xuchaoji.com/index.php/archives/290/
View Details目标
创建Web项目的目录结构
可以启动Tomcat服务器
编写Servlet并访问成功
问题
IDEA社区版没有创建Web工程的选项
IDEA社区版没有Tomcat插件
由于在项目中经常需要使用到Java的对象拷贝和属性复制,如DTO、VO和数据库Entity之间的转换,因此本文对需要用到的相关方法、工具类做一个汇总,包括浅拷贝和深拷贝,方便在需要用到时作为参考。
View DetailsQueryWrapper queryWrapper = new QueryWrapper<>(); 查询指定字段 通过select()查询指定字段,同时可对字段进行Mysql函数处理
1 |
queryWrapper.select("service_code as serviceCode", "sum(num) as num"); |
设置limit 通过last(),效果等同于limit
1 |
queryWrapper.last("limit 0,5"); |
查询条件中使用函数 例如,在查询IP时,想使用INET_ATON()函数,可以使用apply()实现
1 2 |
queryWrapper.apply("INET_ATON(qsip) <= INET_ATON({0})", ipQuery); queryWrapper.apply("INET_ATON(zzip) >= INET_ATON({0})", ipQuery); |
from:https://blog.csdn.net/qq_42594278/article/details/106625280
View Details博主在最近的开发中又遇到了关于定时调度的开发任务,在定时调度其实有很多的第三方平台可以接入,但是其实在SpringBoot有自带的定时任务注解@Scheduled。@Scheduled可以通过注解配置快速实现方法的定时调度,直接在方法加上@Scheduled注解即可。 一.@Scheduled注解参数 1.cron参数 这个参数是最经常使用的参数,表示接收一个cron参数,cron它是一个表达式,最多接收7个参数,从左到右分别表示:秒 分 时 天 月 周 年;参数以空格隔开,其中年不是必须参数,可以省略。
1 2 3 4 5 6 7 8 |
/** * cron 一共可以有7个参数 以空格分开 其中年不是必须参数 * [秒] [分] [小时] [日] [月] [周] [年] * 一下表示 */ @Scheduled(cron ="0 0 0 * * * ?") public void testScheduledCron(){ } |
注意!!! 在使用时需要在类上添加注解@EnableScheduling,表示开启定时任务。 cron参数意义: 序号 含义 是否必填 入参范围 可填通配符 1 秒 是 0-59 , – * / 2 分 是 0-59 , – * / 3 时 是 0-23 , – * / 4 日 是 1-31 , – * ? / L W 5 月 是 1-12 , – * / 6 周(周一 ~ 周日) 是 1-7 , – * ? / L # 8 年 否 1970-2099 , – * / 常用通配符: *:表示所有值 比如用在日 表示每一天。 ?:表示不指定值 比如周配置 […]
View Details1.单表查询
1 2 3 4 5 6 7 8 9 |
@GetMapping("/list") public TableDataInfo list(Student student){ LambdaQueryWrapper<Student> lqw = new LambdaQueryWrapper<Student>(); lqw.eq(Student::getName, student.getName()); lqw.like(Student::getClass,student.getClass()); lqw.between("age",student.getAge1(),student.getAge2()); lqw.orderByAsc("age"); List<Student> list = studentService.list(lqw); } |
对应的sql语句为:
1 |
select * from student where name = '?' and class like '%?%' and age between '?' and '?' order by '?' asc |
1.1、单表查询的基本用法 函数名 说明 例子 eq 等于 例:eq(“name”,“张子”) ===> name = ‘张子’ ne 不等于 例:ne(“name”,“张子”) ===> name <> ‘张子’ gt 大于 例:gt(“age”,“18”) ===> age>18 lt 小于 例:lt(“age”,“18”) ===> age<18 between 在值1到值2之间 例:between(“age”,18,30) ===> 18<age<30’ like 模糊查询 例:like(“name”,“张”) ===> name like ‘%张%’ isNull 字段为NULL 例:isNull(“name”) ===> name is null 2、多表查询
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 |
//Controller @GetMapping("/listAndClass") public TableDataInfo listAndClass(Student student) { QueryWrapper<Student > qw = new QueryWrapper<Student >(); if(StringUtils.isNotBlank(student.getName())){ qw.eq("s.name",student.getName()); } if(StringUtils.isNotBlank(student.getClassName())){ qw.like("c.name",student.getClassName()); } startPage(); List<Student > list = studentService.listAndClass(qw); return getDataTable(list); } //Service List<Student> listAndClass(QueryWrapper<Student> qw); //Service impl @Override public List<Student> listAndClass(QueryWrapper<Student> qw) { return this.getBaseMapper().listAndClass(qw); } //Mapper @Select("select s.*,c.name from student s left join class c on s.id = c.student_id "+ "${ew.customSqlSegment}") List<YwSpaqjgDj> listAndClass(@Param(Constants.WRAPPER) QueryWrapper<Student> qw); |
from:https://www.cnblogs.com/gongss/p/16727090.html
View Details//SerializerFeature.WriteDateUseDateFormat 使用日期字段格式序列化(2017-01-01),而不是用时间戳表示日期 JSON.toJSONString(data, SerializerFeature.WriteDateUseDateFormat)); from:https://www.cnblogs.com/gossip/p/6963957.html
View Details