a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 125|回复: 0

[基础知识] JAVA认证考试基础知识笔记21

[复制链接]
发表于 2012-8-4 12:37:27 | 显示全部楼层 |阅读模式
15./**, `! q. M0 q% I, y
      Z; {* P; r$ b, @9 C* U& h
    16.* 获取邮箱
8 `2 r# y  D# b3 `: E, Z   
' W' S. w( P7 U9 H9 O" U" U# z5 B7 h    17.*9 X/ h  {8 `% M" v9 x) A
   
5 t( x% Y0 I3 @0 `! G    18.* @param type 邮箱类型, N" \0 G) \5 S
    8 F; `) X3 Z4 l) I* B
    19.* @return 符合类型的邮箱( c; e6 w: S8 Z4 ^# P# @1 _
    1 S& `# I; o, g, ]! Z
    20.*/0 p$ H  k( ^% H% D
   
8 Z8 n. E& S+ _8 q4 I8 j3 y    21.public static SimpleMailSender getSender(MailSenderType type) {  h* k9 ?' W* o" [. v4 l, N
    % y8 B0 m% w4 P( B$ Q9 m
    22.if (type == MailSenderType.SERVICE) {0 G) x, o: R- M( t" f
    + Z/ M. c4 k2 ^$ v; \$ {' U
    23.if (serviceSms == null) {+ _7 @2 c0 ?% M1 `
   
" s* l  }  {6 o  A    24.serviceSms = new SimpleMailSender("invisible@126.com",
( N8 }8 o0 k; O; E! K! n( x    % d0 S( ^% |: f, u5 d& z1 l9 b3 I
    25."hidden");
( K+ z# Y' u" {; |  j) X    # T, n# s% h0 g% K
    26.}6 ^) }  Z* W7 I$ c8 I  ^' L
   
$ W8 f4 b7 n% {4 x    27.return serviceSms;
* {4 y! ]% U/ X    2 K7 M) W  y8 }+ D2 J
    28.}
+ h% J2 R; L* y* h4 d   
" O" o; q; o3 l% r; i' b    29.return null;
9 U2 ]' C% e7 g' O, E- h   
# M; Z1 B1 Z9 H) f5 i$ {* y    30.}. X" f7 n2 `" E( `1 u* o
    ' @8 x; O7 g- S" r" b
    31.}
, ]5 X3 c' R3 S6 \" E7 B    8 |" a1 u" f7 q$ i
    4、发送邮件,还是观察者模式DEMO里面的代码,呼呼。
; c( W- ]* ^2 t6 S    - L: w) H8 k+ f. h( ^
    1.package com.mzule.dp.observer.observer;
' a( d4 s# |% j% R7 Z) f6 S2 H    ; y6 v2 m/ L1 V, G  W# ?# W' [
    2.import java.util.ArrayList;
( D% n; b% x, F1 y2 e    3 m% P+ p3 x' j2 o
    3.import java.util.List;
: V" b3 Z$ V9 p   
  t0 J; ^) O# h5 N# L. n    4.import java.util.Observable;' [' m4 O2 l- }+ X9 s" ~, Y& t6 R/ g! v( ?
   
* O$ a" M& B) i# F+ k) t- o# c    5.import java.util.Observer;$ \0 Q8 a1 v, l4 t8 m$ f
   
# G+ W9 S5 {( s4 }    6.import javax.mail.MessagingException;
% W' g# w( g$ L   
& k; A$ X6 A9 V5 Q    7.import javax.mail.internet.AddressException;- h! Z; @! I* Z7 ?  z" B, w" K
    9 z% _& M: l  Y. w' T# n- ]- o
    8.import com.mzule.dp.observer.constant.MailSenderType;7 L/ n. u  J8 \, S
    4 V+ S) ~( [* F. I. C
    9.import com.mzule.dp.observer.factory.MailSenderFactory;% Z- s6 \0 A$ P% A
   
6 H  q8 J3 @* X: E6 I    10.import com.mzule.dp.observer.po.Product;8 P8 U* w% R' r2 Z: j( u  J
   
- A  d# d5 w9 |! V$ i    11.import com.mzule.simplemail.SimpleMailSender;" f/ {. y$ ?$ l
    0 M7 |8 A% D$ C; A" m, Z7 C
    12.public class ProductPriceObserver implements Observer {4 ^, \* O3 `& N; f$ Q
    5 x) X* k& b5 Y! I3 F
    13.@Override- R- j. D( c- c7 h$ b- M! n+ }
    & s7 }$ g0 K7 S; @$ G, v
    14.public void update(Observable obj, Object arg) {9 E9 `% C$ e3 f
   
. ~+ \6 K/ H# X0 k1 u    15.Product product = null;
, X7 z# \; r$ B    % h  P/ b3 `6 N" V
    16.if (obj instanceof Product) {
. I7 J% q. n( J+ B   
1 c1 U  O# }" B. d8 N3 @) e1 l. B( l    17.product = (Product) obj;7 {* e% m3 ]7 x- U! m4 H
    3 z9 E! R8 }* E4 a6 G2 @
    18.}3 ~1 H0 X% m  J" w5 E4 n2 b5 y+ q5 B
    7 p$ D5 m- E% T" I6 g3 d2 E
    19.if (arg instanceof Float) {
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-8 03:47 , Processed in 0.276314 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表