1、String.format()的用法
- String.format(emailTemplate.toString(),riskContent);
二、url的编码和解码
1、编码:
- String str = URLEncoder.encode(“你好”,"UTF-8");//对“你好”进行UTF-8编码。
2、解码:
- Stringversion = URLDecoder.decode(str,"UTF-8");//对传到后台的字符串解码。
三、String
1、模板、在s%后面可以有string.fromat将已经编译好的字符串添加到此
- <table border="1" width="90%%">
- <tr>
- <td colspan="4" align="center">项目跟新报告</td>
- </tr>
- <tr>
- <td align="left">编号</td>
- <td align="left">项目名称</td>
- <td align="left">项目责任人</td>
- <td align="left">最后跟新时间</td>
- </tr>
- %s
- </table>
四、将double类型的值转换为字符串并且保留两位小数
- public String getHundred(String value, String value2) {
- // 将double类型的数字转换为带两位小数的字符串
- DecimalFormat df = new DecimalFormat("0.00");
- double num1 = Double.parseDouble(value);
- double num2 = Double.parseDouble(value2);
- double num3;
- if (num2 > 0) {
- num3 = num1 / num2;
- } else {
- num3 = 0;
- }
- return df.format(num3);
- }
五、数组、集合帮助类
1、 Arrays--数组帮助类
Collections--集合帮助类
2、截取集合前面的第0到第5条数据
六、类型转换
- 1、时间类型转换
- Date date = new Date();
- SimpleDateFormat ddd = new SimpleDateFormat("yyyy-MM-dd");
- final String time = ddd.format(date);
- 2、类型转换:
- 1、将“ind”转换为int类型 ind.intValue() <!--[if gte mso 9]><xml>
- 2、另一种转换
- public static void main(String[] args) {
- String s = "111";
- double number = Double.parseDouble(s);//转换为double类型
- System.out.println(number);
- int number2 = Integer.parseInt(s);//转换为int类型
- System.out.println(number2);
- }
七、 系统自带的获得唯一编码,每种语言都有
- select sys_guid() from dual; --oracle生成唯一标示
- java.util.UUID.randomUUID(); --java生成唯一标示
八、向页面返回数据
- //struts2封装
- renderText();
- rendet(xml,"sdsvs");
- //servlet
- write();
- write(xml,"ssss")
- //任意申明一个类都行
- Test test = new Test();
- String ttt = test.getClass().getResource("/").toString();
- String sqlday="";
- //得到传过来的类型-1、1(前一天或者后一天)
- String type=request.getParameter("types");
- //得到传过来的时间
- String datetime=request.getParameter("rqs");
- //日期类型
- Calendar c = Calendar.getInstance();
- //格式化时间类型
- SimpleDateFormat fam = new SimpleDateFormat("yyyy-MM-dd");
- //将传过来的时间转换为时间类型
- Date time = fam.parse(datetime);
- //将时间塞到Calendar对象中去
- c.setTime(time);
- //根据类型判断
- if(type.equals("-1")){
- c.set(Calendar.DATE,c.get(Calendar.DATE) - 1); //得到前一天
- }else{
- c.set(Calendar.DATE,c.get(Calendar.DATE) + 1);
- }
- //得到字符串类型的时间
- sqlday = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
- //申明map集合
- Map<String,String> map = new HashMap<String,String>();
- map.put("SXBM","30000009800754268913440300");
- map.put("SXBM2","300000098007542689134403001");
- map.put("SXBM3","300000098007542689134403002");
- //第一种方式,效率慢
- //将map键值(Key)迭代
- Iterator<String> iterator = map.keySet().iterator();
- while(iterator.hasNext()){
- //得到键值
- String key = (String)iterator.next();
- //得到value值
- String var = (String)map.get(key);
- js.put(key, var);
- }
- //第二种方式,效率快
- //类型可以强制转换
- Map map = new HashMap();
- Iterator iter = map.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- Object key = entry.getKey();
- Object val = entry.getValue();
- }
- DigestUtils.md5Hex("111111");
- public static void main(String[] args) {
- Map<String,String> map = new HashMap<String,String>();
- map.put("xiongmin-1","xiongmin-11");
- map.put("xiongmin-2","xiongmin-22");
- map.put("xiongmin-3","xiongmin-33");
- //循环map
- for (Map.Entry<String,String> entry : map.entrySet()){
- //取key
- System.out.println("key=" + entry.getKey());
- //取值
- System.out.println("value=" + entry.getValue());
- }
- }
- import java.net.URLDecoder;
- import java.net.URLEncoder;
- public class Test {
- public static void main(String[] args) {
- try {
- String str = "你妹%";
- //URLEncoder编码
- String urlEncoder = URLEncoder.encode(str,"utf-8");
- //URLDecoder解码
- String urlDreol = URLDecoder.decode(urlEncoder,"utf-8");
- System.out.println(urlEncoder);
- System.out.println(urlDreol);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
<< : 左移运算符,num << 1,相当于num乘以2的1次方
>> : 右移运算符,num >> 1,相当于num除以2的一次方
>>> : j>>>i 与 j/(int)(Math.pow(2,i))的结果相同,其中i和j是整形。
- System.out.println(8 << 1);
- System.out.println(8 << 2);
- System.out.println(8 << 3);
- System.out.println("------------------");
- System.out.println("");
- System.out.println(8 >> 1);
- System.out.println(8 >> 2);
- System.out.println(8 >> 3);
- System.out.println("------------------");
- System.out.println("");
- System.out.println(8 >>> 1);
- System.out.println(8 >>> 2);
- System.out.println(8 >>> 3);
16
32
64
------------------
4
2
1
------------------
4
2
1
17、使用正则表达式
- public static final String CURRENCY_FEN_REGEX = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,50})";
- if (!password.matches(CURRENCY_FEN_REGEX)) {
- return ajaxDoneError("密码至少存在一个大写字母,一个小写字母,一个数字,且长度为8-50位");
- }
18、判断两个类型是否相等
- package com.wanrong.adminWeb.SpdEsbForward;
- public class Text {
- public static void main(String[] args) {
- A ab = new B();
- A ac = new C();
- B bc = new C();
- B bb = new B();
- C cc = new C();
- // 对象实现一个接口,用这个对象和这个接口进行instanceof判断,都为true。
- System.out.println("ab instanceof A=" + (ab instanceof A));
- System.out.println("ac instanceof A=" + (ac instanceof A));
- System.out.println("bc instanceof A=" + (bc instanceof A));
- System.out.println("bb instanceof A=" + (bb instanceof A));
- System.out.println("cc instanceof A=" + (cc instanceof A));
- // 对象和父类进行instanceof判断,都为true
- System.out.println("ab instanceof B=" + (ab instanceof B));
- System.out.println("ac instanceof B=" + (ac instanceof B));
- System.out.println("bc instanceof B=" + (bc instanceof B));
- System.out.println("bb instanceof B=" + (bb instanceof B));
- System.out.println("cc instanceof B=" + (cc instanceof B));
- // 对象和他的子类进行instanceof判断为false
- System.out.println("ab instanceof C=" + (ab instanceof C));
- System.out.println("ac instanceof C=" + (ac instanceof C));
- System.out.println("bc instanceof C=" + (bc instanceof C));
- System.out.println("bb instanceof C=" + (bb instanceof C));
- System.out.println("cc instanceof C=" + (cc instanceof C));
- }
- }
- interface A {
- }
- class B implements A {
- }
- class C extends B {
- }
ab instanceof A=true
ac instanceof A=true
bc instanceof A=true
bb instanceof A=true
cc instanceof A=true
ab instanceof B=true
ac instanceof B=true
bc instanceof B=true
bb instanceof B=true
cc instanceof B=true
ab instanceof C=false
ac instanceof C=true
bc instanceof C=true
bb instanceof C=false
cc instanceof C=true
19、com.alibaba.fastjson.JSONObject,将json格式的数据转换为对象
- public <T> T getModel(String Data, Class<?> clazz) {
- return (T) JSONObject.parseObject(Data, clazz);
- }
二、url的编码和解码
1、编码:
- String str = URLEncoder.encode(“你好”,"UTF-8");//对“你好”进行UTF-8编码。
2、解码:
- Stringversion = URLDecoder.decode(str,"UTF-8");//对传到后台的字符串解码。
三、String
1、模板、在s%后面可以有string.fromat将已经编译好的字符串添加到此
- <table border="1" width="90%%">
- <tr>
- <td colspan="4" align="center">项目跟新报告</td>
- </tr>
- <tr>
- <td align="left">编号</td>
- <td align="left">项目名称</td>
- <td align="left">项目责任人</td>
- <td align="left">最后跟新时间</td>
- </tr>
- %s
- </table>
二、url的编码和解码
1、编码:
- String str = URLEncoder.encode(“你好”,"UTF-8");//对“你好”进行UTF-8编码。
2、解码:
- Stringversion = URLDecoder.decode(str,"UTF-8");//对传到后台的字符串解码。
三、String
1、模板、在s%后面可以有string.fromat将已经编译好的字符串添加到此
- <table border="1" width="90%%">
- <tr>
- <td colspan="4" align="center">项目跟新报告</td>
- </tr>
- <tr>
- <td align="left">编号</td>
- <td align="left">项目名称</td>
- <td align="left">项目责任人</td>
- <td align="left">最后跟新时间</td>
- </tr>
- %s
- </table>
四、将double类型的值转换为字符串并且保留两位小数
- public String getHundred(String value, String value2) {
- // 将double类型的数字转换为带两位小数的字符串
- DecimalFormat df = new DecimalFormat("0.00");
- double num1 = Double.parseDouble(value);
- double num2 = Double.parseDouble(value2);
- double num3;
- if (num2 > 0) {
- num3 = num1 / num2;
- } else {
- num3 = 0;
- }
- return df.format(num3);
- }
五、数组、集合帮助类
1、 Arrays--数组帮助类
Collections--集合帮助类
2、截取集合前面的第0到第5条数据
六、类型转换
- 1、时间类型转换
- Date date = new Date();
- SimpleDateFormat ddd = new SimpleDateFormat("yyyy-MM-dd");
- final String time = ddd.format(date);
- 2、类型转换:
- 1、将“ind”转换为int类型 ind.intValue() <!--[if gte mso 9]><xml>
- 2、另一种转换
- public static void main(String[] args) {
- String s = "111";
- double number = Double.parseDouble(s);//转换为double类型
- System.out.println(number);
- int number2 = Integer.parseInt(s);//转换为int类型
- System.out.println(number2);
- }
七、 系统自带的获得唯一编码,每种语言都有
- select sys_guid() from dual; --oracle生成唯一标示
- java.util.UUID.randomUUID(); --java生成唯一标示
八、向页面返回数据
- //struts2封装
- renderText();
- rendet(xml,"sdsvs");
- //servlet
- write();
- write(xml,"ssss")
- //任意申明一个类都行
- Test test = new Test();
- String ttt = test.getClass().getResource("/").toString();
- String sqlday="";
- //得到传过来的类型-1、1(前一天或者后一天)
- String type=request.getParameter("types");
- //得到传过来的时间
- String datetime=request.getParameter("rqs");
- //日期类型
- Calendar c = Calendar.getInstance();
- //格式化时间类型
- SimpleDateFormat fam = new SimpleDateFormat("yyyy-MM-dd");
- //将传过来的时间转换为时间类型
- Date time = fam.parse(datetime);
- //将时间塞到Calendar对象中去
- c.setTime(time);
- //根据类型判断
- if(type.equals("-1")){
- c.set(Calendar.DATE,c.get(Calendar.DATE) - 1); //得到前一天
- }else{
- c.set(Calendar.DATE,c.get(Calendar.DATE) + 1);
- }
- //得到字符串类型的时间
- sqlday = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
- //申明map集合
- Map<String,String> map = new HashMap<String,String>();
- map.put("SXBM","30000009800754268913440300");
- map.put("SXBM2","300000098007542689134403001");
- map.put("SXBM3","300000098007542689134403002");
- //第一种方式,效率慢
- //将map键值(Key)迭代
- Iterator<String> iterator = map.keySet().iterator();
- while(iterator.hasNext()){
- //得到键值
- String key = (String)iterator.next();
- //得到value值
- String var = (String)map.get(key);
- js.put(key, var);
- }
- //第二种方式,效率快
- //类型可以强制转换
- Map map = new HashMap();
- Iterator iter = map.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- Object key = entry.getKey();
- Object val = entry.getValue();
- }
- DigestUtils.md5Hex("111111");
- public static void main(String[] args) {
- Map<String,String> map = new HashMap<String,String>();
- map.put("xiongmin-1","xiongmin-11");
- map.put("xiongmin-2","xiongmin-22");
- map.put("xiongmin-3","xiongmin-33");
- //循环map
- for (Map.Entry<String,String> entry : map.entrySet()){
- //取key
- System.out.println("key=" + entry.getKey());
- //取值
- System.out.println("value=" + entry.getValue());
- }
- }
- import java.net.URLDecoder;
- import java.net.URLEncoder;
- public class Test {
- public static void main(String[] args) {
- try {
- String str = "你妹%";
- //URLEncoder编码
- String urlEncoder = URLEncoder.encode(str,"utf-8");
- //URLDecoder解码
- String urlDreol = URLDecoder.decode(urlEncoder,"utf-8");
- System.out.println(urlEncoder);
- System.out.println(urlDreol);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
<< : 左移运算符,num << 1,相当于num乘以2的1次方
>> : 右移运算符,num >> 1,相当于num除以2的一次方
>>> : j>>>i 与 j/(int)(Math.pow(2,i))的结果相同,其中i和j是整形。
- System.out.println(8 << 1);
- System.out.println(8 << 2);
- System.out.println(8 << 3);
- System.out.println("------------------");
- System.out.println("");
- System.out.println(8 >> 1);
- System.out.println(8 >> 2);
- System.out.println(8 >> 3);
- System.out.println("------------------");
- System.out.println("");
- System.out.println(8 >>> 1);
- System.out.println(8 >>> 2);
- System.out.println(8 >>> 3);
16
32
64
------------------
4
2
1
------------------
4
2
1
17、使用正则表达式
- public static final String CURRENCY_FEN_REGEX = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,50})";
- if (!password.matches(CURRENCY_FEN_REGEX)) {
- return ajaxDoneError("密码至少存在一个大写字母,一个小写字母,一个数字,且长度为8-50位");
- }
18、判断两个类型是否相等
- package com.wanrong.adminWeb.SpdEsbForward;
- public class Text {
- public static void main(String[] args) {
- A ab = new B();
- A ac = new C();
- B bc = new C();
- B bb = new B();
- C cc = new C();
- // 对象实现一个接口,用这个对象和这个接口进行instanceof判断,都为true。
- System.out.println("ab instanceof A=" + (ab instanceof A));
- System.out.println("ac instanceof A=" + (ac instanceof A));
- System.out.println("bc instanceof A=" + (bc instanceof A));
- System.out.println("bb instanceof A=" + (bb instanceof A));
- System.out.println("cc instanceof A=" + (cc instanceof A));
- // 对象和父类进行instanceof判断,都为true
- System.out.println("ab instanceof B=" + (ab instanceof B));
- System.out.println("ac instanceof B=" + (ac instanceof B));
- System.out.println("bc instanceof B=" + (bc instanceof B));
- System.out.println("bb instanceof B=" + (bb instanceof B));
- System.out.println("cc instanceof B=" + (cc instanceof B));
- // 对象和他的子类进行instanceof判断为false
- System.out.println("ab instanceof C=" + (ab instanceof C));
- System.out.println("ac instanceof C=" + (ac instanceof C));
- System.out.println("bc instanceof C=" + (bc instanceof C));
- System.out.println("bb instanceof C=" + (bb instanceof C));
- System.out.println("cc instanceof C=" + (cc instanceof C));
- }
- }
- interface A {
- }
- class B implements A {
- }
- class C extends B {
- }
ab instanceof A=true
ac instanceof A=true
bc instanceof A=true
bb instanceof A=true
cc instanceof A=true
ab instanceof B=true
ac instanceof B=true
bc instanceof B=true
bb instanceof B=true
cc instanceof B=true
ab instanceof C=false
ac instanceof C=true
bc instanceof C=true
bb instanceof C=false
cc instanceof C=true
四、将double类型的值转换为字符串并且保留两位小数
- public String getHundred(String value, String value2) {
- // 将double类型的数字转换为带两位小数的字符串
- DecimalFormat df = new DecimalFormat("0.00");
- double num1 = Double.parseDouble(value);
- double num2 = Double.parseDouble(value2);
- double num3;
- if (num2 > 0) {
- num3 = num1 / num2;
- } else {
- num3 = 0;
- }
- return df.format(num3);
- }
五、数组、集合帮助类
1、 Arrays--数组帮助类
Collections--集合帮助类
2、截取集合前面的第0到第5条数据
六、类型转换
- 1、时间类型转换
- Date date = new Date();
- SimpleDateFormat ddd = new SimpleDateFormat("yyyy-MM-dd");
- final String time = ddd.format(date);
- 2、类型转换:
- 1、将“ind”转换为int类型 ind.intValue() <!--[if gte mso 9]><xml>
- 2、另一种转换
- public static void main(String[] args) {
- String s = "111";
- double number = Double.parseDouble(s);//转换为double类型
- System.out.println(number);
- int number2 = Integer.parseInt(s);//转换为int类型
- System.out.println(number2);
- }
七、 系统自带的获得唯一编码,每种语言都有
- select sys_guid() from dual; --oracle生成唯一标示
- java.util.UUID.randomUUID(); --java生成唯一标示
八、向页面返回数据
- //struts2封装
- renderText();
- rendet(xml,"sdsvs");
- //servlet
- write();
- write(xml,"ssss")
- //任意申明一个类都行
- Test test = new Test();
- String ttt = test.getClass().getResource("/").toString();
- String sqlday="";
- //得到传过来的类型-1、1(前一天或者后一天)
- String type=request.getParameter("types");
- //得到传过来的时间
- String datetime=request.getParameter("rqs");
- //日期类型
- Calendar c = Calendar.getInstance();
- //格式化时间类型
- SimpleDateFormat fam = new SimpleDateFormat("yyyy-MM-dd");
- //将传过来的时间转换为时间类型
- Date time = fam.parse(datetime);
- //将时间塞到Calendar对象中去
- c.setTime(time);
- //根据类型判断
- if(type.equals("-1")){
- c.set(Calendar.DATE,c.get(Calendar.DATE) - 1); //得到前一天
- }else{
- c.set(Calendar.DATE,c.get(Calendar.DATE) + 1);
- }
- //得到字符串类型的时间
- sqlday = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
- //申明map集合
- Map<String,String> map = new HashMap<String,String>();
- map.put("SXBM","30000009800754268913440300");
- map.put("SXBM2","300000098007542689134403001");
- map.put("SXBM3","300000098007542689134403002");
- //第一种方式,效率慢
- //将map键值(Key)迭代
- Iterator<String> iterator = map.keySet().iterator();
- while(iterator.hasNext()){
- //得到键值
- String key = (String)iterator.next();
- //得到value值
- String var = (String)map.get(key);
- js.put(key, var);
- }
- //第二种方式,效率快
- //类型可以强制转换
- Map map = new HashMap();
- Iterator iter = map.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- Object key = entry.getKey();
- Object val = entry.getValue();
- }
- DigestUtils.md5Hex("111111");
- public static void main(String[] args) {
- Map<String,String> map = new HashMap<String,String>();
- map.put("xiongmin-1","xiongmin-11");
- map.put("xiongmin-2","xiongmin-22");
- map.put("xiongmin-3","xiongmin-33");
- //循环map
- for (Map.Entry<String,String> entry : map.entrySet()){
- //取key
- System.out.println("key=" + entry.getKey());
- //取值
- System.out.println("value=" + entry.getValue());
- }
- }
- import java.net.URLDecoder;
- import java.net.URLEncoder;
- public class Test {
- public static void main(String[] args) {
- try {
- String str = "你妹%";
- //URLEncoder编码
- String urlEncoder = URLEncoder.encode(str,"utf-8");
- //URLDecoder解码
- String urlDreol = URLDecoder.decode(urlEncoder,"utf-8");
- System.out.println(urlEncoder);
- System.out.println(urlDreol);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
<< : 左移运算符,num << 1,相当于num乘以2的1次方
>> : 右移运算符,num >> 1,相当于num除以2的一次方
>>> : j>>>i 与 j/(int)(Math.pow(2,i))的结果相同,其中i和j是整形。
- System.out.println(8 << 1);
- System.out.println(8 << 2);
- System.out.println(8 << 3);
- System.out.println("------------------");
- System.out.println("");
- System.out.println(8 >> 1);
- System.out.println(8 >> 2);
- System.out.println(8 >> 3);
- System.out.println("------------------");
- System.out.println("");
- System.out.println(8 >>> 1);
- System.out.println(8 >>> 2);
- System.out.println(8 >>> 3);
16
32
64
------------------
4
2
1
------------------
4
2
1
17、使用正则表达式
- public static final String CURRENCY_FEN_REGEX = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,50})";
- if (!password.matches(CURRENCY_FEN_REGEX)) {
- return ajaxDoneError("密码至少存在一个大写字母,一个小写字母,一个数字,且长度为8-50位");
- }
18、判断两个类型是否相等
- package com.wanrong.adminWeb.SpdEsbForward;
- public class Text {
- public static void main(String[] args) {
- A ab = new B();
- A ac = new C();
- B bc = new C();
- B bb = new B();
- C cc = new C();
- // 对象实现一个接口,用这个对象和这个接口进行instanceof判断,都为true。
- System.out.println("ab instanceof A=" + (ab instanceof A));
- System.out.println("ac instanceof A=" + (ac instanceof A));
- System.out.println("bc instanceof A=" + (bc instanceof A));
- System.out.println("bb instanceof A=" + (bb instanceof A));
- System.out.println("cc instanceof A=" + (cc instanceof A));
- // 对象和父类进行instanceof判断,都为true
- System.out.println("ab instanceof B=" + (ab instanceof B));
- System.out.println("ac instanceof B=" + (ac instanceof B));
- System.out.println("bc instanceof B=" + (bc instanceof B));
- System.out.println("bb instanceof B=" + (bb instanceof B));
- System.out.println("cc instanceof B=" + (cc instanceof B));
- // 对象和他的子类进行instanceof判断为false
- System.out.println("ab instanceof C=" + (ab instanceof C));
- System.out.println("ac instanceof C=" + (ac instanceof C));
- System.out.println("bc instanceof C=" + (bc instanceof C));
- System.out.println("bb instanceof C=" + (bb instanceof C));
- System.out.println("cc instanceof C=" + (cc instanceof C));
- }
- }
- interface A {
- }
- class B implements A {
- }
- class C extends B {
- }
ab instanceof A=true
ac instanceof A=true
bc instanceof A=true
bb instanceof A=true
cc instanceof A=true
ab instanceof B=true
ac instanceof B=true
bc instanceof B=true
bb instanceof B=true
cc instanceof B=true
ab instanceof C=false
ac instanceof C=true
bc instanceof C=true
bb instanceof C=false
cc instanceof C=true
- public String getHundred(String value, String value2) {
- // 将double类型的数字转换为带两位小数的字符串
- DecimalFormat df = new DecimalFormat("0.00");
- double num1 = Double.parseDouble(value);
- double num2 = Double.parseDouble(value2);
- double num3;
- if (num2 > 0) {
- num3 = num1 / num2;
- } else {
- num3 = 0;
- }
- return df.format(num3);
- }
五、数组、集合帮助类
1、 Arrays--数组帮助类
Collections--集合帮助类
2、截取集合前面的第0到第5条数据
六、类型转换
- 1、时间类型转换
- Date date = new Date();
- SimpleDateFormat ddd = new SimpleDateFormat("yyyy-MM-dd");
- final String time = ddd.format(date);
- 2、类型转换:
- 1、将“ind”转换为int类型 ind.intValue() <!--[if gte mso 9]><xml>
- 2、另一种转换
- public static void main(String[] args) {
- String s = "111";
- double number = Double.parseDouble(s);//转换为double类型
- System.out.println(number);
- int number2 = Integer.parseInt(s);//转换为int类型
- System.out.println(number2);
- }
七、 系统自带的获得唯一编码,每种语言都有
- select sys_guid() from dual; --oracle生成唯一标示
- java.util.UUID.randomUUID(); --java生成唯一标示
八、向页面返回数据
- //struts2封装
- renderText();
- rendet(xml,"sdsvs");
- //servlet
- write();
- write(xml,"ssss")
- //任意申明一个类都行
- Test test = new Test();
- String ttt = test.getClass().getResource("/").toString();
- String sqlday="";
- //得到传过来的类型-1、1(前一天或者后一天)
- String type=request.getParameter("types");
- //得到传过来的时间
- String datetime=request.getParameter("rqs");
- //日期类型
- Calendar c = Calendar.getInstance();
- //格式化时间类型
- SimpleDateFormat fam = new SimpleDateFormat("yyyy-MM-dd");
- //将传过来的时间转换为时间类型
- Date time = fam.parse(datetime);
- //将时间塞到Calendar对象中去
- c.setTime(time);
- //根据类型判断
- if(type.equals("-1")){
- c.set(Calendar.DATE,c.get(Calendar.DATE) - 1); //得到前一天
- }else{
- c.set(Calendar.DATE,c.get(Calendar.DATE) + 1);
- }
- //得到字符串类型的时间
- sqlday = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
- //申明map集合
- Map<String,String> map = new HashMap<String,String>();
- map.put("SXBM","30000009800754268913440300");
- map.put("SXBM2","300000098007542689134403001");
- map.put("SXBM3","300000098007542689134403002");
- //第一种方式,效率慢
- //将map键值(Key)迭代
- Iterator<String> iterator = map.keySet().iterator();
- while(iterator.hasNext()){
- //得到键值
- String key = (String)iterator.next();
- //得到value值
- String var = (String)map.get(key);
- js.put(key, var);
- }
- //第二种方式,效率快
- //类型可以强制转换
- Map map = new HashMap();
- Iterator iter = map.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- Object key = entry.getKey();
- Object val = entry.getValue();
- }
十二、MD5加密
- DigestUtils.md5Hex("111111");
- public static void main(String[] args) {
- Map<String,String> map = new HashMap<String,String>();
- map.put("xiongmin-1","xiongmin-11");
- map.put("xiongmin-2","xiongmin-22");
- map.put("xiongmin-3","xiongmin-33");
- //循环map
- for (Map.Entry<String,String> entry : map.entrySet()){
- //取key
- System.out.println("key=" + entry.getKey());
- //取值
- System.out.println("value=" + entry.getValue());
- }
- }
- import java.net.URLDecoder;
- import java.net.URLEncoder;
- public class Test {
- public static void main(String[] args) {
- try {
- String str = "你妹%";
- //URLEncoder编码
- String urlEncoder = URLEncoder.encode(str,"utf-8");
- //URLDecoder解码
- String urlDreol = URLDecoder.decode(urlEncoder,"utf-8");
- System.out.println(urlEncoder);
- System.out.println(urlDreol);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
将jar包拷贝到:jdk\jre\lib\ext目录下 16、java中有三种移位运算符
<< : 左移运算符,num << 1,相当于num乘以2的1次方
>> : 右移运算符,num >> 1,相当于num除以2的一次方
>>> : j>>>i 与 j/(int)(Math.pow(2,i))的结果相同,其中i和j是整形。
- System.out.println(8 << 1);
- System.out.println(8 << 2);
- System.out.println(8 << 3);
- System.out.println("------------------");
- System.out.println("");
- System.out.println(8 >> 1);
- System.out.println(8 >> 2);
- System.out.println(8 >> 3);
- System.out.println("------------------");
- System.out.println("");
- System.out.println(8 >>> 1);
- System.out.println(8 >>> 2);
- System.out.println(8 >>> 3);
16
32
64
------------------
4
2
1
------------------
4
2
1
17、使用正则表达式
- public static final String CURRENCY_FEN_REGEX = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,50})";
- if (!password.matches(CURRENCY_FEN_REGEX)) {
- return ajaxDoneError("密码至少存在一个大写字母,一个小写字母,一个数字,且长度为8-50位");
- }
18、判断两个类型是否相等
- package com.wanrong.adminWeb.SpdEsbForward;
- public class Text {
- public static void main(String[] args) {
- A ab = new B();
- A ac = new C();
- B bc = new C();
- B bb = new B();
- C cc = new C();
- // 对象实现一个接口,用这个对象和这个接口进行instanceof判断,都为true。
- System.out.println("ab instanceof A=" + (ab instanceof A));
- System.out.println("ac instanceof A=" + (ac instanceof A));
- System.out.println("bc instanceof A=" + (bc instanceof A));
- System.out.println("bb instanceof A=" + (bb instanceof A));
- System.out.println("cc instanceof A=" + (cc instanceof A));
- // 对象和父类进行instanceof判断,都为true
- System.out.println("ab instanceof B=" + (ab instanceof B));
- System.out.println("ac instanceof B=" + (ac instanceof B));
- System.out.println("bc instanceof B=" + (bc instanceof B));
- System.out.println("bb instanceof B=" + (bb instanceof B));
- System.out.println("cc instanceof B=" + (cc instanceof B));
- // 对象和他的子类进行instanceof判断为false
- System.out.println("ab instanceof C=" + (ab instanceof C));
- System.out.println("ac instanceof C=" + (ac instanceof C));
- System.out.println("bc instanceof C=" + (bc instanceof C));
- System.out.println("bb instanceof C=" + (bb instanceof C));
- System.out.println("cc instanceof C=" + (cc instanceof C));
- }
- }
- interface A {
- }
- class B implements A {
- }
- class C extends B {
- }
ab instanceof A=true
ac instanceof A=true
bc instanceof A=true
bb instanceof A=true
cc instanceof A=true
ab instanceof B=true
ac instanceof B=true
bc instanceof B=true
bb instanceof B=true
cc instanceof B=true
ab instanceof C=false
ac instanceof C=true
bc instanceof C=true
bb instanceof C=false
cc instanceof C=true
19、com.alibaba.fastjson.JSONObject,将json格式的数据转换为对象
- public <T> T getModel(String Data, Class<?> clazz) {
- return (T) JSONObject.parseObject(Data, clazz);
- }
19、com.alibaba.fastjson.JSONObject,将json格式的数据转换为对象
- public <T> T getModel(String Data, Class<?> clazz) {
- return (T) JSONObject.parseObject(Data, clazz);
- }