zoukankan      html  css  js  c++  java
  • java 知识点随记

    /**
    * 返回 短信验证码
    * 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:

     ORACLE 分页:

    select r,ename,sal from

    (select rownum r, ename,sal from (select * from emp order by sal desc ))

    where r>5 and r<=10;

    select rownum r, t.* from (select * from emp order by sal desc)t

    where rownum<=10;

    minus

    select rownum r, t.* from (select * from emp order by sal desc)t

    where rownum<=5;

    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;

          }

    Hibernate

    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

    Spring  mvc:

    配置 dispatchServlet.   handleMapping HandleAdapter  ViewResolver

    处理器

    http://jinnianshilongnian.iteye.com/blog/1594806

    1. 开发视图页面
    1. 具体问题:(POST方式的乱码问题)
    2. <filter>  
    3.     <filter-name>CharacterEncodingFilter</filter-name>  
    4.     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
    5.     <init-param>  
    6.         <param-name>encoding</param-name>  
    7.         <param-value>utf-8</param-value>  
    8.     </init-param>  
    9. </filter>  
    10. <filter-mapping>  
    11.     <filter-name>CharacterEncodingFilter</filter-name>  
    12.     <url-pattern>/*</url-pattern>  
    13. </filter-mapping>  

    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

  • 相关阅读:
    vueJs+webpack单页面应用--vue-router配置
    webstorm IDE添加Plugins----添加vue插件
    WebStorm 11、PhpStorm 10免费激活(不需要注册码)
    webpack react基础配置二 热加载
    webpack react基础配置一
    移动端页面去掉click点击 背景色变化
    css美化checkbox radio样式
    ie11媒体查询以及其他hack
    angularJS ng-grid 配置
    网络7. TCP/IP网络之网络接口层
  • 原文地址:https://www.cnblogs.com/xifenglou/p/5409099.html
Copyright © 2011-2022 走看看