开发人员手册_第1页
开发人员手册_第2页
开发人员手册_第3页
开发人员手册_第4页
开发人员手册_第5页
已阅读5页,还剩37页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、开发人员手册软件的下载与安装必备的安装软件:JDK 1.6直接安装,全部选择确定。Eclipse Mysql 5.6.Navicat 11.1.9Tomcat 7.0 2.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.1 Mysql数据库创建项目后端开发。数据库的连接封装引入JDBC的驱动,可以从mysql的

2、安装目录中找到。创建一个数据库连接类package org.bn.oa.conn;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;publicclass OAConn private Connection conn;public OAConn()try Class.forName(com.mysql.jdbc.Driver); catch (ClassNotFoundException e) / TODO: handle exceptione.printStackTrac

3、e();public Connection getConnection()try conn=DriverManager.getConnection(jdbc:mysql:/localhost:3306/oa, root, root); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();returnthis.conn;publicvoid closeConnection()try conn.close(); catch (SQLException e) / TODO Auto-generated

4、 catch blocke.printStackTrace();实体层创建一个包,用来存放实体,每一个实体与数据库中的一张表进行对应。创建一个新的实体类User对User类的属性定义package org.bn.oa.beans;publicclassUser privateintid;publicint getUserId() returnthis.id;publicvoid setUserId(int userid) this.id = userid;private String name;public String getName() ;publicvoid

5、 setUserName(String username) = username;private String sex;public String getUserSex() returnthis.sex;publicvoid setUserSex(String usersex) this.sex = usersex;private String identityNum;public String getIdentityNum() returnthis.identityNum;publicvoid setIdentityNum(String identitynum) this

6、.identityNum = identitynum;privateintisvalid;publicint getIsValid() returnthis.isvalid;publicvoid setIsValid(int isvalid) this.isvalid = isvalid;private String telephone;public String getTelephone() returnthis.telephone;publicvoid setTelephone(String telephone) this.telephone = telephone;private Str

7、ing mail;public String getMail()returnthis.mail;publicvoid setMain(String mail)this.mail=mail; Dao层创建一个新的包,用来存放用户操作的接口在该包下创建接口userDaopackage org.bn.oa.dao;import java.util.ArrayList;import org.bn.oa.beans.User;publicinterface UserDao /1 success,0 failpublicint insertUser(User user);/1 success,0 fail

8、publicintupdateUser(User user);/1 success,0 failpublicint deleteUser(long userId);public User getSingleUserById(long userID);public ArrayList getUserList();创建DaoImpl包以存放Dao接口的实现类编写实现userDao的实现类UserDaoImplpackage org.bn.oa.daoImpl;import java.util.ArrayList;import org.bn.oa.beans.User;import org.bn.o

9、a.conn.OAConn;import org.bn.oa.dao.UserDao;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;publicclass UserDaoImpl implements UserDao private OAConn oacon;public UserDaoImpl() oacon = new OAConn();Overridepublicint insertUser(User user) / TODO Auto-generated

10、method stubString sql = insert into user(name,sex,identityNum,isvalid,telphone,mail) values(?,?,?,?,?,?);PreparedStatement ps;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.

11、getIsValid();ps.setString(5, user.getTelephone();ps.setString(6, user.getMail();ps.executeUpdate(); catch (SQLException e) / TODO Auto-generated catch blockreturn 0;oacon.closeConnection();return 1;Overridepublicint deleteUser(long userId) / TODO Auto-generated method stubString sql = delete from us

12、er where id=?;PreparedStatement ps;try ps = oacon.getConnection().prepareStatement(sql);ps.setLong(1, userId);ps.execute(); catch (SQLException e) / TODO Auto-generated catch blockreturn 0;oacon.closeConnection();return 1;Overridepublic User getSingleUserById(long userID) / TODO Auto-generated metho

13、d stub/ TODO Auto-generated method stubString sql = select * from user where id=?;User user = new User();PreparedStatement ps;try ps = oacon.getConnection().prepareStatement(sql);ps.setLong(1, userID);ResultSet rs = ps.executeQuery();while (rs.next()user.setUserId(rs.getLong(1);user.setUserName(rs.g

14、etString(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 (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();oacon.closeConnection();return user;Over

15、ridepublic ArrayList getUserList() / TODO Auto-generated method stubArrayList users = new ArrayList();String sql = select * from user;PreparedStatement ps;try ps = oacon.getConnection().prepareStatement(sql);ResultSet rs = ps.executeQuery();while (rs.next() User user = new User();user.setUserName(rs

16、.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 (SQLException e) / TODO Auto-generated cat

17、ch blockreturnnull;oacon.closeConnection();return users;Overridepublicint updateUser(User user) / TODO Auto-generated method stubString sql = update user set name=?,sex=?,identityNum=?,isvalid=?,telphone=?,mail=? where id=?;PreparedStatement ps;try ps = oacon.getConnection().prepareStatement(sql);ps.setString(1, user.getName();ps.setString(2, user.getUserSex();ps.setString(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论