开发人员手册

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

开发人员手册1.0软件的下载与安装必备的安装软件:JDK1.6直接安装,全部选择确定。EclipseMysql5.6.Navicat11.1.9Tomcat7.02.Eclipse+Tomcat配置3Eclipse项目搭建与开发1.打开Eclipse---file--------New---------project选择项目按Alt+Enter把mysql-connector-java-5.1.33-bin框架包放入OA项目WEB-Info/lib目录下创建项目WebContent/WEB-INF目录下创建web.xml3.1Mysql数据库创建项目后端开发。1.数据库的连接封装引入JDBC的驱动,可以从mysql的安装目录中找到。创建一个数据库连接类packageorg.bn.oa.conn;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;publicclassOAConn{privateConnectionconn;publicOAConn(){try{Class.forName(com.mysql.jdbc.Driver);}catch(ClassNotFoundExceptione){//TODO:handleexceptione.printStackTrace();}}publicConnectiongetConnection(){try{conn=DriverManager.getConnection(jdbc:mysql://localhost:3306/oa,root,root);}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnthis.conn;}publicvoidcloseConnection(){try{conn.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}2.实体层创建一个包,用来存放实体,每一个实体与数据库中的一张表进行对应。创建一个新的实体类User对User类的属性定义packageorg.bn.oa.beans;publicclassUser{privateintid;publicintgetUserId(){returnthis.id;}publicvoidsetUserId(intuserid){this.id=userid;}privateStringname;publicStringgetName(){returnthis.name;}publicvoidsetUserName(Stringusername){this.name=username;}privateStringsex;publicStringgetUserSex(){returnthis.sex;}publicvoidsetUserSex(Stringusersex){this.sex=usersex;}privateStringidentityNum;publicStringgetIdentityNum(){returnthis.identityNum;}publicvoidsetIdentityNum(Stringidentitynum){this.identityNum=identitynum;}privateintisvalid;publicintgetIsValid(){returnthis.isvalid;}publicvoidsetIsValid(intisvalid){this.isvalid=isvalid;}privateStringtelephone;publicStringgetTelephone(){returnthis.telephone;}publicvoidsetTelephone(Stringtelephone){this.telephone=telephone;}privateStringmail;publicStringgetMail(){returnthis.mail;}publicvoidsetMain(Stringmail){this.mail=mail;}}3.Dao层创建一个新的包,用来存放用户操作的接口4.在该包下创建接口userDaopackageorg.bn.oa.dao;importjava.util.ArrayList;importorg.bn.oa.beans.User;publicinterfaceUserDao{//1success,0failpublicintinsertUser(Useruser);//1success,0failpublicintupdateUser(Useruser);//1success,0failpublicintdeleteUser(longuserId);publicUsergetSingleUserById(longuserID);publicArrayListUsergetUserList();}创建DaoImpl包以存放Dao接口的实现类编写实现userDao的实现类UserDaoImplpackageorg.bn.oa.daoImpl;importjava.util.ArrayList;importorg.bn.oa.beans.User;importorg.bn.oa.conn.OAConn;importorg.bn.oa.dao.UserDao;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;publicclassUserDaoImplimplementsUserDao{privateOAConnoacon;publicUserDaoImpl(){oacon=newOAConn();}@OverridepublicintinsertUser(Useruser){//TODOAuto-generatedmethodstubStringsql=insertintouser(name,sex,identityNum,isvalid,telphone,mail)values(?,?,?,?,?,?);PreparedStatementps;try{ps=oacon.getConnection().prepareStatement(sql);ps.setString(1,user.getName());ps.setString(2,user.getUserSex());ps.setString(3,user.getIdentityNum());ps.setInt(4,user.getIsValid());ps.setString(5,user.getTelephone());ps.setString(6,user.getMail());ps.executeUpdate();}catch(SQLExceptione){//TODOAuto-generatedcatchblockreturn0;}oacon.closeConnection();return1;}@OverridepublicintdeleteUser(longuserId){//TODOAuto-generatedmethodstubStringsql=deletefromuserwhereid=?;PreparedStatementps;try{ps=oacon.getConnection().prepareStatement(sql);ps.setLong(1,userId);ps.execute();}catch(SQLExceptione){//TODOAuto-generatedcatchblockreturn0;}oacon.closeConnection();return1;}@OverridepublicUsergetSingleUserById(longuserID){//TODOAuto-generatedmethodstub//TODOAuto-generatedmethodstubStringsql=select*fromuserwhereid=?;Useruser=newUser();PreparedStatementps;try{ps=oacon.getConnection().prepareStatement(sql);ps.setLong(1,userID);ResultSetrs=ps.executeQuery();while(rs.next()){user.setUserId((rs.getLong(1)));user.setUserName(rs.getString(2));user.setUserSex(rs.getString(3));user.setIdentityNum(rs.getString(4));user.setIsValid(rs.getInt(5));user.setTelephone(rs.getString(6));user.setMail(rs.getString(7));}rs.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}oacon.closeConnection();returnuser;}@OverridepublicArrayListUsergetUserList(){//TODOAuto-generatedmethodstubArrayListUserusers=newArrayListUser();Stringsql=select*fromuser;PreparedStatementps;try{ps=oacon.getConnection().prepareStatement(sql);ResultSetrs=ps.executeQuery();while(rs.next()){Useruser=newUser();user.setUserName(rs.getString(name));user.setUserSex(rs.getString(sex));user.setUserId(rs.getLong(id));user.setTelephone(rs.getString(telphone));user.setMail(rs.getString(mail));user.setIdentityNum(rs.getString(identityNum));user.setIsValid(rs.getInt(isvalid));users.add(user);}}catch(SQLExceptione){//TODOAuto-generatedcatchblockreturnnull;}oacon.closeConnection();returnusers;}@OverridepublicintupdateUser(Useruser){//TODOAuto-generatedmethodstubStringsql=updateusersetname=?,sex=?,identityNum=?,isvalid=?,telphone=?,mail=?whereid=?;PreparedStatementps;try{ps=oacon.getConnection().prepareStatement(sql);ps.setString(1,user.getNam

1 / 38
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功