Wicket學習筆記(1):入門篇

最近需要學習wicket框架,而這個框架的學習資料好像也不是很多,到處找相關的資料來進行學習。另外這個框架因爲出現的也比較早,現在使用的人並不是很多,自己學習一下,也就做一些記載。

使用工具
開發工具:eclipse

我以個人通俗的理解來看這個框架,有人說這個類似ASP.NET,實際上和安卓的開發同樣有點類似,不去說的有多高大上,一切白話文形式的顯示,希望對像我一樣的小白能有一點點小幫助即可。

1-首先創建一個dynamic web project工程,我的目錄如下,都是wicket常用的控件,簡單的學習了一下。
在這裏插入圖片描述

2-這裏先看demo裏邊的三個文件
HelloWordApplication.java
HelloWordPage.java
HelloWordPage.html

這裏邊HelloWordApplication 相當於一個入口,這個會在web.xml裏邊進行配置,然後調用Hello WordPage.java。這裏邊HelloWordPage.java
HelloWordPage.html,兩個的名字是一樣的,也必須是一樣的。下面看看每個文件內容

HelloWorldApplication.java

package hyron.wicket.demo;

import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;

import hyron.wicket.bookmarkablepagelink.BookMarkablePage;
import hyron.wicket.border.BorderPage;
import hyron.wicket.box.CheckBoxPage;
import hyron.wicket.button.ButtonPage;
import hyron.wicket.checkgroup.CheckGroupPage;
import hyron.wicket.container.WebMarkupContainerPage;
import hyron.wicket.downloadlink.DownloadLinkPage;
import hyron.wicket.dropdownchoice.DropdownChoicePage;
import hyron.wicket.externallink.ExternalLinkPage;
import hyron.wicket.image.ImagePage;
import hyron.wicket.include.IncludePage;
import hyron.wicket.link.LinkPage;
import hyron.wicket.listview.ListViewPage;
import hyron.wicket.pagelink.PageLInkPage;
import hyron.wicket.pagetablelistview.PagetableListPage;
import hyron.wicket.popupsetting.PopupLinkPage;
import hyron.wicket.textfield.TextFieldPage;
import hyron.wicket.userresist.UserResistPage;
//import wicket.protocol.http.WebApplication;

public class HelloWorldApplication extends WebApplication{
	@Override
	public Class<? extends Page> getHomePage() 
		// http://localhost:8080/Wicket/helloWorld
		{ 
			return HelloWorldPage.class;
			//return WebMarkupContainerPage.class;
			//return BorderPage.class;
			//return IncludePage.class;
			//return ExternalLinkPage.class;
			//return PageLInkPage.class;
			//return BookMarkablePage.class;
			//return DownloadLinkPage.class;
			//return PopupLinkPage.class;
			//return ButtonPage.class;
			//return TextFieldPage.class;
			//return CheckBoxPage.class;
			//return CheckGroupPage.class;
		    //return  DropdownChoicePage.class;
			//return ImagePage.class;
			//return ListViewPage.class;
			//return PagetableListPage.class;
			//return UserResistPage.class;
		}
}


HelloWorldPage.java

package hyron.wicket.demo;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;

public class HelloWorldPage extends WebPage{
	
	private static final long serialVerssionUID = 1L;
	
	public HelloWorldPage() {
		
		super();
		
		add(new Label("message", "HelloWorld!"));
		
		add(new Label("birthday","20200202"));
		
		Label label=new Label("escape","<span>message</span>");
		
		add(label);
	}
}

HelloWorldPage.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

   1/span控件的測試
   <br>
   <span wicket:id="message"> 我要在這裏輸出helloword </span>
   <br>
   2/label控件的測試
   <br>
   這裏所有的申明的wicket id都必須要在Java類中對應
   <br>
   <label wicket:id="birthday">這裏輸出用戶生日信息</label>
   <br>
   <label wicket:id="escape">測試</label>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>Wicket</display-name>
  
 <- 這裏使用的是filter也可以使用servlet但是filter可以實現更加強大的功能 ->
<filter>
		<filter-name>HelloWorldApplication</filter-name>
		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
		<init-param>
			<param-name>applicationClassName</param-name>
			<param-value>hyron.wicket.demo.HelloWorldApplication</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>HelloWorldApplication</filter-name>
		<url-pattern>/helloWorld/*</url-pattern>
	</filter-mapping>

</web-app>

http://localhost:8080/Wicket/helloWorld/
運行效果:
在這裏插入圖片描述

說明:
wicket:id="birthday"這個是wicket框架的最重要的東西了,所有的定義的ID,都需要在於該html同名的Java類裏邊進行指定使用,如:add(new Label(“birthday”,“20200202”));

可以寫成
Label label = new Label(“birthday”,“20200202”));
add(label);這個樣子的形式

獲取ID爲birthday的wicket控件,並且新建對象Label 用以獲取對應,並且給予一個值,然後使用add將控件添加到頁面容器內,才能最終形成一個頁面。

我將整個工程文件放在下面,這些只是部分wicket控件的簡單使用,需要使用的可以下載使用。

百度網盤鏈接: https://pan.baidu.com/s/1ZsP8mqtP7gPatp9bZVKv8A
提取碼: 2tnn

CSDN上文件路徑:
https://download.csdn.net/download/zxx123123121/12159351

發佈了10 篇原創文章 · 獲贊 7 · 訪問量 337
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章