久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

第一章:struts2框架與hibernate框架

 太極混元天尊 2018-06-11

一,、使用struts2實(shí)現(xiàn)文件上傳

1,、寫頁面upload.jsp

? ? ? ?
?

2,、寫uploadAction.java文件

1,、獲取myfile,,myfileFileName的get與set方法

2、指定路徑

3,、判斷路徑是否存在,,如果不存在則新建

4、把文件名與路徑拼接

5,、使用fileUtiles工具類把文件復(fù)制到指定路徑下

private File myfile; private String myfileFileName; public String upload() throws IOException{ String path=''D:/upload''; File f=new File(path); if(!f.exists()){ f.mkdirs(); } File file=new File(path,myfileFileName); FileUtils.copyFile(myfile,file); return ''upload''; }

3,、在struts.xml文件中配置

/uploadsuccess.jsp upload

二、使用struts2框架和ajax寫用戶名校驗(yàn)

1,、寫ajax.jsp頁面

2,、寫ajaxAction.java文件

private String name; private String msg; public String ajax() throws IOException{ if(name.equals(''小明'')){ msg=''1''; }else{ msg=''0''; } HttpServletResponse response= ServletActionContext.getResponse(); response.setCharacterEncoding(''utf-8''); response.getWriter().print(msg); return null; }

3、在xml文件中配置

ajax

三,、使用struts2框架通過hello.action路徑,,可以訪問到TestAction的hello()方法

在xml文件中添加代碼

四、采用hibernate框架編寫代碼對(duì)people表進(jìn)行增,刪,改,查操作

用hibernate框架首先寫hibernate.cfg.xml配置文件

com.mysql.jdbc jdbc:mysql://localhost:3306/work_hibernate root wanghui true true update org.hibernate.dialect.MySQL5InnoDBDialect 4

1,、寫pojo類people.java

@Entity創(chuàng)建表

@Id

@GeneratedValue(strategy=GenerationType.IDENTITY)

指定主鍵與主鍵生成策略

@Entitypublic class People { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Integer id; private String name; private Integer age; private String sex;

2,、寫測(cè)試類測(cè)試

public void save(){ Session session=HibernateUtil.getSessionfactory().openSession(); Transaction ta=session.beginTransaction(); session.save(new People(null, ''小芳'', 26, ''男'')); ta.commit(); session.close(); } public void delete(){ Session session=HibernateUtil.getSessionfactory().openSession(); Transaction ta=session.beginTransaction(); People people=session.get(People.class, 1); session.delete(people); ta.commit(); session.close(); } public void update(){ Session session=HibernateUtil.getSessionfactory().openSession(); Transaction ta=session.beginTransaction(); Query query=session.createQuery(''update People set age=age+1''); query.executeUpdate(); ta.commit(); session.close(); } public void sel(){ Session session=HibernateUtil.getSessionfactory().openSession(); Transaction ta=session.beginTransaction(); People people=session.get(People.class, 2); System.out.println(people); ta.commit(); session.close(); } public static void main(String[] args) { PeopleTest test=new PeopleTest(); //test.save(); //test.delete(); //test.update(); test.sel(); }

五、通過hibernate框架描述emp表和dept表的一對(duì)多關(guān)系,,并寫主方法查詢,,在查詢部門信息的同時(shí),把該部門下的員工信息查出來

1,、emp.java與dept.java文件

emp:@Entitypublic class Emp { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Integer id; private String name;?dept:@Entitypublic class Dept { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Integer id; private String name; @OneToMany @JoinColumn(name=''dept_id'') private Set emps=new HashSet<>();

2,、寫測(cè)試類

public void save(){ Session session=HibernateUtil.getSessionfactory().openSession(); Transaction ta=session.beginTransaction(); Set emps=new HashSet<>(); emps.add(session.get(Emp.class, 1)); session.save(new Dept(null, ''研發(fā)部'',emps)); ta.commit(); session.close(); } public void sel(){ Session session=HibernateUtil.getSessionfactory().openSession(); Transaction ta=session.beginTransaction(); Dept dept=session.get(Dept.class, 1); System.out.println(dept); ta.commit(); session.close(); } public static void main(String[] args) { DeptTest test=new DeptTest(); //test.save(); test.sel(); }

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多