/**
* 返回 短信驗證碼
* example : 766221
* @return
*/
private String randomMath(){
Random rad=new Random();
String result = rad.nextInt(1000000) +"";
if(result.length()!=6){
return randomMath();
}
return result;
}
任務執行的時間統計
StopWatch stopWatch = new StopWatch();
stopWatch.start();
dosomething();
stopWatch.stop();
log.info("消耗時間統計:{} ms", stopWatch.getTotalTimeMillis());
spring.cloud.zookeeper.connect-string : *.*.*.*:2181
feign.client.config.default.connectTimeout:30000
............................readTimeout:30000
spring.servlet.multipart.max-file-size: 2MB
swagger.base.package: com.*.*
ORACLE 分頁:node
select r,ename,sal fromweb
(select rownum r, ename,sal from (select * from emp order by sal desc ))spring
where r>5 and r<=10;sql
select rownum r, t.* from (select * from emp order by sal desc)texpress
where rownum<=10;apache
minusapi
select rownum r, t.* from (select * from emp order by sal desc)t緩存
where rownum<=5;session
sql1992:併發
select ename,dname from emp,dept
where emp.deptno=dept.deptno and emp.deptno=30;
sql 1999:
select ename,dname from emp join dept on (emp.emptno=dept.deptno)
where emp.deptno=30;
內聯結: outer 能夠省略
select dname,ename from emp join dept on emp.deptno=dept.deptno;
左外聯結:
select dname,ename from emp left join dept on emp.deptno=dept.deptno;
右外聯結:
select dname,enmae from emp right join dept on emp.deptno=dept.deptno;
全外聯結:
select dname,enmae from emp full join dept on emp.deptno=dept.deptno;
集合操做:
union 並集,不含重複值
unionAll
minus 前一個結果集
減去後一個結果集的差集
從一個表複製到另外一個表。
create table empCopy as select * from emp;
事務:
始於一個DML語句,insert update delete 語句,結束於如下幾種狀況:
1.commit or rollback
2.執行DDL語句
3.正常斷開鏈接時,自動commit
4.異常斷開鏈接時,自動rollback
求部門哪些人的薪水最高?
select ename,max_sal from emp e
join(select max(sal) max_sal,deptno from emp group by deptno) t
on (e.sal=t.max_sal and e.deptno=t.deptno)
求部門平均薪水的等級
select deptno,avg_sal,grade from salgrade s
join(select deptno,avg(sal) avg_sal from emp group by deptno) t
on(t.avg_sal between s.min_sal and s.max_sal)
求哪些是經理人
select enamefrom emp where empno in(select distinct mgr from emp);
select ename from emp where empno in(select distinct mgr from emp);
不用組函數,求薪水的最高值
select sal from emp where sal not in(select distinct e1.sal from emp e1 join emp e2
on( e1.sal<e2.sal)
select sal from emp where sal not in ( select distinct e1.sal from emp e1 join emp e2 on (e1.sal<e2.sal))
索引:
優勢: 增長查詢速度
缺點: 佔用空間,另外引發插入,修改,刪除速度的下降。
使用時機: 惟一性好,查詢次數多的
create index idx.. on empcopy(name);
序列:
create sequense seq_emcopy_id start with 1 increment by 1;
安裝時的system 密碼
使用system 用戶爲scott增長權限:
grant create view,create table to scott;
使用system 用戶爲scott解鎖:
alter user scott account unlock;
private 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;
}
Hibernate3.jar /lib下
Hibernate.cfg.xml
sessionfactory
Hibernate.propertiest
開啓二級緩存:
1.<property name=’hibernate.cache.use_second_level_cache」>true</property>
<property name=’hibernate.cache.provider_class」>org.hibernate.cache.EhCacheProvider</property>
2.類前面
@cache(usage=CacheConcurrencyStrategy.Ready_WRITE)
二級緩存的KEY 類全名#ID
Get load關係。 Load確定得查到,否則就報錯
搜索不到符合條件的記錄,GET 返回一個null,load返回一個objectnotfoundException.
Load 有懶加載,get直接得到數據。
List()iterate() 關係:
Iterate先取ID,再去緩存中查詢有沒有,若是沒有,再發出SQL查詢
List只會往二級緩存存放數據,可是自身查詢不用緩存
查詢緩存 依賴於二級緩存
Key爲查詢語句,只對query.list()起做用。
<property name=hibernate.cache.use_query_cache>true</property>
s.createQuery(from banji).setCacheable(true).list()
LRU LFU FIFO
樂觀鎖:(併發性不高)
實體bean增長一個version字段。
若是當前記錄被修改或刪除,報錯。
悲觀鎖:(併發性高)
事務A:s.get(Account.class,1,LockMode.UPGRADE);
事務B,若是在A 未commit時,讀取會形成死鎖。
Slf (slf-log4j14-.jar轉接)
Slf4j nodep / log4j /jdk logging/apache commons logging
Log4j.properties
Spring mvc:
配置 dispatchServlet. handleMapping HandleAdapter ViewResolver
處理器
http://jinnianshilongnian.iteye.com/blog/1594806
applicationContext -> beanfactory
使用applicationcontext,功能更強大,(生命週期)
<bean scope=singleton/prototype/request/session/globalSession>
事務處理:
配置事務管理器 HibernateTransactionManager 指定 SESSIONFACTORY.
多數據源事務:
1. 使用 atomikos jta xadatasource 方式 解決。
2. 兩段提交協議
3. MQ推送
<bean id=txmanager class = org.springframework.orm.hibernate3.HibernateTransactionManager>
<property name=sessionFactory ref=sessionFactory></property>
</bean>
<tx:annotation-driven transaction-manager=’txmanager/>
<aop:config>
<aop:pointcut expression=execution(public * com.sxt.service.impl.*.*(..) id=bussinessService />
<aop:advisor advice-ref=txAdvice pointcut-ref=businessService />
</aop:config>
<tx:advice id=」txAdvice」 transaction-manager= txmanager >
<tx:attributes>
<tx:method name= get* read-only=true propagation= not_supported />
<tx:method name=’*’ />
</tx:attributes>
性能的問題,要親手測試,根據測試結果 說明問題
HTTP1.0 默認短鏈接
HTTP1.1默認長鏈接
OpenSessionInViewFilter 注意點:
1. 必須配置在struts2 filter前面。
2. Filter 須要 sessionfactory bean,若是須要更名 須要在filter配置信息中加入 param-name: sessionfactorybeanname param-value
3. 若是不配置 transaction,會出異常
InvaliddataaccessapiUsageException write operations are not allowed **** readonly
亂碼 解決:
Filter 過濾
Spring 有characterencodingfilter 解決亂碼問題
1.寫在 struts2 filter前面
分佈式事務:
<bean id="datasource1"
class="com.atomikos.jdbc.SimpleDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="XADBMS_ONE"/>
<property name="xaDataSourceClassName" value="COM.FirstSQL.Dbcp.DbcpXADataSource"/>
<property name="xaDataSourceProperties" value="user=username;portNumber=8000"/
<property name="exclusiveConnectionMode" value="true"/>
</bean>
<bean id="datasource2"
class="com.atomikos.jdbc.SimpleDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="XADBMS_TWO"/>
<property name="xaDataSourceClassName" value="COM.FirstSQL.Dbcp.DbcpXADataSource"/>
<property name="xaDataSourceProperties" value="user=username;portNumber=8000"/
<property name="exclusiveConnectionMode" value="true"/>
</bean>
<bean id="atomikosTransactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
<property name="forceShutdown" value="true"/>
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="200"/>
</bean>
<bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager"/>
<property name="userTransaction" ref="atomikosUserTransaction"/>
</bean>
<bean id="dao" class= "...">
<property name="dataSource" ref="datasource"/>
</bean>
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd" );
Date date = sdf.parse( dates. get(1));
Calendar calendar = Calendar. getInstance();
calendar.setTime( date);
calendar.add(Calendar. DAY_OF_MONTH,1);
-- postgre sql表名 字段名區分大小寫
使用aspect 切面 ,能夠處理全部的web請求,將其輸入輸出 以日誌的形式 記錄下來
ehcache 配置:
1. 增長jar包
2. ehcache配置文件
3. 開啓ehcache註解 @enablecaching