在jsp中,其實(shí)jsp就是servlet,jsp和servlet也都是一個(gè)class:
1 .request.getRealPath(),這個(gè)方法已經(jīng)不推薦使用,在servlet后繼版本中將被取締。
2.getServletContext().getRealPath("/")這個(gè)方法比較好用,可以直接在servlet和jsp中使用。
3.request.getSession().getServletContext().getRealPath()也可以在jsp和servlet使用。
4.this.getClass().getClassLoader().getResource("").getPath(),這個(gè)方法可以在任意jsp,servlet,java文件中使用,因?yàn)椴还苁莏sp,servlet其實(shí)都是java程序,都是一個(gè)class。所以它應(yīng)該是一個(gè)通用的方法。
普遍的,簡單的權(quán)限系統(tǒng)要求:
1.系統(tǒng)所有資源定義 [資源表] ( 還可以分為更小的權(quán)限表,操作表,這里通叫資源表)
2.定義角色 [角色表]
3.給角色指定資源(一個(gè)角色可以管理多個(gè)資源) [角色-資源表]
4.定義用戶組 [用戶表]
5.給用戶組指定角色(一個(gè)用戶組可以擁有多種角色) [用戶組-角色表]
6.給用戶指定角色(一個(gè)用戶可以擁有多種角色,可以直接指定角色,也可以繼承用戶組的角色)[用戶-角色表]
查找權(quán)限時(shí):
根據(jù)用戶ID[用戶-角色表]或用戶組ID[用戶組-角色表],查到所有角色I(xiàn)D,再[角色-資源表]找到所有角色下的所有資源。
此就是用戶擁有的資源。(資源一般為模塊,當(dāng)然也可以分更細(xì)的定義為頁面,操作方法等)
\n"); cgiHtmlEscape(username); fprintf(cgiOut, "\n"); char password[241]; cgiFormString("password", password, 241); fprintf(cgiOut, "password:
\n"); cgiHtmlEscape(password); fprintf(cgiOut, "\n"); char sql[300]={'\0'}; //不能用指針! //插入數(shù)據(jù) sprintf(sql, "INSERT INTO \"user\" VALUES('%s', '%s');", username,password); //sql = "INSERT INTO \"user\" VALUES('username', 'password');" ; sqlite3_exec( db , sql , 0 , 0 , &zErrMsg ); printf(sql); printf("插入數(shù)據(jù)成功!\n"); int nrow = 0, ncolumn = 0; char **azResult; //二維數(shù)組存放結(jié)果 //查詢數(shù)據(jù) /* int sqlite3_get_table(sqlite3*, const char *sql,char***result , int *nrow , int *ncolumn ,char **errmsg ); result中是以數(shù)組的形式存放你所查詢的數(shù)據(jù),首先是表名,再是數(shù)據(jù)。 nrow ,ncolumn分別為查詢語句返回的結(jié)果集的行數(shù),列數(shù),沒有查到結(jié)果時(shí)返回0 */ char *sql2 = "SELECT * FROM user"; sqlite3_get_table( db , sql2 , &azResult , &nrow , &ncolumn , &zErrMsg ); int i = 0 ; printf( "row:%d column=%d
[轉(zhuǎn)自] http://webdn.trueself.cn/archives/107
◆ 使用strtok函數(shù)分割。
原型:char *strtok(char *s, char delim);
strtok在s中查找包含在delim中的字符并用NULL('\0')來替換,直到找遍整個(gè)字符串。
功能:分解字符串為一組字符串。s為要分解的字符串,delim為分隔符字符串。
說明:首次調(diào)用時(shí),s指向要分解的字符串,之后再次調(diào)用要把s設(shè)成NULL。
strtok在s中查找包含在delim中的字符并用NULL('\0')來替換,直到找遍整個(gè)字符串。
返回值:從s開頭開始的一個(gè)個(gè)被分割的串。當(dāng)沒有被分割的串時(shí)則返回NULL。
所有delim中包含的字符都會(huì)被濾掉,并將被濾掉的地方設(shè)為一處分割的節(jié)點(diǎn)。
使用例:
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
int main(int argc,char **argv)
{
char * buf1="aaa, ,a, ,,,bbb-c,,,ee|abc";
/* Establish string and get the first token: */
char* token = strtok( buf1, ",-|");
while( token != NULL )
{
/* While there are tokens in "string" */
printf( "%s ", token );
/* Get next token: */
token = strtok( NULL, ",-|");
}
return 0;
}
OUT 值:
aaa
a
bbb
c
ee
abc
◆ 使用strstr函數(shù)分割。
原型:extern char *strstr(char *haystack,char *needle);
用法:#include <string.h>
功能:從字符串haystack中尋找needle第一次出現(xiàn)的位置(不比較結(jié)束NULL)
說明:返回指向第一次出現(xiàn)needle位置的指針,如果沒找到則返回NULL。
使用例:
#include <stdio.h>
#include <string.h>
int main(int argc,char **argv)
{
char *haystack="aaa||a||bbb||c||ee||";
char *needle="||";
char* buf = strstr( haystack, needle);
while( buf != NULL )
{
buf[0]='\0';
printf( "%s\n ", haystack);
haystack = buf + strlen(needle);
/* Get next token: */
buf = strstr( haystack, needle);
}
return 0;
}
OUT 值:
aaa
a
bbb
c
ee
◆ strtok比較適合多個(gè)字符作分隔符的場(chǎng)合,而strstr適合用字符串作分隔符的場(chǎng)合。
我們來看看到底如何從POST表單收集數(shù)據(jù)到CGI程序,下面給出了一個(gè)比較簡單的C源代碼:
#include<stdio.h>
#include<stdlib.h>
#define MAXLEN 80
#define EXTRA 5
/* 4個(gè)字節(jié)留給字段的名字"data", 1個(gè)字節(jié)留給"=" */
#define MAXINPUT MAXLEN+EXTRA+2
/* 1個(gè)字節(jié)留給換行符,還有一個(gè)留給后面的NULL */
#define DATAFILE "../data/data.txt"
/* 要被添加數(shù)據(jù)的文件 */
void unencode(char *src, char *last, char *dest)
{
for(; src != last; src++, dest++)
if(*src == "+")
*dest = " ";
else if(*src == "%") {
int code;
if(sscanf(src+1,"%2x",&code)!=1)code="?";
*dest=code;
src +=2;}
else
*dest=*src;
*dest=" ";
*++dest="";
}
int main(void)
{
char *lenstr;
char input[MAXINPUT], data[MAXINPUT];
long len;
printf("%s%c%c", "Content-Type:text/html;charset=gb2312",13,10);
printf("<TITLE>Response</TITLE>");
lenstr=getenv("CONTENT_LENGTH");
if(lenstr==NULL || sscanf(lenstr,"%ld",&len)!=1 || len>MAXLEN)
printf("<P>表單提交錯(cuò)誤");
else{
FILE *f;
fgets(input, len+1, stdin);
unencode(input+EXTRA, input+len, data);
f =fopen(DATAFILE, "a");
if(f == NULL)
printf("<P>對(duì)不起,意外錯(cuò)誤,不能夠保存你的數(shù)據(jù)");
else
fputs(data, f);
fclose(f);
printf("<P>非常感謝,您的數(shù)據(jù)已經(jīng)被保存<BR>%s",data);
}
return 0;
}
從本質(zhì)上來看,程序先從CONTENT_LENGTH環(huán)境變量中得到數(shù)據(jù)的字長,然后讀取相應(yīng)長度的字符串。因?yàn)閿?shù)據(jù)內(nèi)容在傳輸?shù)倪^程中是經(jīng)過了編碼的,所以必須進(jìn)行相應(yīng)的解碼。編碼的規(guī)則很簡單,主要的有這幾條:
1. 表單中每個(gè)每個(gè)字段用字段名后跟等號(hào),再接上上這個(gè)字段的值來表示,每個(gè)字段之間的內(nèi)容用&連結(jié); 2. 所有的空格符號(hào)用加號(hào)代替,所以在編碼碼段中出現(xiàn)空格是非法的;
3. 特殊的字符比如標(biāo)點(diǎn)符號(hào),和一些有特定意義的字符如“+”,用百分號(hào)后跟其對(duì)應(yīng)的ACSII碼值來表示。
例如:如果用戶輸入的是:
Hello there!
那么數(shù)據(jù)傳送到服務(wù)器的時(shí)候經(jīng)過編碼,就變成了data=Hello+there%21 上面的unencode()函數(shù)就是用來把編碼后的數(shù)據(jù)進(jìn)行解碼的。在解碼完成后,數(shù)據(jù)被添加到data.txt文件的尾部,并在瀏覽其中回顯出來。
把文件編譯完成后,把它改名為collect.cgi后放在CGI目錄中就可以被表單調(diào)用了。下面給出了其相應(yīng)的表單:
<FORM ACTION="/cgi-bin/collect.cgi" METHOD="POST" >
<P>請(qǐng)輸入您的留言(最多80個(gè)字符):<BR>
<INPUT NAME="data" SIZE="60" MAXLENGTH="80" ><BR>
<INPUT TYPE="SUBMIT" VALUE="確定">
</FORM >
事實(shí)上,這個(gè)程序只能作為例子,是不能夠正式的使用的。它漏掉了很關(guān)鍵的一個(gè)問題:當(dāng)有多個(gè)用戶同時(shí)像文件寫入數(shù)據(jù)是,肯定會(huì)有錯(cuò)誤發(fā)生。而對(duì)于一個(gè)這樣的程序而言,文件被同時(shí)寫入的幾率是很大的。因此,在比較正式的留言版程序中,都需要做一些更多的考慮,比如加入一個(gè)信號(hào)量,或者是借助于一個(gè)鑰匙文件等。因?yàn)槟侵皇蔷幊痰募记蓡栴},在這兒就不多說了。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
printf("Content-type:text/html\n\n");
printf("hello world!");
fflush(stdout);
}
處理get代碼
#include <stdio.h>
#include <stdlib.h>
int zmain(void)
{char *data;
long m,n;
printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10);
printf("<TITLE>Multiplication results</TITLE>\n");
printf("<H3>Multiplication results</H3>\n");
data = getenv("QUERY_STRING");
if(data == NULL)
printf("<P>Error! Error in passing data from form to script.");
else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)
printf("<P>Error! Invalid data. Data must be numeric.");
else
printf("<P>The product of %ld and %ld is %ld.",m,n,m*n);
return 0;
}
處理post代碼
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i,n;
printf("Content-type:text/html\n\n");
n=0;
if(getenv("CONTENT_LENGTH"))
n=atoi(getenv("CONTENT_LENGTH"));
printf("%d",n);
for(i=0;i<n;i++)
putchar(getchar());
putchar('\n');
fflush(stdout);
}
還是代碼
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* 轉(zhuǎn)換函數(shù)聲明 */
int htoi(char *);
/* 主函數(shù) */
void zmain() {
int i,n;
char c;
printf ("Content-type: text/html\n\n");
n=0;
if (getenv("CONTENT_LENGTH"))
n=atoi(getenv("CONTENT_LENGTH"));
for (i=0; i<n;i++){
int is_eq=0; //判斷是否有等于號(hào)。
c=getchar();
switch(c){
case '&':
c='\n';
break;
case '+':
c='+';
break;
case '%':
{
char s[3];
s[0]=getchar();
s[1]=getchar();
s[2]=0;
c=htoi(s);
i+=2;
}
break;
case '=':
c='=';
is_eq=1;
break;
};
putchar(c);
//if (is_eq) putchar(' ');
}
putchar ('\n');
fflush(stdout);
}
/* 轉(zhuǎn)換為小寫 */
int islower (int ch )
{
return (unsigned int) (ch - 'a') < 26u;
}
/* convert hex string to int 16進(jìn)制轉(zhuǎn)換成10進(jìn)制 */
int htoi(char *s)
{
char *digits="0123456789ABCDEF";
if(islower(s[0])) s[0]=toupper(s[0]);
if(islower(s[1])) s[1]=toupper(s[1]);
return 16 * (strchr(digits, s[0]) -strchr(digits,'0') ) +(strchr(digits,s[1])-strchr(digits,'0'));
}
#include<stdio.h>
#include<stdlib.h>
void zzzmain()
{
int i,n;
printf("Content-type:text/html\n\n");
n=0;
if(getenv("CONTENT_LENGTH"))
n=atoi(getenv("CONTENT_LENGTH"));
printf("%d",n);
for(i=0;i<n;i++)
putchar(getchar());
putchar('\n');
fflush(stdout);
}
http://samhe.javaeye.com/blog/142416 DWR(Direct Web Remoting)是一個(gè)WEB遠(yuǎn)程調(diào)用框架.利用這個(gè)框架可以讓AJAX開發(fā)變得很簡單.利用DWR可以在客戶端利用JavaScript直接調(diào)用服務(wù)端的Java方法并返回值給JavaScript就好像直接本地客戶端調(diào)用一樣(DWR根據(jù)Java類來動(dòng)態(tài)生成JavaScrip代碼).它的最新版本DWR0.6添加許多特性如:支持Dom Trees的自動(dòng)配置,支持Spring(JavaScript遠(yuǎn)程調(diào)用spring bean),更好瀏覽器支持,還支持一個(gè)可選的commons-logging日記操作.
1. dwr - direct web remote
2. 推技術(shù)
3. http 長連接
4. Comet ---- HTTP長連接的“服務(wù)器推”技術(shù)
5. Jetty服務(wù)器 ---- Jetty 6 Web 服務(wù)器針對(duì) AJAX、Comet 應(yīng)用的特點(diǎn)進(jìn)行了很多創(chuàng)新的改進(jìn),請(qǐng)參考文章“AJAX,Comet and Jetty”(請(qǐng)參見 參考資源)。
http://wiki.javascud.org/display/dwrcn/Home
http://wiki.springside.org.cn/display/springside/DWR
學(xué)習(xí)共進(jìn)!
MyEclipse 5.5 開發(fā) Struts 1.2 簡單登錄的入門視頻(有聲+源碼) 2007-09-19 01:50
視頻講解: Netbeans 5.5 配置顯示中文 JavaDoc
入門視頻: 使用 MyEclipse 開發(fā) Swing 應(yīng)用
河南話講解 MyEclipse + Tomcat Servlet 開發(fā)入門視頻
MyEclipse + JPA + Toplink 開發(fā)視頻: 開發(fā)并運(yùn)行第一個(gè) JPA 項(xiàng)目
MyEclipse + JBoss 開發(fā)視頻: 配置,開發(fā)并運(yùn)行第一個(gè) EJB 3 項(xiàng)目
JDBC 入門視頻: 配置 SQL Explorer 插件, ODBC 數(shù)據(jù)源, 建表, 用 JDBC 讀取數(shù)據(jù)庫
Tomcat 入門視頻: 下載, 運(yùn)行, 第一個(gè) HelloWorld
Eclipse 入門視頻: 下載, 運(yùn)行, 第一個(gè) HelloWorldJava 入門視頻: 下載, 安裝 JDK, 配置環(huán)境變量, HelloWorld
推薦給初學(xué)者的 Java 視頻
Netbeans 6.0 M10 開發(fā) UML 項(xiàng)目的入門視頻
MyEclipse UML 入門視頻2 - 根據(jù)代碼反向工程生成 UML
MyEclipse + Tomcat 開發(fā)視頻: 下載,安裝,配置,開發(fā)并運(yùn)行Web項(xiàng)目
小電影: 用 MyEclipse 開發(fā) Spring + Struts + Hibernate 的總結(jié)與操作視頻(9分鐘)
小電影: 用 MyEclipse 開發(fā) Spring + Struts 的總結(jié)與操作視頻(7分鐘)
用MyEclipse 4 分鐘開發(fā)Spring整合Hibernate應(yīng)用的視頻
在 Linux 上配置并運(yùn)行 Tomcat 服務(wù)器(入門整理)(視頻)
Java 初學(xué)者入門視頻: 下載 JDK 和 Netbeans
Hibernate 英文 PPT 及 MyEclipse 操作視頻整理
推薦一點(diǎn) MyEclipse 的官方Spring,Hibernate入門視頻教程
Netbeans 5.5 + JPA + Hibernate 3 + Tomcat 實(shí)例有聲視頻
夏昕 <<Spring 開發(fā)指南入門>>1 分鐘上手教程視頻(不帶解說)
Java EE 5 入門 PPT 講解有聲視頻 - 第二部分
Java EE 5 入門 PPT 講解有聲視頻 - 第一部分
Java EE 5 入門視頻 - 在 JSF 中使用 JPA
視頻:使用 Netbeans 5.5可視化開發(fā) JSF 的簡單注冊(cè)流程
Java EE 5 入門視頻 - 在 J2SE 中使用 JPA
Weblogic 9 之旅圖文視頻 2 - Portal 開發(fā)環(huán)境設(shè)置, 簡單的Portal 開發(fā)(視頻已貼上)
用 JProfiler4 調(diào)優(yōu) Weblogic 和 Tomcat 的視頻(原創(chuàng))
來自 http://www.aygfsteel.com/beansoft
public class UploadServlet extends HttpServlet {
protected void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {;}
protected void doPost( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {
MultipartRequest parts = new MultipartRequest( req, "C:\\MyUploadPath" );
PrintWriter out = res.getWriter();
out.print( "SUCCESS" );
out.close();
}
}
as:
private function doUpload( event:Object ):Void {
var file:FileReference = new FileReference();
// Ask the user to choose a file to upload
if( file.browse( ["JPEG Files", "*.jpg"] ) ) {
file.addListener( this );
file.upload( "http://myurl/servlet/MyUploadServlet" );
}
}
private function onUploadSuccess( ref:FileReference, response:String ):Void {
imgUpload.source = "http://myurl/myfilepath/" + ref.name;
}
private function onUploadFailed( ref:FileReference, error:String, response:String ):Void {
mx.controls.Alert.show( "Upload error: " + error );
}
已經(jīng)很久沒摸過FLASH了,由于要接一個(gè)項(xiàng)目需要用的flash實(shí)現(xiàn)。 當(dāng)我使用flash cs3 寫程序時(shí)發(fā)現(xiàn)已經(jīng)和以前的大不一樣了!多年沒接觸本來還想在友人面前顯耀一下寶刀未老,天哪,好多地方不一樣了,剛接觸還真不習(xí)慣,還出丑了。
flash cs3 的改變?cè)醋杂?as3的重大改變。更源于flash player AM2的重大改變。
下邊的所有都是自己對(duì)JAVA的理解不知道對(duì)不對(duì),有待于以后實(shí)踐驗(yàn)證
用JAVA編程,無論是什么框架,什么庫,什么插件, 他們的也還是來自 最基本java類編程。
比如,我猜想 TOMCAT服務(wù)器,也是由一個(gè)帶MAIN方法的類來啟動(dòng)的, 然后開通一個(gè)端口服務(wù)器,它的原理應(yīng)該和java socket server編程應(yīng)該是一個(gè)道理。主要是啟動(dòng)一些類,來接受客戶端的請(qǐng)求(容器的原理應(yīng)該是這樣吧)
java 中文亂碼處理。
參考
http://china.eceel.com/article/study_for_character_encoding_java.htm
http://upurban.com/bbs/viewtopic.php?t=246
1。什么是utf-8,什么是ISO-8859-1,什么是GB2312,還有什么是unicode
2。java 程序的字符的表示格式
3。jsp 程序中文顯示處理實(shí)例
3。1
<%@ page pageEncoding="ISO-8859-1"%>和<%@ page pageEncoding="GB2312"%>和<%@ page
pageEncoding="UTF-8"%>各自的意思是什么,他們是否只對(duì)post提交有效!
request.setCharacterEncoding("UTF-8")是什么意思?有什么區(qū)別?還有
response.setCharacterEncoding("UTF-8"),優(yōu)先于下邊
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
setCharacterEncoding()該函數(shù)用來設(shè)置http請(qǐng)求或者相應(yīng)的編碼。
對(duì)于request,是指提交內(nèi)容的編碼,指定后可以通過getParameter()則直接獲得正確的字符串,如果不
指定,則默認(rèn)使用iso8859-1編碼,需要進(jìn)一步處理。參見下述"表單輸入"。值得注意的是在執(zhí)行
setCharacterEncoding()之前,不能執(zhí)行任何getParameter()。java doc上說明:This method must be
called prior to reading request parameters or reading input using getReader()。而且,該指定
只對(duì)POST方法有效,對(duì)GET方法無效。分析原因,應(yīng)該是在執(zhí)行第一個(gè)getParameter()的時(shí)候,java將會(huì)
按照編碼分析所有的提交內(nèi)容,而后續(xù)的getParameter()不再進(jìn)行分析,所以setCharacterEncoding()無
效。而對(duì)于GET方法提交表單是,提交的內(nèi)容在URL中,一開始就已經(jīng)按照編碼分析所有的提交內(nèi)容,
setCharacterEncoding()自然就無效。
對(duì)于response,則是指定輸出內(nèi)容的編碼,同時(shí),該設(shè)置會(huì)傳遞給瀏覽器,告訴瀏覽器輸出內(nèi)容所采用的
編碼。
3.2. jsp輸出
指定文件輸出到browser是使用的編碼,該設(shè)置也應(yīng)該置于文件的開頭。例如:<%@ page
contentType="text/html; charset= GBK" %>。該設(shè)置和response.setCharacterEncoding("GBK")等效。
4。java EE程序利用過濾器 處理中文問實(shí)例
提交數(shù)據(jù)的編碼格式
tomcat默認(rèn)提交格式是ISO-8859-1
可以通過設(shè)置過濾器(只針對(duì)post提交)或修改server.xml 的URIencoding 編碼格式(只針對(duì)get提交)
達(dá)到你想要的 數(shù)據(jù)提交編碼格式。
總結(jié)
---by mylu 18:26 2007-5-20
ORM
Object Relation Mapping
對(duì)象 關(guān)系 映射
對(duì)象 指實(shí)體域?qū)ο?br />關(guān)系 關(guān)系數(shù)據(jù)
模型
概念模型(實(shí)體-屬性)
關(guān)系數(shù)據(jù)模型(關(guān)系數(shù)據(jù)庫)
域模型(對(duì)象)
軟件分層
v - 表述層
c /
??? /業(yè)務(wù)層
m- 持久層(hibernate 技術(shù)實(shí)現(xiàn))
??? \數(shù)據(jù)層
mvc 對(duì)應(yīng) 各層次
概念實(shí)體關(guān)系
1對(duì)1
1對(duì)多
多對(duì)多
表與表之間的關(guān)系 參照完整性
外鍵
多對(duì)多
多對(duì)一
域?qū)ο笾g的 關(guān)系
關(guān)聯(lián) (一對(duì)一 一對(duì)多 多對(duì)多)
依賴 (一個(gè)類需要訪問另外一個(gè)類)
聚集 (一個(gè)類的對(duì)象是另一個(gè)類的一部分, 人和手)
一般化 (繼承關(guān)系)
域?qū)ο?br />?實(shí)體域?qū)ο? (實(shí)體EJB,POJO)
過程域?qū)ο? (會(huì)話EJB,消息驅(qū)動(dòng)EJB,POJO)
事件域?qū)ο? ()
在hibernate中 一般只關(guān)注 實(shí)體域?qū)ο?和 過程域?qū)ο?/p>
域?qū)ο蟮年P(guān)系
?域?qū)ο蟮年P(guān)聯(lián)關(guān)系 是有方向的
體現(xiàn)在類的編碼不一樣的
單向關(guān)聯(lián)
雙向關(guān)聯(lián)
?
域?qū)ο蟮某志没?br />把對(duì)象從內(nèi)存中 保存到持久化設(shè)備中去
ORM 與? ORM模式
ORM模式是一種持久化技術(shù),還有其他模式的持久化技術(shù)。如主動(dòng)域模式(BMP),JDO模式,CMP模式。
域模型和數(shù)據(jù)模型的各個(gè)不匹配之處
1,繼承
2,多對(duì)多
3,雙向
4。粒度
盡量少連接查詢,很消耗時(shí)間的操作
?
創(chuàng)建持久化類
1。持久化類符合javabean的規(guī)范,包含一些屬性 以及對(duì)應(yīng)的getxxx 色天下學(xué)習(xí)方法
2。持久化類有一個(gè)id屬性,用來唯一表示類的每一個(gè)對(duì)象。 也叫OID 對(duì)象表示符
3。Hibernate要求持久化類必須提供一個(gè)不帶參數(shù)的默認(rèn)構(gòu)造方法
創(chuàng)建數(shù)據(jù)庫schema
創(chuàng)建對(duì)象-關(guān)系映射文件
(一般在eslispe中先創(chuàng)建數(shù)據(jù)庫 然后再創(chuàng)建持久化類以及映射文件)
hibernate 映射類型
hibernate的初始化
static{
try{
//根據(jù)默認(rèn)位置的hibernate配置文件創(chuàng)建 configuration實(shí)例
Configuration config = new Configuration();
config.addClass(Customer.class);
//創(chuàng)建SessionFactory 實(shí)例
sessionFactory = config.buildSessinoFactroy();
}catch(Exception e){e.printStackTrace();}
}
SessionFactory 接口
一個(gè)SessionFactory 實(shí)例是對(duì)應(yīng)一個(gè)數(shù)據(jù)源的,應(yīng)用從SessionFactory 獲取session實(shí)例對(duì)象
1線程安全的
2重量級(jí)的,不能隨意創(chuàng)建和銷毀她的實(shí)例。
Session 接口
1 Session接口是hibernate應(yīng)用最為廣泛的接口。
2 Session也被稱為持久化管理器,它提供和持久化相關(guān)的操作
3 Session有以下特點(diǎn)
?a 不是線程安全的 所以應(yīng)避免多線程共用一個(gè)Session實(shí)例
?b Session實(shí)例是輕量級(jí)的,所謂輕量級(jí)是指他的創(chuàng)建和銷毀不需要消耗太多的資源。意味著程序中可以經(jīng)常創(chuàng)建和銷毀Session實(shí)例,保證不多線程使用Session對(duì)象。
Session接口的常用方法:
save()
update()
delete()
load()
Session執(zhí)行事務(wù)流程
Session session = factory.openSession();
Transaction tx;
try{
tx = session.beginTranscation();
//執(zhí)行事務(wù)
...
//提交事務(wù)
tx.commit();
}
catche(Exception e)
{//如果出現(xiàn)異常,撤消事務(wù)
if(tx!=null)tx.rollback();
throw e;
}
finally{
session.close(); //不管事務(wù)是否成功,最后都要關(guān)閉session對(duì)象
}
}
?
?
?
?
版本0.1.0
(更新中...)
Table of Contents
Q: 如何使用導(dǎo)出功能
A: 為了使用導(dǎo)出功能,只需要在web.xml文件中加入eXtremeComponents的導(dǎo)出過濾器的配置,內(nèi)容如下:
<filter>
<filter-name>eXtremeExport</filter-name>
<filter-class>org.extremecomponents.table.filter.ExportFilter</filter-class>
<init-param>
<param-name>responseHeadersSetBeforeDoFilter</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>eXtremeExport</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Q: 傳入中文參數(shù)亂碼,如下頁面:
<form id="form1" name="form1" method="post" action="應(yīng)用eXtremeTable的action或是結(jié)果頁面名">
<select name="selecttype" size="6">
<option value="第一個(gè)">第一個(gè)</option>
<option value="第二個(gè)">第二個(gè)</option>
<option value="第三個(gè)">第三個(gè)</option>
</select>
<input type="text" name="username" />
<input type="submit" name="Submit" value="提交" />
</form>
當(dāng)你提交時(shí)含有eXtremeTable的結(jié)果頁面會(huì)自動(dòng)取得頁面上的表單參數(shù),那怕是經(jīng)過了action的mapping.findForward("forward"),在我的試用過程中到頁面上會(huì)出現(xiàn)傳遞過去的參數(shù),但出現(xiàn)了亂碼問題,使用查詢(filter)功能是的中文參數(shù)問題類似。
A:
確認(rèn)服務(wù)器的參數(shù)是否設(shè)置了正確的編碼,如果使用Tomcat請(qǐng)確認(rèn)Server.xml:
<Connector port="80" URIEncoding="UTF-8" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false"
redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" />
添加編碼過濾器到你的應(yīng)用工程:
/*
* Copyright 1999-2001,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package filters;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;
/**
* <p>Example filter that sets the character encoding to be used in parsing the
* incoming request, either unconditionally or only if the client did not
* specify a character encoding. Configuration of this filter is based on
* the following initialization parameters:</p>
* <ul>
* <li><strong>encoding</strong> - The character encoding to be configured
* for this request, either conditionally or unconditionally based on
* the <code>ignore</code> initialization parameter. This parameter
* is required, so there is no default.</li>
* <li><strong>ignore</strong> - If set to "true", any character encoding
* specified by the client is ignored, and the value returned by the
* <code>selectEncoding()</code> method is set. If set to "false,
* <code>selectEncoding()</code> is called <strong>only</strong> if the
* client has not already specified an encoding. By default, this
* parameter is set to "true".</li>
* </ul>
*
* <p>Although this filter can be used unchanged, it is also easy to
* subclass it and make the <code>selectEncoding()</code> method more
* intelligent about what encoding to choose, based on characteristics of
* the incoming request (such as the values of the <code>Accept-Language</code>
* and <code>User-Agent</code> headers, or a value stashed in the current
* user's session.</p>
*
* @author Craig McClanahan
* @version $Revision: 1.3 $ $Date: 2004/02/28 03:35:22 $
*/
public class SetCharacterEncodingFilter implements Filter {
// ----------------------------------------------------- Instance Variables
/**
* The default character encoding to set for requests that pass through
* this filter.
*/
protected String encoding = null;
/**
* The filter configuration object we are associated with. If this value
* is null, this filter instance is not currently configured.
*/
protected FilterConfig filterConfig = null;
/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;
// --------------------------------------------------------- Public Methods
/**
* Take this filter out of service.
*/
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
// Pass control on to the next filter
chain.doFilter(request, response);
}
/**
* Place this filter into service.
*
* @param filterConfig The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
// ------------------------------------------------------ Protected Methods
/**
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters. If no character encoding should be set, return
* <code>null</code>.
* <p>
* The default implementation unconditionally returns the value configured
* by the <strong>encoding</strong> initialization parameter for this
* filter.
*
* @param request The servlet request we are processing
*/
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}
在web.xml中添加編碼過濾器配置:
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>gb2312</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Q:關(guān)于導(dǎo)出時(shí)中文文件名為亂碼的問題
A: 這是個(gè)bug,建議使用英文文件名,主要原因還是編碼問題。我們現(xiàn)在正在想辦法解決。
Q:導(dǎo)出時(shí)文件內(nèi)容亂碼
A:首先請(qǐng)確認(rèn)使用的是extremecomponents-1.0.1-M5-A4版以后的版本
Q:當(dāng)變量名為"action",在IE下執(zhí)行產(chǎn)生javascript錯(cuò)誤
A: 內(nèi)部使用了一些關(guān)鍵字,就目前我所知的為"action"、"submit"。建議大家命名時(shí)盡量避免,如果大家必須使用,則可以使用table標(biāo)簽的autoIncludeParameters參數(shù)設(shè)置為"false":
autoIncludeParameters="false"
Q:怎么樣格式化輸出表單中的數(shù)據(jù)
A: 你可以設(shè)置列的cell:
詳細(xì)信息請(qǐng)參考指南
Q:怎么樣加入鏈接
A: 你可以參考下例:
<ec:table
var="pres"
items="presidents"
action="${pageContext.request.contextPath}/compact.run"
imagePath="${pageContext.request.contextPath}/images/table/compact/*.gif"
view="compact"
title="Compact Toolbar View"
showTooltips="false"
>
<ec:exportPdf
fileName="output.pdf"
tooltip="Export PDF"
headerColor="black"
headerBackgroundColor="#b6c2da"
headerTitle="Presidents"
text="PDF"
/>
<ec:exportXls
fileName="output.xls"
tooltip="Export Excel"
text="XLS"
/>
<ec:row>
<ec:column property="fullName" title="Name">
<a >${pres.fullName}</a>
</ec:column>
<ec:column property="nickName"/>
<ec:column property="term"/>
<ec:column property="born" cell="date"/>
<ec:column property="died" cell="date"/>
<ec:column property="career"/>
</ec:row>
</ec:table>
一個(gè)J2EE 工程中涉及的對(duì)象
?
概念
持久化框架、ORM框架、DAO設(shè)計(jì)模式
他們的關(guān)系是:ORM框架是一種持久化框架,DAO是用于實(shí)現(xiàn)持久化框架的一種設(shè)計(jì)模式。
沒什么區(qū)別
ActionErrors.GLOBAL_ERROR也是一個(gè)字符串。 最好寫做ActionErrors.GLOBAL_ERROR
不然的話可能會(huì)報(bào)錯(cuò)。
Cannot retrieve mapping for action
異常
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /Login (/Login是你的action名字)
可能原因
action沒有再struts-config.xml 中定義,或沒有找到匹配的action,例如在JSP文件中使用 <html:form action="Login.do".將表單提交給Login.do處理,如果出現(xiàn)上述異常,請(qǐng)查看struts-config.xml中的定義部分,有時(shí)可能是打錯(cuò)了字符或者是某些不符合規(guī)則,可以使用struts console工具來檢查。
Cannot retrieve definition for form bean null
異常
org.apache.jasper.JasperException: Cannot retrieve definition for form bean null
可能原因
這個(gè)異常是因?yàn)镾truts根據(jù)struts-config.xml中的mapping沒有找到action期望的form bean。大部分的情況可能是因?yàn)樵趂orm-bean中設(shè)置的name屬性和action中設(shè)置的name屬性不匹配所致。換句話說,action和form都應(yīng)該各自有一個(gè)name屬性,并且要精確匹配,包括大小寫。這個(gè)錯(cuò)誤當(dāng)沒有name屬性和action關(guān)聯(lián)時(shí)也會(huì)發(fā)生,如果沒有在action中指定name屬性,那么就沒有name屬性和action相關(guān)聯(lián)。當(dāng)然當(dāng)action制作某些控制時(shí),譬如根據(jù)參數(shù)值跳轉(zhuǎn)到相應(yīng)的jsp頁面,而不是處理表單數(shù)據(jù),這是就不用name屬性,這也是action的使用方法之一。
No action instance for path /xxxx could be created
異常
No action instance for path /xxxx could be created
可能原因
特別提示:因?yàn)橛泻芏嘀星闆r會(huì)導(dǎo)致這個(gè)錯(cuò)誤的發(fā)生,所以推薦大家調(diào)高你的web服務(wù)器的日志/調(diào)試級(jí)別,這樣可以從更多的信息中看到潛在的、在試圖創(chuàng)建action類時(shí)發(fā)生的錯(cuò)誤,這個(gè)action類你已經(jīng)在struts-config.xml中設(shè)置了關(guān)聯(lián)(即添加了<action>標(biāo)簽)。
在struts-config.xml中通過action標(biāo)簽的class屬性指定的action類不能被找到有很多種原因,例如:
定位編譯后的.class文件失敗。Failure to place compiled .class file for the action in the classpath (在web開發(fā)中,class的的位置在r WEB-INF/classes,所以你的action class必須要在這個(gè)目錄下。例如你的action類位于WEB-INF/classes/action/Login.class,那么在struts-config.xml中設(shè)置action的屬性type時(shí)就是action.Login).
拼寫錯(cuò)誤,這個(gè)也時(shí)有發(fā)生,并且不易找到,特別注意第一個(gè)字母的大小寫和包的名稱。
在struts-config.xml中指定的action類沒有繼承自Stuts的Action類,或者你自定義的Action類沒有繼承自Struts提供的Action類。
你的action類必須繼承自Struts提供的Action類。
你的classpath的問題。例如web server沒有發(fā)現(xiàn)你的資源文件,資源文件必須在WEB-INF/classes/目錄下。
Problem in struts-config.xml file with action mapping.
Problem with data-sources.xml file.
相關(guān)鏈接
http://www.mail-archive.com/struts-user ... org/msg65874.html
Action Mapping mistake in struts-config.xml:
http://www.manning.com/ao/readforum.ht ... mp;readthread=177
data-sources.xml file?:
http://www.caucho.com/quercus/faq/section.xtp?section_id=30
No getter method for property XXXX of bean org.apache.struts.taglib.html.BEAN
異常
javax.servlet.jsp.JspException: No getter method for property username of bean org.apache.struts.taglib.html.BEAN
可能原因
沒有位form bean中的某個(gè)變量定義getter 方法
這個(gè)錯(cuò)誤主要發(fā)生在表單提交的FormBean中,用struts標(biāo)記<html:text property=”username”>時(shí),在FormBean中必須有一個(gè)getUsername()方法。注意字母“U”。
Related Links
Case can trip up the matching between get method's name and name specified in Struts tag
http://saloon.javaranch.com/cgi-bin/ubb/ultimate ... c&f=58&t=000163
java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm
錯(cuò)誤
java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm
可能原因
這個(gè)錯(cuò)誤主要發(fā)生在在classpath中找不到相應(yīng)的Java .class文件。如果這個(gè)錯(cuò)誤發(fā)生在web應(yīng)用程序的運(yùn)行時(shí),主要是因?yàn)橹付ǖ腸lass文件不在web server的classpath中(/WEB-INF/classes 和 /WEB-INF/lib)。
在上面的錯(cuò)誤中,原因是找不到ActionForm類。
This error is sometimes seen when one or more ActionForm.class instances are actually in the classpath. This most often occurs when ActionForm.class is made available correctly by placing struts.jar in the /WEB-INF/lib directory. When this library has been correctly placed and it is verified that ActionForm.class actually is present in the struts.jar file, the problem is either that more than one copy of ActionForm.class is in the classpath or (more likely) that duplicate versions of class files other than ActionForm are in the same classpath, causing confusion. This is especially true if a class that extends ActionForm is made available twice, such as in an .ear file that encompasses a .war file as well as in the .war file's own classpath (/WEB-INF/classes). This problem can be resolved by guaranteeing that there are no redundant classes, especially those related to Struts (directly from Struts or extensions of Struts), in the web application's view.
相關(guān)連接
EJB and Web Shared Links:
http://forum.java.sun.com/thread.jsp?forum=26&am ... ;tstart=0&trange=15
Keep Action and ActionForm (and their children) as non-overlapping unit(s) of an application
http://www.mail-archive.com/struts-u ... ache.org/msg47466.html
http://www.mail-archive.com/struts-user ... org/msg47467.html
Exception creating bean of class org.apache.struts.action.ActionForm: {1}
異常
javax.servlet.jsp.JspException: Exception creating bean of class org.apache.struts.action.ActionForm: {1}
可能原因
Instantiating Struts-provided ActionForm class directly instead of instantiating a class derived off ActionForm. This might occur implicitly if you specify that a form-bean is this Struts ActionForm class rather than specifying a child of this class for the form-bean.
Not associating an ActionForm-descended class with an action can also lead to this error.
Related Links
Cannot find ActionMappings or ActionFormBeans collection
Exception
javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
可能原因
不是標(biāo)識(shí)Struts actionServlet的<servlet>標(biāo)記就是映射.do擴(kuò)展名的<sevlet-mapping>標(biāo)記或者兩者都沒有在web.xml中聲明。
在struts-config.xml中的打字或者拼寫錯(cuò)誤也可導(dǎo)致這個(gè)異常的發(fā)生。例如缺少一個(gè)標(biāo)記的關(guān)閉符號(hào)/>。最好使用struts console工具檢查一下。
另外,load-on-startup必須在web.xml中聲明,這要么是一個(gè)空標(biāo)記,要么指定一個(gè)數(shù)值,這個(gè)數(shù)值用來表servlet運(yùn)行的優(yōu)先級(jí),數(shù)值越大優(yōu)先級(jí)越低。
還有一個(gè)和使用load-on-startup有關(guān)的是使用Struts預(yù)編譯JSP文件時(shí)也可能導(dǎo)致這個(gè)異常。
相關(guān)鏈接
Explicitly Define <load-on-startup>
http://saloon.javaranch.com/cgi-bin/ubb/ultim ... topic&f=50&t=001055
http://threebit.net/tutorials/ejb/general/
NullPointerException at ... RequestUtils.forwardURL
異常
java.lang.NullPointerException at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1223)
可能原因
在struts-config.xml中的forward元素缺少path屬性。例如應(yīng)該是如下形式:
<forward name="userhome" path="/user/userhome.jsp"/>
Cannot find bean org.apache.struts.taglib.html.BEAN in any scope
Exception
javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope
Probable Causes
試圖在Struts的form標(biāo)記外使用form的子元素。這常常發(fā)生在你在</html:form>后面使用Struts的html標(biāo)記。
另外要注意可能你不經(jīng)意使用的無主體的標(biāo)記,如<html:form … />,這樣web 服務(wù)器解析時(shí)就當(dāng)作一個(gè)無主體的標(biāo)記,隨后使用的所有<html>標(biāo)記都被認(rèn)為是在這個(gè)標(biāo)記之外的,如又使用了<html:text property=”id”>
還有就是在使用taglib引入HTML標(biāo)記庫時(shí),你使用的prefix的值不是html。
相關(guān)連接
Using form subelements outside of a form tag
http://forum.java.sun.com/thread.jsp?thread= ... &message=1384153
Missing message for key xx.xx.xx
Exception
javax.servlet.jsp.JspException: Missing message for key xx.xx.xx
Probable Causes
這個(gè)key的值對(duì)沒有在資源文件ApplicationResources.properties中定義。如果你使用eclipse時(shí)經(jīng)常碰到這樣的情況,當(dāng)項(xiàng)目重新編譯時(shí),eclipse會(huì)自動(dòng)將classes目錄下的資源文件刪除。
資源文件ApplicationResources.properties 不在classpath中 應(yīng)將資源文件放到 WEB-INF/classes 目錄下,當(dāng)然要在struts-config.xml中定義)
Cannot find message resources under key org.apache.struts.action.MESSAGE
異常
Cannot find message resources under key org.apache.struts.action.MESSAGE
可能原因
很顯然,這個(gè)錯(cuò)誤是發(fā)生在使用資源文件時(shí),而Struts沒有找到資源文件。
Implicitly trying to use message resources that are not available (such as using empty html:options tag instead of specifying the options in its body -- this assumes options are specified in ApplicationResources.properties file)
XML parser issues -- too many, too few, incorrect/incompatible versions
Related Links
Provide Struts with Resource Bundle
http://threebit.net/tutorials/ejb/general/
XML Parser Issues
http://www.mail-archive.com/struts-user ... org/msg15779.html
No input attribute for mapping path /loginAction
錯(cuò)誤
No input attribute for mapping path /xxxxAction
可能原因e
No input attribute in action mapping in struts-config.xml file for the action with the name specified in the error message. An input attribute is not required if form validation is not performed (either because the validate attribute is set to false or because the validation method in the relevant form class is not implemented. The input attribute specifies the page leading to this action because that page is used to display error messages from the form validation.
Related Links
Strange Output Characters
錯(cuò)誤
Strange and seemingly random characters in HTML and on screen, but not in original JSP or servlet.
可能原因
混和使用Struts的html:form標(biāo)記和標(biāo)準(zhǔn)的HTML標(biāo)記不正確。
使用的編碼樣式在本頁中不支持。
"Document contained no data" or no data rendered on page
錯(cuò)誤
"Document contained no data" in Netscape
No data rendered (completely empty) page in Microsoft Internet Explorer
可能原因
使用一個(gè)Action的派生類而沒有實(shí)現(xiàn)perform()方法或execute()方法。在Struts1.0中實(shí)現(xiàn)的是perform()方法,在Struts1.1中實(shí)現(xiàn)的是execute()方法,但Struts1.1向后兼容perform()方法。
但你使用Struts1.1創(chuàng)建一個(gè)Action的派生類,并且實(shí)現(xiàn)了execute()方法,而你在Struts1.0中運(yùn)行的話,就會(huì)得到"Document contained no data" error message in Netscape or a completely empty (no HTML whatsoever) page rendered in Microsoft Internet Explorer.”的錯(cuò)誤信息。
在講外連接之前,先舉例介紹內(nèi)連接,也就是一般的相等連接。
select * from a, b where a.id = b.id;
對(duì)于外連接,Oracle中可以使用“(+)”來表示,9i可以使用LEFT/RIGHT/FULL OUTER JOIN,下面將配合實(shí)例一一介紹。
1. LEFT OUTER JOIN:左外關(guān)聯(lián)
SELECT e.last_name, e.department_id, d.department_name?
FROM employees e?
LEFT OUTER JOIN departments d?
ON (e.department_id = d.department_id);
?
等價(jià)于
SELECT e.last_name, e.department_id, d.department_name?
FROM employees e, departments d?
WHERE e.department_id=d.department_id(+);
?
結(jié)果為:所有員工及對(duì)應(yīng)部門的記錄,包括沒有對(duì)應(yīng)部門編號(hào)department_id的員工記錄。
2. RIGHT OUTER JOIN:右外關(guān)聯(lián)
SELECT e.last_name, e.department_id, d.department_name?
FROM employees e?
RIGHT OUTER JOIN departments d?
ON (e.department_id = d.department_id);
?
等價(jià)于
SELECT e.last_name, e.department_id, d.department_name?
FROM employees e, departments d?
WHERE e.department_id(+)=d.department_id;
?
結(jié)果為:所有員工及對(duì)應(yīng)部門的記錄,包括沒有任何員工的部門記錄。
3. FULL OUTER JOIN:全外關(guān)聯(lián)
SELECT e.last_name, e.department_id, d.department_name?
FROM employees e?
FULL OUTER JOIN departments d?
ON (e.department_id = d.department_id);
?
結(jié)果為:所有員工及對(duì)應(yīng)部門的記錄,包括沒有對(duì)應(yīng)部門編號(hào)department_id的員工記錄和沒有任何員工的部門記錄。
下棋沒啥長進(jìn),今天用了半個(gè)小時(shí)看看兵書,總結(jié)一下。
開局基本原理:
[盡快集結(jié)子力]
[爭奪河界]
1。 盡快集結(jié)子力
·????????如無必要,不要重復(fù)走同一子
·? ?? ???先出炮、馬 ,然后車、兵?? ?[車要通 馬要靈 炮要能呼應(yīng)]
·? ?? ???不可用一兩個(gè)棋盲目進(jìn)攻
·? ?? ???子力要互相呼應(yīng),互相配合,不可互相干擾和阻塞
·? ?? ???若吃兵使用對(duì)方能力快速出子或發(fā)動(dòng)攻勢(shì),便不要吃
·? ?? ???若吃兵使用對(duì)方能力快速出子或發(fā)動(dòng)攻勢(shì),便不要吃
2.?????? 爭奪河界 :
除車以外,其他棋子在河界附近都可發(fā)揮最大威力及控制力,在中心的棋子要調(diào)動(dòng)到兩翼也較靈活、快速,所以河界附近為兵家必爭之地。若河界附近被對(duì)方占領(lǐng),便得設(shè)法攻下它。反之,自己占據(jù)時(shí),須要堅(jiān)守并利用它向?qū)Ψ降木艑m進(jìn)攻。
中局原理
3.? ?? ? 善用「車」:
4.????????在防守中進(jìn)攻,兼顧協(xié)調(diào)
5.?????? 保護(hù)「士兵」:
關(guān)鍵還是實(shí)戰(zhàn)時(shí)眼光銳利,先人一步。
oracle 分頁
1. 最好還是利用分析函數(shù)
row_number() over ( partition by col1 order by col2 )
比如想取出100-150條記錄,按照tname排序
select tname,tabtype from (
?? select tname,tabtype,row_number() over ( order by tname ) rn from tab
)
where rn between 100 and 150;
2. 直接使用rownum 虛列
select tname,tabtype from (
?? select tname,tabtype,rownum rn from tab where rownum <= 150
)
where rn >= 100;
使用序列不能基于整個(gè)記錄集合進(jìn)行排序,如果指定了order by子句,排序的的是選出來的記錄集的排序.
------------------------------------------------------------------------
經(jīng)過測(cè)試,在100萬條數(shù)據(jù)的表中,檢索數(shù)據(jù)的時(shí)候,方法2的速度要比方法1要快的.
排序分頁
說明:Oracle下用rownum進(jìn)行分頁時(shí) 很容易出現(xiàn)排序的錯(cuò)亂。
但多套一層select 就能很好的解決該問題,特此記錄,語句如下:
select t2.* from (select t1.*, rownum rn from (select * from tb_courseinfo order by rownum? desc )t1 where rownum <=?150 )t2 where rn >100
不懂具體效率怎么樣,和上邊一樣應(yīng)該還可以。
實(shí)際例子代碼如下
int curpage=1;//當(dāng)前頁
int page_record=20;//每頁顯示的記錄數(shù)
int introwcount=0; // 記錄數(shù)
if(request.getParameter("page")==null||Integer.parseInt(request.getParameter("page"))<=0)
{
curpage = 0;
}
else
{
curpage=Integer.parseInt(request.getParameter("page"))-1;//獲取傳遞的值,需要顯示的頁
}
String sql = "select t2.* from (select t1.*, rownum rn from (select * from tb_courseinfo order by rownum? desc )t1 where rownum <= "+(curpage+1)*page_record+" )t2 where rn > "+curpage*page_record;