<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java學(xué)習(xí)

    java學(xué)習(xí)

     

    java的值傳遞和引用傳遞

    public class Man {
    private String id;
      public String getId() {
    return id;
    }
    public void setId(String id) {
    this.id = id;
    }
    public void man() {
    System.out.println("man");
    }
    }
    public class TestMan {
    //值傳遞傳遞的是值的副本
    public static int getInt(int i){
    i=4;
    return i;
    }
    //引用傳遞,傳遞的是對(duì)象的引用,指向的還是原來(lái)的對(duì)象
    public static Man getMan(Man man){
    man.setId("111");
    return man;
    }
    public static String getS(String s){
    return s="111";
    }
    public static void main(String[] args) {
    int i=1;
    TestMan.getInt(i);
    System.out.println(i);
    Man man = new Man();
    man.setId("222");
    TestMan.getMan(man);
    System.out.println(man.getId());
    String s="222";
    TestMan.getS(s);
    System.out.println(s);
    }
    }

    posted @ 2017-12-08 17:19 楊軍威 閱讀(133) | 評(píng)論 (0)編輯 收藏

    子線程執(zhí)行10次,主線程執(zhí)行100次,然后再子線程執(zhí)行10次,主線程執(zhí)行100次,循環(huán)50次

    package com.yjw.thread;
    public class Test2 {
    static class Businis {
    boolean f = false;// true sub執(zhí)行,false main執(zhí)行
    public synchronized void sub(int i) {
    if (!f) {
    try {
    this.wait();
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    for (int j = 1; j <= 10; j++) {
    System.out.println("sub=" + j + ",loop=" + i);
    }
    f = false;
    this.notify();
    }
    public synchronized void main(int i) {
    if (f) {
    try {
    this.wait();
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    for (int j = 1; j <= 100; j++) {
    System.out.println("main=" + j + ",loop=" + i);
    }
    f = true;
    this.notify();
    }
    }
    public static void main(String[] args) {
    final Businis businis = new Businis();
    for (int i = 1; i <= 50; i++) {
    businis.main(i);
                            businis.sub(i);
    }
    }
    }

    posted @ 2017-12-08 16:24 楊軍威 閱讀(249) | 評(píng)論 (0)編輯 收藏

    線程重寫了run方法并傳入一個(gè)新的線程時(shí)執(zhí)行run的改變

    @org.junit.Test
    public void test2(){
    new Thread( new Runnable() {
    public void run() {
    System.out.println(2);
    }
    }){
    public void run() {
    System.out.println(1);
    };
    }.start();
    }
    線程重寫了run方法,又傳入了新的線程,此線程只執(zhí)行重寫了run方法的方法,因?yàn)楦鶕?jù)面向?qū)ο蟮脑瓌t,子類重寫了父類的方法,只執(zhí)行子類的方法。

    posted @ 2017-12-08 09:39 楊軍威 閱讀(241) | 評(píng)論 (0)編輯 收藏

    瀏覽器觸發(fā)ajax請(qǐng)求的次數(shù)限制

    一個(gè)頁(yè)面同時(shí)觸發(fā)ajax請(qǐng)求的次數(shù)不能過(guò)多,同時(shí)觸發(fā)的次數(shù)不要超過(guò)6個(gè),不然過(guò)多的ajax會(huì)被瀏覽器阻塞,不能實(shí)現(xiàn)異步請(qǐng)求。

    posted @ 2017-12-06 14:56 楊軍威 閱讀(362) | 評(píng)論 (0)編輯 收藏

    負(fù)載均衡出現(xiàn)404

    負(fù)載均衡時(shí),如果客戶端訪問(wèn)出現(xiàn)404的情況時(shí),有可能是負(fù)載均衡映射到了空的服務(wù)造成的,需要檢查負(fù)載均衡對(duì)應(yīng)的后臺(tái)主機(jī)是否存在。

    posted @ 2017-12-06 14:54 楊軍威 閱讀(178) | 評(píng)論 (0)編輯 收藏

    oracle建立普通用戶

    1、
    1. create user aaaaidentified by 123aaa;  
      2、
      grant connect, resource to aaaa;
      3、
      grant create session to aaaa;

    posted @ 2017-11-27 14:23 楊軍威 閱讀(159) | 評(píng)論 (0)編輯 收藏

    createQuery is not valid without active transaction

    在DAO文件中,通過(guò)sessionFactory.getCurrentSession()來(lái)獲取會(huì)話,報(bào)異常:org.hibernate.HibernateException: createQuery is not valid without active transaction。經(jīng)過(guò)實(shí)驗(yàn),發(fā)現(xiàn)將Hibernate的配置文件中的<property name="current_session_context_class">thread</property>屬性去掉就好了。原來(lái)"current_session_context_class"屬性的意思是,設(shè)置當(dāng)前會(huì)話的上下文環(huán)境,如果設(shè)置為thread,那么同一線程則共享同一session會(huì)話。因此通過(guò)getCurrentSession()得到的session,是同一線程上的session,而不是Spring管理的那個(gè)能夠自動(dòng)開啟事務(wù)的session。去除掉該屬性就好了

    posted @ 2017-11-24 15:14 楊軍威 閱讀(184) | 評(píng)論 (0)編輯 收藏

    Java泛型

    2. 泛型類:泛型只在編譯時(shí)期有效,編譯后的字節(jié)碼文件中不存在有泛型信息!

    1. 泛型方法:

    public class GenericDemo {



    // 定義泛型方法
    public <K,T> T save(T t,K k) {
    return null;
    }
    // 測(cè)試方法
    @Test
    public void testMethod() throws Exception {
    // 使用泛型方法:  在使用泛型方法的時(shí)候,確定泛型類型
    save(1.0f, 1);
    }
    }

    2. 泛型類:

    public class GenericDemo<T> {



    // 定義泛型方法
    public <K> T save(T t,K k) {
    return null;
    }
    public void update(T t) {

    }

       

        // 測(cè)試方法

        @Test

        public void testMethod() throws Exception {

           

            // 泛型類:  在創(chuàng)建愛泛型類對(duì)象的時(shí)候,確定類型

            GenericDemo<String> demo = new GenericDemo<String>();

            demo.save("test", 1);

        }

    }
    3. 泛型接口:
    /**
     * 泛型接口
     * @author Jie.Yuan
     *
     * @param <T>
     */
    public interface IBaseDao<T> {
    void save(T t );
    void update(T t );
    }
    泛型接口類型確定: 實(shí)現(xiàn)泛型接口的類也是抽象,那么類型在具體的實(shí)現(xiàn)中確定或創(chuàng)建泛型類的時(shí)候確定。
    泛型的反射

    /**

     * 所有dao的公用的方法,都在這里實(shí)現(xiàn)

     * @author Jie.Yuan

     *

     */

    public class BaseDao<T>{

       

        // 保存當(dāng)前運(yùn)行類的參數(shù)化類型中的實(shí)際的類型

    private Class clazz;


    // 表名
    private String tableName;
    // 構(gòu)造函數(shù): 1. 獲取當(dāng)前運(yùn)行類的參數(shù)化類型; 2. 獲取參數(shù)化類型中實(shí)際類型的定義(class)
    public BaseDao(){
    //  this  表示當(dāng)前運(yùn)行類  (AccountDao/AdminDao)
    //  this.getClass()  當(dāng)前運(yùn)行類的字節(jié)碼(AccountDao.class/AdminDao.class)
    //  this.getClass().getGenericSuperclass();  當(dāng)前運(yùn)行類的父類,即為BaseDao<Account>
    //                                           其實(shí)就是“參數(shù)化類型”, ParameterizedType   
    Type type = this.getClass().getGenericSuperclass();
    // 強(qiáng)制轉(zhuǎn)換為“參數(shù)化類型”  【BaseDao<Account>】
    ParameterizedType pt = (ParameterizedType) type;
    // 獲取參數(shù)化類型中,實(shí)際類型的定義  【new Type[]{Account.class}】
    Type types[] =  pt.getActualTypeArguments();
    // 獲取數(shù)據(jù)的第一個(gè)元素:Accout.class
    clazz = (Class) types[0];
    // 表名  (與類名一樣,只要獲取類名就可以)
    tableName = clazz.getSimpleName();
    }

    /**
    * 主鍵查詢
    * @param id 主鍵值
    * @return      返回封裝后的對(duì)象
    */
    public T findById(int id){
    /*
    * 1. 知道封裝的對(duì)象的類型
    * 2. 表名【表名與對(duì)象名稱一樣, 且主鍵都為id】
    * 即,
    *  ---》得到當(dāng)前運(yùn)行類繼承的父類  BaseDao<Account>
    *   ----》 得到Account.class
    */
    String sql = "select * from " + tableName + " where id=? ";
    try {
    return JdbcUtils.getQuerrRunner().query(sql, new BeanHandler<T>(clazz), id);
    } catch (SQLException e) {
    throw new RuntimeException(e);
    }
    }
    /**
    * 查詢?nèi)?/span>
    * @return
    */
    public List<T> getAll(){
    String sql = "select * from " + tableName ;
    try {
    return JdbcUtils.getQuerrRunner().query(sql, new BeanListHandler<T>(clazz));
    } catch (SQLException e) {
    throw new RuntimeException(e);
    }
    }
    }

    posted @ 2017-11-14 17:34 楊軍威 閱讀(119) | 評(píng)論 (0)編輯 收藏

    log4j整合springmvc在web.xml中的配置

    <!-- Log4j配置 -->
    <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>classpath:config/log4j.properties</param-value>
      </context-param>
      <context-param>  
            <param-name>log4jRefreshInterval</param-name>  
            <param-value>60000</param-value>  
        </context-param>  
        <listener>  
            <listener-class>  
                org.springframework.web.util.Log4jConfigListener  
            </listener-class>  
        </listener>  
    <!-- end -->  
      
        <listener>  
            <listener-class>  
                org.springframework.web.context.ContextLoaderListener  
            </listener-class>  
        </listener> 
    配置的順序不能亂!

    posted @ 2017-11-14 17:17 楊軍威 閱讀(1556) | 評(píng)論 (0)編輯 收藏

    java自定義annotation模仿hibernate注解實(shí)體和表對(duì)象

    package com.annotation;
    import static java.lang.annotation.ElementType.FIELD;
    import static java.lang.annotation.ElementType.METHOD;
    import java.lang.annotation.Documented;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    @Documented
    @Retention(RetentionPolicy.RUNTIME)
    @Target(value={ FIELD, METHOD})
    public @interface Column {
    String ColumnName();
    }
    package com.annotation;
    import static java.lang.annotation.ElementType.FIELD;
    import static java.lang.annotation.ElementType.METHOD;
    import java.lang.annotation.Documented;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    @Documented
    @Retention(RetentionPolicy.RUNTIME)
    @Target(value={ FIELD, METHOD})
    public @interface Id {
    }
    package com.annotation;
    import static java.lang.annotation.ElementType.TYPE;
    import java.lang.annotation.Documented;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    @Documented
    @Retention(RetentionPolicy.RUNTIME)
    @Target(value={  TYPE})
    public @interface Table {
    String tableName();
    }
    package com;
    import java.lang.reflect.Field;
    import java.lang.reflect.ParameterizedType;
    import java.lang.reflect.Type;
    import com.annotation.Column;
    import com.annotation.Id;
    import com.annotation.Table;
    public class BaseDao<T,Pk> {
    private Class<T> persistentClass;
    @SuppressWarnings("unused")
    private Class<Pk> persistentPK;
    private String tableName;//表名稱
    private String id;//主鍵
    public BaseDao() {
    ParameterizedType ptype=(ParameterizedType) this.getClass().getGenericSuperclass();
    Type[] types = ptype.getActualTypeArguments();
    for (Type type : types) {
    System.out.println(type.toString());
    }
    this.persistentPK = (Class<Pk>) types[1];
    this.persistentClass = (Class<T>) types[0];
    Table table = this.persistentClass.getAnnotation(Table.class);
    tableName=table.tableName();
    Field[] fields = this.persistentClass.getDeclaredFields();
    for (Field field : fields) {
    field.setAccessible(true);
    Id annotationId = field.getAnnotation(Id.class);
    if(annotationId != null){
    Column annotationCo = field.getAnnotation(Column.class);
    id=annotationCo.ColumnName();
    break;
    }
    }
    }
    public T getT(T t){
    System.out.println(tableName);
    System.out.println(id);
    return t;
    }
    }
    package com;
    import com.annotation.Column;
    import com.annotation.Id;
    import com.annotation.Table;
    @Table(tableName = "t_user")
    public class User {
    @Id
    @Column(ColumnName = "uid")
    private String id="1";
    public String getId()  {
    return id;
    }
    public void setId(String id) {
    this.id = id;
    }
    public User(String id) {
    super();
    this.id = id;
    System.out.println("有參數(shù)");
    }
    public User() {
    System.out.println("沒有參數(shù)");
    }
    }
    package com;
    public class UserDao extends BaseDao<User, String>{
    }

    posted @ 2017-11-14 17:15 楊軍威 閱讀(241) | 評(píng)論 (0)編輯 收藏

    僅列出標(biāo)題
    共43頁(yè): First 上一頁(yè) 4 5 6 7 8 9 10 11 12 下一頁(yè) Last 

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿

    隨筆檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲国产精品一区二区成人片国内 | 亚洲国产精品无码专区影院| 亚洲av无码国产精品色在线看不卡| 成年人免费视频观看| 毛片免费在线视频| 精品免费国产一区二区| 免费观看a级毛片| 免费一级毛片在级播放| 亚洲国产一成久久精品国产成人综合| 成人亚洲网站www在线观看| 亚洲午夜无码AV毛片久久| 在线精品亚洲一区二区小说| 久久精品国产亚洲网站| 亚洲日本在线观看| 亚洲不卡视频在线观看| 久久综合久久综合亚洲| 九九精品国产亚洲AV日韩| 免费一级毛片在线播放放视频| j8又粗又长又硬又爽免费视频 | 亚洲一区中文字幕| 亚洲欧美成aⅴ人在线观看| 黄色网址免费在线| a级片在线免费看| h片在线免费观看| 国产美女做a免费视频软件| 亚洲天堂中文字幕在线| 亚洲av网址在线观看| 久久精品国产亚洲av麻豆图片| 亚洲精品国产首次亮相| 一级黄色免费大片| 99re免费视频| 免费无码不卡视频在线观看| 亚洲视频在线精品| 久久久久亚洲Av无码专| 亚洲gay片在线gv网站| 成人无码视频97免费| 2021久久精品免费观看| 国产一级淫片a视频免费观看| 亚洲综合国产一区二区三区| 91亚洲国产成人久久精品网址| 日韩国产欧美亚洲v片|