读书笔记-2

1、反射
2、oracle年-月-日 时-分-秒
3、oracle创建有参、无参函数
4、oracle行转列
5、Struts2拦截器
6、Filter过滤器(web.xml)

1、反射
(1)检查类的结构
在java.lang.reflect包里有3个类Field,Method,Constructor分别用于描述类的域、方法和构造器。
2、oracle年月日时分秒
select to_char(sysdate,'yyyy-mm-dd HH24-MI-ss')FROM DUAL
3、oracle函数
(1)大于4000的存储方式
create or replace function funny
return  clob 
is
  v_yct clob;
begin
  v_yct:=rpad('a',4002,'b');
  return v_yct;
end funny;
select dbms_lob.getlength(funny) from dual;--获得大于4000的存储长度
(2)创建有参函数
create or replace function lenVarchar(p_char varchar2)
return number
is 
begin
     return length(p_char);
end;
调用(
declare v_char varchar2(32767);
begin

v_char:=rpad('aa',32767,0);
dbms_output.put_line(lenVarchar(v_char));
end;)
4、oracle行转列
create table orders(
       order_date varchar2(20),
       cust_name varchar2(20),
       ar number(10,2)
)
insert into orders(order_date,cust_name,ar)
values('2014-07-01','张先生',1156.7);
insert into orders(order_date,cust_name,ar)
values('2014-07-01','张先生',1000);
insert into orders(order_date,cust_name,ar)
values('2014-07-01','李先生',1000);
insert into orders(order_date,cust_name,ar)
values('2014-07-02','张先生',1156.7);
insert into orders(order_date,cust_name,ar)
values('2014-07-02','李先生',1000);
insert into orders(order_date,cust_name,ar)
values('2014-07-03','张先生',1156.7);
insert into orders(order_date,cust_name,ar)
values('2014-07-03','李先生',1000);
insert into orders(order_date,cust_name,ar)
values('2014-07-04','张先生',1156.7);
insert into orders(order_date,cust_name,ar)
values('2014-07-05','李先生',1000);

select order_date,cust_name,sum(ar) ar From orders
group by order_date,cust_name


select cust_name,order_date,AR,case  when order_date='2014-07-01' then ar end "07-01" ,
       case  when order_date='2014-07-02' then ar end "07-02" ,
       case  when order_date='2014-07-03' then ar end "07-03" ,
       case  when order_date='2014-07-04' then ar end "07-04" ,
       case  when order_date='2014-07-05' then ar end "07-05" 
       from (    
          select order_date,cust_name,sum(ar) ar From orders
          group by order_date,cust_name
      )a
      order by cust_name

      select cust_name,
       MAX(case  when order_date='2014-07-01' then ar end) "07-01" ,
       MAX(case  when order_date='2014-07-02' then ar end) "07-02" ,
       MAX(case  when order_date='2014-07-03' then ar end) "07-03" ,
       MAX(case  when order_date='2014-07-04' then ar end) "07-04" ,
       MAX(case  when order_date='2014-07-05' then ar end) "07-05" 
       from (    
          select order_date,cust_name,sum(ar) ar From orders
          group by order_date,cust_name ) a group by cust_name 
          order by cust_name
5、Struts2拦截器
<package name="bbs_user" namespace="/user" extends="struts-default">
			<!-- 包下面 -->
			<interceptors>
				<interceptor name="encodingInterCeptor" class="com.bbs.interceptor.StrutsInterceptor"/>
				<interceptor-stack name="basicStack">
					<interceptor-ref name="encodingInterCeptor"/>
					<interceptor-ref name="defaultStack"/>
				</interceptor-stack>
			</interceptors>

		<action name="login" class="userAction" method="login">
	       <!--interceptor-ref name="encodingInterCeptor"/-->
	       <interceptor-ref name="basicStack"/>
			<result name="pwdFailure">
				../login.jsp
			</result>
		</action>
</package>
6、Filter过滤器(web.xml)
<!-- 过滤器编码 -->
<filter>
	<filter-name>ActionFilter</filter-name>
	<filter-class>com.bbs.filter.FilterEncoding</filter-class>
	<init-param>
		<param-name>ignore</param-name>
		<param-value>true</param-value>
	</init-param>
	<init-param>
		<param-name>encoding</param-name>
		<param-value>utf-8</param-value>
	</init-param>
</filter>

<filter-mapping>
	<filter-name>ActionFilter</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>

<context-param>
		<param-name>initValue</param-name>
		<param-value>BBS</param-value>
	</context-param>


Java类
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain fc) throws IOException, ServletException {
		//设置编码
		req.setCharacterEncoding(this.encoding);
		//System.out.println("项目编码"+this.encoding);
		fc.doFilter(req, resp);
		//req.getServerName();
		//req.getServerPort();req.getParameterValues(arg0);req.getRequestDispatcher(arg0);
		HttpServletRequest request=(HttpServletRequest)req;
		HttpServletResponse response=(HttpServletResponse)resp;
		String referer = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + request.getRequestURI() + "?" + request.getQueryString();
		//request.getRequestDispatcher("").forward(req, resp);
		//response.sendRedirect("url");
		System.out.println(request.getRequestURL());
		//System.out.println(request.getContextPath());
		System.out.println(referer);
	}

	public void init(FilterConfig fc) throws ServletException {
		this.encoding=fc.getInitParameter("encoding");//获得web.XML的值
	System.out.println(fc.getServletContext().getInitParameter("initValue"));
		System.out.println("过滤器初始化!");

	}

你可能感兴趣的:(读书笔记)