如何用wordpress做視頻網(wǎng)站品牌seo培訓咨詢
單元測試
-
? ?操作步驟:
? ? ? ?a.導包import org.junit;
? ? ? ?b.三個注解 ?@Test @Before @After
? ? ? ?c.點擊@Test 運行就可以了
? ?用在不需要控制臺輸入的情境下:javaweb,框架項目,微服務項目 供開發(fā)人員自己做測試。
package com.page.test;import com.page.entry.DVD;
import com.page.service.DvdService;
import com.page.service.impl.DvdServiceImpl;
import com.page.controller.DvdController;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings("all")
public class DVDTest {@Testpublic void test1(){DvdController controller=new DvdController();controller.menu();}DvdService service=null;@Beforepublic void testB(){service=new DvdServiceImpl();}@Testpublic void test2(){int i= service.getDataCount(new DVD());System.out.println("一共有"+i+"條數(shù)據(jù)");}@Testpublic void test3(){int i= service.getDataCount(new DVD());System.out.println("一共有"+i+"條數(shù)據(jù)");}@Afterpublic void testA(){System.out.println("測試結(jié)束!");}}
注解
一,注解的分類
1,jdk中的常用注解:
? ? ? ? ? ? ? ? ? @SuppressWarnings("all") ? 抑制警告
? ? ? ? ? ? ? ? ? @Deprecated ?標記過時
? ? ? ? ? ? ? ? ? @Override ? ?表示重寫方法
2,單元測試里的注解:
? ? ? ? ? ? ? ? @Test
? ? ? ? ? ? ? ? @Before
? ? ? ? ? ? ? ? @After
3,javadao注釋里的注解;
4,框架、javaweb里的注解。
5,元注解:修飾注解的注解就是元注解。
其中注意:
? @param @return和@exception這三個標記都是只用于方法的。
? @param的格式要求: @param 形參名 形參類型 形參說明
? @return的格式要求: @return 返回值類型返回值說明,如果方法的返回值類型是void就不能寫
? @exception的格式要求: @exception 異常類型異常說明
? @param和@exception可以并列多個
枚舉
一,創(chuàng)建
package page.enumdemo;public enum DVDType {恐怖,搞笑,穿越,古裝
}
二,使用
package page.test;import page.entry.DVD;
import page.enumdemo.DVDType;import java.util.Scanner;public class EnumTest {public static void main(String[] args) {//賦值,取值,轉(zhuǎn)換,枚舉DVD dvd=new DVD();//1,直接賦值dvd.setDvdType(DVDType.古裝);//2,控制臺輸入賦值Scanner input=new Scanner(System.in);String s=input.next();DVDType dvdType=DVDType.valueOf(s);dvd.setDvdType(dvdType);System.out.println(dvd.getDvdType());}
}
三,Enum類常用方法
package com.msb.enum03;public class TestSeason {//這是一個main方法,是程序的入口:public static void main(String[] args) {//用enum關(guān)鍵字創(chuàng)建的Season枚舉類上面的父類是:java.lang.Enum,常用方法子類Season可以直接拿過來使用://toString();--->獲取對象的名字Season autumn = Season.AUTUMN;System.out.println(autumn/*.toString()*/);//AUTUMNSystem.out.println("--------------------");//values:返回枚舉類對象的數(shù)組Season[] values = Season.values();for(Season s:values){System.out.println(s/*.toString()*/);}System.out.println("--------------------");//valueOf:通過對象名字獲取這個枚舉對象//注意:對象的名字必須傳正確,否則拋出異常Season autumn1 = Season.valueOf("AUTUMN");System.out.println(autumn1);}
}
網(wǎng)絡(luò)編程
- 客戶端
package page.socketdemo;/*** 客戶端:發(fā)送信息給服務器 問 “中午吃啥了?”*/import java.io.*; import java.net.Socket; import java.util.Scanner;public class Asocket {public static void main(String[] args) throws IOException {while (true) {Scanner input = new Scanner(System.in);//設(shè)置一個socket對象,鎖定服務器的IP和端口Socket socket = new Socket("127.0.0.1", 8888);//2.獲得輸出節(jié)點流OutputStream outputStream = socket.getOutputStream();DataOutputStream dos = new DataOutputStream(outputStream);//3.寫入數(shù)據(jù)/* dos.writeUTF("中午吃啥了?");*/System.out.println("請輸入你要發(fā)送的信息:");dos.writeUTF(input.next());//4.接受服務器端回復的消息InputStream inputStream = socket.getInputStream();DataInputStream dis = new DataInputStream(inputStream);System.out.println("服務器回復:" + dis.readUTF());//4.關(guān)閉流資源dis.close();dos.close();}} }
- 服務器端
package page.socketdemo;import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.Scanner;/*** 服務器端*/ public class SSocket {public static void main(String[] args) throws IOException {Scanner input = new Scanner(System.in);ServerSocket ss = new ServerSocket(8888);while (true) {System.out.println("服務器已啟動!");//通過系統(tǒng)類,一直關(guān)注一個端口號,判斷是否有客戶端發(fā)送請求//2.接收發(fā)送過來的請求:Socket socket = ss.accept();//accept();---可以阻塞線程//3.獲得輸入流InputStream inputStream = socket.getInputStream();DataInputStream dis = new DataInputStream(inputStream);//4.讀出String s = dis.readUTF();System.out.println("客戶端發(fā)來了的消息:" + s);//5.回復OutputStream outputStream = socket.getOutputStream();DataOutputStream dos = new DataOutputStream(outputStream);System.out.println("請回復客戶:");dos.writeUTF(input.next());//5.關(guān)閉資源dos.close();dis.close();}} }
cmd