|
oracle10g以上版本提供行转列组合成字符串函数wm_concat,注意跟其他字段一起select的时候要用group by
例如有个users表如下:
id yhm xm
1 001 小唐
2 002 小李
3 003 小张
select wm_concat(yhm) 用户名, wm_concat(xm) 姓名 from users
执行结果为:
用户名 姓名
001,002,003 小唐,小李,小张
public static String lastMonFirstDay(){ Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; cal.set(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.DAY_OF_MONTH, -1); int day = cal.get(Calendar.DAY_OF_MONTH); String months = ""; String days = ""; if (month > 1) { month--; } else { year--; month = 12; } if (!(String.valueOf(month).length() > 1)) { months = "0" + month; } else { months = String.valueOf(month); } if (!(String.valueOf(day).length() > 1)) { days = "0" + day; } else { days = String.valueOf(day); } String firstDay = "" + year + "-" + months + "-01"; String[] lastMonth = new String[2]; lastMonth[0] = firstDay; return firstDay; } public static String lastMonLastDay(){ Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; cal.set(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.DAY_OF_MONTH, -1); int day = cal.get(Calendar.DAY_OF_MONTH); String months = ""; String days = ""; if (month > 1) { month--; } else { year--; month = 12; } if (!(String.valueOf(month).length() > 1)) { months = "0" + month; } else { months = String.valueOf(month); } if (!(String.valueOf(day).length() > 1)) { days = "0" + day; } else { days = String.valueOf(day); } String lastDay = "" + year + "-" + months + "-" + days; String[] lastMonth = new String[2]; lastMonth[1] = lastDay; return lastDay; }
首先导入使用jar包:activation.jar,commons-logging-1.0.4.jar,mail.jar,spring.jar
1、使用xml配置javamail:
在classpath底下新建application-mail.xml,内容如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
-
- <bean id="mailSender"
- class="org.springframework.mail.javamail.JavaMailSenderImpl">
- <property name="host">
- <value>stmp.163.com</value>
- </property>
- <property name="javaMailProperties">
- <props>
- <prop key="mail.smtp.auth">true</prop>
- <prop key="mail.smtp.timeout">25000</prop>
- </props>
- </property>
- <property name="username">
- <value>xxxx@163.com</value>
- </property>
- <property name="password">
- <value>xxxxxx</value>
- </property>
- </bean>
- </beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!-- 注意:这里的参数(如用户名、密码)都是针对邮件发送者的 -->
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host">
<value>stmp.163.com</value>
</property>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.timeout">25000</prop>
</props>
</property>
<property name="username">
<value>xxxx@163.com</value>
</property>
<property name="password">
<value>xxxxxx</value>
</property>
</bean>
</beans>
或者把以上的Beans配置到applicaiont.xml里面也可以。
2、发送Email类:
- public class SendMail {
- public ApplicationContext ctx = null;
- public SendMail() {
-
- ctx = new ClassPathXmlApplicationContext("applicationContext-mail.xml");
- }
- public void send() {
-
- JavaMailSender sender = (JavaMailSender) ctx.getBean("mailSender");
- SimpleMailMessage mail = new SimpleMailMessage();
-
-
- try {
- mail.setTo("xxx@qq.com");
- mail.setFrom("xxxx@163.com");
- mail.setSubject("spring mail test!");
- mail.setText("springMail的简单发送测试");
- sender.send(mail);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
public class SendMail {
public ApplicationContext ctx = null;
public SendMail() {
//获取上下文
ctx = new ClassPathXmlApplicationContext("applicationContext-mail.xml");
}
public void send() {
//获取JavaMailSender bean
JavaMailSender sender = (JavaMailSender) ctx.getBean("mailSender");
SimpleMailMessage mail = new SimpleMailMessage(); //注意SimpleMailMessage只能用来发送text格式的邮件
try {
mail.setTo("xxx@qq.com");//接受者
mail.setFrom("xxxx@163.com");//发送者,这里还可以另起Email别名,不用和xml里的username一致
mail.setSubject("spring mail test!");//主题
mail.setText("springMail的简单发送测试");//邮件内容
sender.send(mail);
} catch (Exception e) {
e.printStackTrace();
}
}
发送html格式的Email:
- public class SendMail {
- public ApplicationContext ctx = null;
- public SendMail() {
-
- ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
- }
- public void send() {
-
- JavaMailSender sender = (JavaMailSender) ctx.getBean("mailSender");
- JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
- MimeMessage mailMessage = senderImpl.createMimeMessage();
-
- MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,true,"utf-8");
- try {
- messageHelper.setTo(email.getEmail());
- messageHelper.setFrom("xxx@163.com");
- messageHelper.setSubject("测试邮件");
-
- messageHelper.setText("<html><head></head><body><h1>hello!!chao.wang</h1></body></html>",true);
- sender.send(mailMessage);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
public class SendMail {
public ApplicationContext ctx = null;
public SendMail() {
//获取上下文
ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
}
public void send() {
//获取JavaMailSender bean
JavaMailSender sender = (JavaMailSender) ctx.getBean("mailSender");
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
MimeMessage mailMessage = senderImpl.createMimeMessage();
//设置utf-8或GBK编码,否则邮件会有乱码
MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,true,"utf-8");
try {
messageHelper.setTo(email.getEmail());//接受者
messageHelper.setFrom("xxx@163.com");//发送者
messageHelper.setSubject("测试邮件");//主题
//邮件内容,注意加参数true,表示启用html格式
messageHelper.setText("<html><head></head><body><h1>hello!!chao.wang</h1></body></html>",true);
sender.send(mailMessage);
} catch (Exception e) {
e.printStackTrace();
}
}
发送html格式并带有附件的Email:
- public class SendMail {
- public ApplicationContext ctx = null;
- public SendMail() {
-
- ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
- }
- public void send() {
-
- JavaMailSender sender = (JavaMailSender) ctx.getBean("mailSender");
- JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
- MimeMessage mailMessage = senderImpl.createMimeMessage();
-
- MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,true,"utf-8");
- try {
- messageHelper.setTo(email.getEmail());
- messageHelper.setFrom("xxx@163.com");
- messageHelper.setSubject("测试邮件");
-
- messageHelper.setText("<html><head></head><body><h1>hello!!chao.wang</h1></body></html>",true);
-
- messageHelper.addInline("a", new File("E:/xiezi.jpg"));
- messageHelper.addInline("b", new File("E:/logo.png"));
- File file=new File("E:/测试中文文件.rar");
-
- messageHelper.addAttachment(MimeUtility.encodeWord(file.getName()), file);
- sender.send(mailMessage);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public class TestApp {
-
- public static void main(String[] args) {
-
- List<String> list = new ArrayList<String>();
- list.add("蹇伟");
- list.add("Jerval");
- list.add("杰威");
- Object[] objects = list.toArray();
- System.out.println("objects:"+Arrays.toString(objects));
- String[] strings1 = new String[list.size()];
- list.toArray(strings1);
- System.out.println("strings1:"+Arrays.toString(strings1));
- String[] strings2 = list.toArray(new String[0]);
- System.out.println("strings2:"+Arrays.toString(strings2));
-
- String[] ss = {"JJ","KK"};
- List<String> list1 = Arrays.asList(ss);
- List<String> list2 = Arrays.asList("AAA","BBB");
- System.out.println(list1);
- System.out.println(list2);
-
- List<String> list3 = new ArrayList<String>(new HashSet<String>());
-
- Set<String> set = new HashSet<String>(new ArrayList<String>());
-
- String[] strs = {"AA","BB"};
- Set<String> set2 = new HashSet<String>(Arrays.asList(strs));
- System.out.println(set2);
-
- Set<String> set3 = new HashSet<String>(Arrays.asList("PP","OO"));
- String[] strSet = new String[set3.size()];
- set3.toArray(strSet);
- System.out.println(Arrays.toString(strSet));
-
- Map<String, String> map = new HashMap<String, String>();
- map.put("YYY", "UUU");
- map.put("RRR", "TTT");
-
- Set<String> mapKeySet = map.keySet();
-
- Set<String> mapValuesSet = new HashSet<String>(map.values());
-
- List<String> mapValuesList = new ArrayList<String>(map.values());
-
- }
- }
public Integer batchInsertEntitylist(final List<Entity> list) {
return (Integer) this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch(); int batch = 0; int count = 0; for (Entity entity: list) { executor.insert("insertEntitylist", entity); batch++; if (batch == 500) { executor.executeBatch(); batch = 0; } } executor.executeBatch(); count = 1; return count; }
}); }
ASCII码表 |
信息在计算机上是用二进制表示的,这种表示法让人理解就很困难。因此计算机上都配有输入和输出设备,这些设备的主要目的就是,以一种人类可阅读的形式将信息在这些设备上显示出来供人阅读理解。为保证人类和设备,设备和计算机之间能进行正确的信息交换,人们编制的统一的信息交换代码,这就是ASCII码表,它的全称是“美国信息交换标准代码”。
|
八进制 |
十六进制 |
十进制 |
字符 |
八进制 |
十六进制 |
十进制 |
字符 |
00 |
00 |
0 |
nul |
100 |
40 |
64 |
@ |
01 |
01 |
1 |
soh |
101 |
41 |
65 |
A |
02 |
02 |
2 |
stx |
102 |
42 |
66 |
B |
03 |
03 |
3 |
etx |
103 |
43 |
67 |
C |
04 |
04 |
4 |
eot |
104 |
44 |
68 |
D |
05 |
05 |
5 |
enq |
105 |
45 |
69 |
E |
06 |
06 |
6 |
ack |
106 |
46 |
70 |
F |
07 |
07 |
7 |
bel |
107 |
47 |
71 |
G |
10 |
08 |
8 |
bs |
110 |
48 |
72 |
H |
11 |
09 |
9 |
ht |
111 |
49 |
73 |
I |
12 |
0a |
10 |
nl |
112 |
4a |
74 |
J |
13 |
0b |
11 |
vt |
113 |
4b |
75 |
K |
14 |
0c |
12 |
ff |
114 |
4c |
76 |
L |
15 |
0d |
13 |
er |
115 |
4d |
77 |
M |
16 |
0e |
14 |
so |
116 |
4e |
78 |
N |
17 |
0f |
15 |
si |
117 |
4f |
79 |
O |
20 |
10 |
16 |
dle |
120 |
50 |
80 |
P |
21 |
11 |
17 |
dc1 |
121 |
51 |
81 |
Q |
22 |
12 |
18 |
dc2 |
122 |
52 |
82 |
R |
23 |
13 |
19 |
dc3 |
123 |
53 |
83 |
S |
24 |
14 |
20 |
dc4 |
124 |
54 |
84 |
T |
25 |
15 |
21 |
nak |
125 |
55 |
85 |
U |
26 |
16 |
22 |
syn |
126 |
56 |
86 |
V |
27 |
17 |
23 |
etb |
127 |
57 |
87 |
W |
30 |
18 |
24 |
can |
130 |
58 |
88 |
X |
31 |
19 |
25 |
em |
131 |
59 |
89 |
Y |
32 |
1a |
26 |
sub |
132 |
5a |
90 |
Z |
33 |
1b |
27 |
esc |
133 |
5b |
91 |
[ |
34 |
1c |
28 |
fs |
134 |
5c |
92 |
\ |
35 |
1d |
29 |
gs |
135 |
5d |
93 |
] |
36 |
1e |
30 |
re |
136 |
5e |
94 |
^ |
37 |
1f |
31 |
us |
137 |
5f |
95 |
_ |
40 |
20 |
32 |
sp |
140 |
60 |
96 |
' |
41 |
21 |
33 |
! |
141 |
61 |
97 |
a |
42 |
22 |
34 |
" |
142 |
62 |
98 |
b |
43 |
23 |
35 |
# |
143 |
63 |
99 |
c |
44 |
24 |
36 |
$ |
144 |
64 |
100 |
d |
45 |
25 |
37 |
% |
145 |
65 |
101 |
e |
46 |
26 |
38 |
& |
146 |
66 |
102 |
f |
47 |
27 |
39 |
` |
147 |
67 |
103 |
g |
50 |
28 |
40 |
( |
150 |
68 |
104 |
h |
51 |
29 |
41 |
) |
151 |
69 |
105 |
i |
52 |
2a |
42 |
* |
152 |
6a |
106 |
j |
53 |
2b |
43 |
+ |
153 |
6b |
107 |
k |
54 |
2c |
44 |
, |
154 |
6c |
108 |
l |
55 |
2d |
45 |
- |
155 |
6d |
109 |
m |
56 |
2e |
46 |
. |
156 |
6e |
110 |
n |
57 |
2f |
47 |
/ |
157 |
6f |
111 |
o |
60 |
30 |
48 |
0 |
160 |
70 |
112 |
p |
61 |
31 |
49 |
1 |
161 |
71 |
113 |
q |
62 |
32 |
50 |
2 |
162 |
72 |
114 |
r |
63 |
33 |
51 |
3 |
163 |
73 |
115 |
s |
64 |
34 |
52 |
4 |
164 |
74 |
116 |
t |
65 |
35 |
53 |
5 |
165 |
75 |
117 |
u |
66 |
36 |
54 |
6 |
166 |
76 |
118 |
v |
67 |
37 |
55 |
7 |
167 |
77 |
119 |
w |
70 |
38 |
56 |
8 |
170 |
78 |
120 |
x |
71 |
39 |
57 |
9 |
171 |
79 |
121 |
y |
72 |
3a |
58 |
: |
172 |
7a |
122 |
z |
73 |
3b |
59 |
; |
173 |
7b |
123 |
{ |
74 |
3c |
60 |
< |
174 |
7c |
124 |
| |
75 |
3d |
61 |
= |
175 |
7d |
125 |
} |
76 |
3e |
62 |
> |
176 |
7e |
126 |
~ |
77 |
3f |
63 |
? |
177 |
7f |
127 |
del |
$j.fn.numeral = function() { $j(this).css("ime-mode", "disabled"); this.bind("keypress",function() { if (event.keyCode == 46) { if (this.value.indexOf(".") != -1) { return false; } } else { return event.keyCode >= 46 && event.keyCode <= 57; } }); this.bind("blur", function() { if (this.value.lastIndexOf(".") == (this.value.length - 1)) { this.value = this.value.substr(0, this.value.length - 1); } else if (isNaN(this.value)) { this.value = ""; } }); this.bind("paste", function() { var s = clipboardData.getData('text'); if (!/\D/.test(s)); value = s.replace(/^0*/, ''); return false; }); this.bind("dragenter", function() { return false; }); this.bind("keyup", function() { if (/(^0+)/.test(this.value)) { this.value = this.value.replace(/^0*/, ''); } }); };
第一种:传入参数仅有数组 <select id="GetEmailList_Test" resultClass="EmailInfo_"> select * from MailInfo with (nolock) where ID in <iterate open="(" close=")" conjunction="," > #[]# </iterate> </select> 调用 string[] strValue = new string[] { "1", "2", "3" }; Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test", strValue );
第二种:传入参数有数组,且有其他数据 <select id="GetEmailList_Test3" parameterClass="TestIn" resultClass="EmailInfo_"> select top(#Count#)* from MailInfo with (nolock) where ID in <iterate open="(" close=")" conjunction="," property="ArrValue" > #ArrValue[]# </iterate> </select> 调用 TestIn ti = new TestIn(); ti.Count = 1; ti.ArrValue = strValue; return Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test3", ti); 实体类: public class TestIn { private int count; public int Count { get { return count; } set { count = value; } } private string[] arrValue; public string[] ArrValue { get { return arrValue; } set { arrValue = value; } } }
第三种:in后面的数据确定,使用string传入 <select id="GetEmailList_Test2" parameterClass="TestIn" resultClass="EmailInfo_"> select * from MailInfo with (nolock) where ID in ($StrValue$) </select> 调用 Reader.QueryForList<EmailInfoModel>("WebApp_Ibatisnet.dao.GetEmailList_Test2", "1,2,3");
其他信息: Iterate的属性: prepend -可被覆盖的SQL语句组成部分,添加在语句的前面(可选) property -类型为java.util.List的用于遍历的元素(必选) open -整个遍历内容体开始的字符串,用于定义括号(可选) close -整个遍历内容体结束的字符串,用于定义括号(可选) conjunction -每次遍历内容之间的字符串,用于定义AND或OR(可选) <iterate>遍历类型为java.util.List的元素。
//获取客户端ip地址
public String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
//获取服务器ip地址
InetAddress inet = InetAddress.getLocalHost();
String hostAddress=inet.getHostAddress();
集合的一个很重要的操作---遍历,学习了三种遍历方法,三种方法各有优缺点~~ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package cn.tsp2c.liubao; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.TreeMap; /** * * @author Administrator */ public class TestMap { public static void main(String[] args) { Map<String, Student> map = new HashMap<String, Student>(); Student s1 = new Student("宋江", "1001", 38); Student s2 = new Student("卢俊义", "1002", 35); Student s3 = new Student("吴用", "1003", 34); map.put("1001", s1); map.put("1002", s2); map.put("1003", s3); Map<String, Student> subMap = new HashMap<String, Student>(); subMap.put("1008", new Student("tom", "1008", 12)); subMap.put("1009", new Student("jerry", "1009", 10)); map.putAll(subMap); work(map); workByKeySet(map); workByEntry(map); } //最常规的一种遍历方法,最常规就是最常用的,虽然不复杂,但很重要,这是我们最熟悉的,就不多说了!! public static void work(Map<String, Student> map) { Collection<Student> c = map.values(); Iterator it = c.iterator(); for (; it.hasNext();) { System.out.println(it.next()); } } //利用keyset进行遍历,它的优点在于可以根据你所想要的key值得到你想要的 values,更具灵活性!! public static void workByKeySet(Map<String, Student> map) { Set<String> key = map.keySet(); for (Iterator it = key.iterator(); it.hasNext();) { String s = (String) it.next(); System.out.println(map.get(s)); } } //比较复杂的一种遍历在这里,呵呵~~他很暴力哦,它的灵活性太强了,想得到什么就能得到什么~~ public static void workByEntry(Map<String, Student> map) { Set<Map.Entry<String, Student>> set = map.entrySet(); for (Iterator<Map.Entry<String, Student>> it = set.iterator(); it.hasNext();) { Map.Entry<String, Student> entry = (Map.Entry<String, Student>) it.next(); System.out.println(entry.getKey() + "--->" + entry.getValue()); } } } class Student { private String name; private String id; private int age; public Student(String name, String id, int age) { this.name = name; this.id = id; this.age = age; } @Override public String toString() { return "Student{" + "name=" + name + "id=" + id + "age=" + age + '}'; } }
|