文章目录
随笔
-
java工程中出现红色感叹号,基本是build 中有问题,工程名上右键,build path --》configure build path–》libraries中有双重的架构软件或者双重的jar文件,解决方法是将多余的jar文件remove
java工程中添加dom4j-1.6.1.jar文件步骤:
一:右键最上层工程名,点击new–》source folder 创建lib文件夹。
二:将dom4j-1.6.1.jar文件复制到lib文件夹中。
三:选中dom4j-1.6.1.jar文件右键,build path–》add to build path
3.解决乱码代码:
idea中:tomcat配置时,Run/Debug Configurations 里在VM options填写 -Dfile.encoding=UTF-8
byte [] bytes = new byte[1024]; String s = "这是doGet方法"; bytes = s.getBytes("utf-8"); String s2 = new String(bytes); System.out.println(s2);
4.修改mysqlroot密码:
`ALTER` `user` `'root'``@``'localhost'` `IDENTIFIED ``BY` `'Cliu123#'`
此处有两点需要注意:
1、不需要flush privileges来刷新权限。
2、密码要包含大写字母,小写字母,数字,特殊符号。
5.mysql8版本中rank是关键字。
6.字符串拼接
"insert into paper(paper_id) values('"+ user +"')"
7.freemarker中的注释
<#-- 注释内容–>
8.正则表达式
可是查看文档1.6中的Pattern
@Test
public void test1(){
String s = "123456";
boolean b = s.matches("[0-9]*");
boolean matches = s.matches("\\d+");
System.out.println(b);
System.out.println(matches);
}
9.异常处理
运行时异常:RuntimeException
编译时异常:Exception(需要用throws抛出)
throws:处理异常的方式,把异常抛出,由调用者来处理
throw:制造异常的方式,并结束方法,(当throw一个异常,方法就结束)
public static void checkScore(int score){
if(score<0 || score>100){
throw new RuntimeExcwption("分数不符合要求");
}
System.out.println("成绩符合要求");
}
public static void checkScore(int score) throws Exception{
if(score<0 || score>100){
throw new Excwption("分数不符合要求");
}
System.out.println("成绩符合要求");
}
windows命令行设置支持UTF-8
(1)查看当前cmd页面支持的编码格式
命令行输入chcp
UTF8代码页的编号:65001
GBK(GB2312)编号是963
(2)更改
\1. 运行CMD;
\2. 输入 CHCP,回车查看当前的编码;
\3. 输入CHCP 65001,回车;
\4. 仅如此,还是不能支持UTF8的正常显示,你还要在窗体上右键,选择属性,来设置字体;
\5. 操作完上面几步后,即使你原来的字体里面没有显示Lucida Console这个字体,现在应该也能看到了。选择它。如果原来就有,可以选上它先试试,不行在执行上述步骤(这里补充:至少我本机需要CHCP 65001下,有朋友说不要);
\6. 选择只应用到本窗体,确认。
这时候,你的Console里面,应该支持UTF8了。
mysql中写入时间对象时修改配置文件:UTC改为CTT
jdbc.url=jdbc:mysql://127.0.0.1:3306/school_store_system?serverTimezone=CTT&useUnicode=true&characterEncoding=utf8
lambda表达式:
参考:https://www.jianshu.com/p/85affe38ce5c
语法:->分隔符的作用
(参数) -> 表达式
永远不要定义 result 的类型,lambda 表达式总是从上下文中推断出来的:
(String first, String second) -> Integer.compare(first.length(), second.length())
Method References(方法引用)
能不能再简洁一点?有的时候我们所要做的事情不过是调用其他类中方法来处理事件。
button.setOnClickListener(event -> System.out.println(event));
如果这样呢?
button.setOnAction(System.out::println);
表达式 System.out::println
属于一个方法引用(method reference), 相当于 lambda 表达式 x -> System.out.println(x)
链接:https://www.jianshu.com/p/85affe38ce5c
示例:
transferCast项目
package lambdaDemo;
import java.util.ArrayList;
import java.util.List;
public class LambdaDemoMain {
public static void main(String[] args) {
LambdaDemoService lambdaDemoService = (s)->{return "s";};//利用lambda省略了重新创一个 LambdaDemoService的实现类,实现接口sayHello的方法,而这个方法只在这里用一次。
System.out.println(lambdaDemoService.sayHello("输入啥都是’s‘"));
List<String> strings = new ArrayList<>();
strings.add("aa");
strings.add("bb");
strings.add("cc");
strings.forEach(System.out::println);//System.out::println//方法引用等效与:
//(str)->{System.out.println(str);}
for (String s :
strings) {
System.out.println(s);
}
}
}
/*
运行结果:
s
aa
bb
cc
aa
bb
cc
*/
package lambdaDemo;
public interface LambdaDemoService {
String sayHello(String s);
}
list相关:subList()方法
List<User> userList = new ArrayList<>();
userList.add(new User("zhd"));
//则此时的userList指向的原内容被改变
//如果需要让原来的内容不变则需要在列表重置前,克隆一份
List<User> userList2 = userList.subList(0,userList.size());
//此时再重置userList不会改变之前的内容。
userList = new ArrayList<>();//重置
seo搜索引擎优化
通过伪静态化达到搜索引擎优化的效果。
伪静态化:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<description>加载/WEB-INF/spring/目录下的所有XML作为Spring MVC的配置文件</description>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/spring-*.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<!-- 默认匹配所有的请求 -->
<!--伪静态化-->
<url-pattern>*.html</url-pattern>
</servlet-mapping>
sublime工具使用
纵列选择 ctrl+alt+下(亲测不行)或者shift+右键或者鼠标的按住滚轮拖动鼠标
在sublime中多行编辑时换行符在linux中无效,待解决。