版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年福建省福州墨尔本理工职业学院人才招聘笔试考试备考题库及答案解析
- 2025四川德阳市广安发展工程建设有限公司第二批项目合同制员工招聘补充说明考试笔试模拟试题及答案解析
- 2025四川达州市中心医院招收重症护理进修学员备考考试试题及答案解析
- 深度解析(2026)《GBT 25919.1-2010 Modbus测试规范 第1部分:Modbus串行链路一致性测试规范》
- 2025年秋季泉州市丰泽区云山实验小学语文顶岗教师招聘参考考试题库及答案解析
- 2025辽宁沈阳盛京资产管理集团有限公司所属子公司沈阳华海锟泰投资有限公司所属子公司招聘5人备考笔试题库及答案解析
- 2025广东广州景泰第三幼儿园教师招聘1人参考考试试题及答案解析
- 2025安徽皖新融资租赁有限公司服务人员招聘岗位核减参考考试试题及答案解析
- 2025成都易付安科技有限公司第一批次招聘15人笔试考试参考题库及答案解析
- 2025贵州万山宏鑫环保科技有限责任公司临聘人员招聘8人参考考试题库及答案解析
- 回转窑安装说明书样本
- 2025年中共宜春市袁州区委社会工作部公开招聘编外人员备考题库附答案详解
- 2026年中医养生馆特色项目打造与客流增长
- 2025年社保常识测试题库及解答
- 2025年铁路运输合同书
- 消防设施培训课件
- 疤痕子宫破裂护理查房
- 2025-2026学年人教版高一生物上册必修1第1-3章知识清单
- 肾内科常见并发症的观察与应急处理
- 《马克思主义与社会科学方法论题库》复习资料
- 西游记第64回课件
评论
0/150
提交评论