關於hibernate和struts2結合的用法

2021-08-14 11:32:16 字數 3085 閱讀 4854

關於乙個完整資料傳輸過程,即資料從頁面通過三層傳到資料庫,或者資料從資料庫通過三層傳到頁面,目前我使用了 兩個框架,這裡我做個總結。

hibernate:

相對於struts2,hibernate還是比較容易理解,即改變service層和dao層的結構,service層變化不大,主要是把sql改變成hql,這裡就不多講,主要的改變是dao層,其中主要**如下:

session session=null;

transaction tx=null;

public listselectall(string hql,int page)

public int add(student s)

public student selectone(int id)

public int update(student st) catch (exception e)

return a;

}public int delete(student st) catch (exception e)

return a;

}public int counts(string hql)

struts2:

struts2主要改變servlet層,簡化了資料從頁面與servlet層傳輸的**,使用了struts2後,servlet層講不存在,改變成action層,主要**如下:

private string page;

private string tname;

private string tage;

private string tid;

//封裝檔案標題屬性

private string title;

//封裝上傳檔案屬性

private file upload;

//獲取提交的檔案型別

private string uploadcontenttype;

//封裝上傳檔名稱

private string uploadfilename;

public string gettid()

public void settid(string tid)

public string gettitle()

public void settitle(string title)

public file getupload()

public void setupload(file upload)

public string getuploadcontenttype()

public void setuploadcontenttype(string uploadcontenttype)

public string getuploadfilename()

public void setuploadfilename(string uploadfilename)

public string getpage()

public void setpage(string page)

public string gettname()

public void settname(string tname)

public string gettage()

public void settage(string tage)

stuservice u=new stuserviceimpl();

student st=new student();

public student getmodel()

teaservice t=new teaserviceimpl();

public string add()

fis.close();

fos.flush();

fos.close();

st.setphoto("upload\\"+this.getuploadfilename());

teacher teacher=t.selectone(integer.parseint(tid));

student s=new student(st.getname(), st.get***(), st.getage(), st.getphoto(), teacher);

int a=u.add(s);

if(a>0)else

} catch (filenotfoundexception e) catch (ioexception e)

return "error";

}public void selectall()

student s=new student();

if(tage==null||"".equals(tage.trim()))

s.setname(tname);

s.setage(integer.parseint(tage));

datagrade dg=u.selectall(s,integer.parseint(page));

super.writejson(dg);

} catch (exception e)

}public string selectone()

public string update()else

return "error";

}public string delete()else

return "error";

}ajax:

function show(page),

datatype:'json',

async:false,

success:function(data)

h+="

總頁數:"+data.sumpage+"";

$("#h1").html(h);

},error:function()

});}

總結:

以上**是關於學生類和老師類的增刪改查,因為老師關聯了學生,我只顯示學生類,自然老師可以想象出來。以上**沒有任何意義,這篇部落格只是讓我在想不起**的時候拿來看的,對各位看客毫無意義。

關於django模型裡面的 str 和

簡而言之,就是 str 和 unicode 都是為了再管理站點中載入這個表時想顯示什麼屬性,當然一般都是顯示乙個name,大體來講是通用的。下面是抄的csdn上面的一篇文章。str 是python的乙個 魔幻 方法,這個方法定義了當object呼叫str 時應該返回的值。django在許多地方使用s...

str函式和mem函式

1 兩函式的標頭檔案都是一樣的 2 str帶頭的函式可以處理字串,遇到null 0 就會停止操作,而mem帶頭的函式則不用,但是它需要指定複製值的長度,以位元組計算 3 常見str帶頭的函式有strlen strcpy strcat strcmp strncpy等,字串查詢。4 常見mem帶頭的函式...

str和byte的區別

1 bytes物件只負責以二進位制位元組序列的形式記錄所需記錄的物件,至於該物件到底表示什麼 比如到底是什麼字元 則由相應的編碼格式解碼所決定 2 bytes是python 3中特有的,python 2 裡不區分bytes和str。3 python3中 str 使用encode方法轉化為 bytes...