admin 管理员组文章数量: 887021
2024年2月18日发(作者:vb字符串截取字符函数)
Tomcat配置完成之后,我们需要连接数据库4.连接数据库
5.编写实体类实体类中的四个类是与数据库当中的四个表相对应的。public class Bill { private Integer id; //id
e = proCode; } public String getProName() { return proName; } public void setProName(String proName) { e = proName; } public String getProDesc() { return proDesc; } public void setProDesc(String proDesc) { c = proDesc; } public String getProContact() { return proContact; } public void setProContact(String proContact) { tact = proContact; } public String getProPhone() { return proPhone; } public void setProPhone(String proPhone) { ne = proPhone; } public String getProAddress() { return proAddress; } public void setProAddress(String proAddress) { ress = proAddress; } public String getProFax() { return proFax; } public void setProFax(String proFax) { = proFax; } public Integer getCreatedBy() { return createdBy; } public void setCreatedBy(Integer createdBy) { dBy = createdBy; } public Date getCreationDate() { return creationDate; } public void setCreationDate(Date creationDate) { onDate = creationDate; } public Integer getModifyBy() { return modifyBy; } public void setModifyBy(Integer modifyBy) { By = modifyBy; } public Date getModifyDate() { return modifyDate; } public void setModifyDate(Date modifyDate) { Date = modifyDate; }}
public Integer getGender() { return gender; } public void setGender(Integer gender) { = gender; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { ay = birthday; } public String getPhone() { return phone; } public void setPhone(String phone) { = phone; } public String getAddress() { return address; } public void setAddress(String address) { s = address; } public Integer getUserRole() { return userRole; } public void setUserRole(Integer userRole) { le = userRole; } public Integer getCreatedBy() { return createdBy; } public void setCreatedBy(Integer createdBy) { dBy = createdBy; } public Date getCreationDate() { return creationDate; } public void setCreationDate(Date creationDate) { onDate = creationDate; } public Integer getModifyBy() { return modifyBy; } public void setModifyBy(Integer modifyBy) { By = modifyBy; } public Date getModifyDate() {
(" and me like ?"); ("%" + username + "%"); } if(userRole > 0){ (" and le = ?"); (userRole); } Object[] objects = y(); rs = e(connection,ng(),objects,rs,pstm); if(()){ count = ("count"); //sql已经把字段名重命名为count } (connection,pstm,null); } return count;}service层实现public List
if(flag){ try { direct(textPath() + "/jsp/?method=query"); } catch (IOException e) { tackTrace(); } }else{ try { uestDispatcher("").forward(req,resp); } catch (ServletException e) { tackTrace(); } catch (IOException e) { tackTrace(); } }}public void isUserCodeExist(HttpServletRequest req, HttpServletResponse resp) { String userCode = ameter("userCode"); Map
public boolean modify(Connection connection, User user) throws SQLException { boolean flag = false; PreparedStatement pstm = null; if(connection != null){ String sql = "update smbms_user as s set me=?,=?," + "ay=?,=?,s=?,le=? where =? "; Object[] params = {rName(),der(),thday(),ne(), ress(),rRole(),()}; int execute = e(connection, sql, params, pstm); if(execute > 0){ flag = true; } (connection,pstm,null); } return flag;}service层public boolean modify(User user);public boolean modify(User user) { boolean flag = false; Connection connection = null; if(user != null){ connection = nection(); try { flag = (connection, user); } catch (SQLException e) { tackTrace(); }finally{ (connection,null,null); } } return flag;}servlet层
public void modify(HttpServletRequest req, HttpServletResponse resp){ String id = ameter("uid"); String userName = ameter("userName"); String gender = ameter("gender"); String birthday = ameter("birthday"); String phone = ameter("phone"); String address = ameter("address"); String userRole = ameter("userRole"); User user = new User(); (f(id)); rName(userName); der(f(gender)); try { thday(new SimpleDateFormat("yyyy-MM-dd").parse(birthday)); } catch (ParseException e) { tackTrace(); } ne(phone); ress(address); rRole(f(userRole)); ationDate(new Date()); ifyBy(((User)sion().getAttribute(_SESSION)).getId()); UserService userService = new UserServiceImp(); if((user)){ try { direct(textPath() + "/jsp/?method=query"); } catch (IOException e) { tackTrace(); } }else{ try { uestDispatcher("").forward(req,resp); } catch (ServletException e) { tackTrace(); } catch (IOException e) { tackTrace(); } }}public void getUserById(HttpServletRequest req, HttpServletResponse resp,String url){ String id = ameter("uid"); if(!OrEmpty(id)){ UserService userService = new UserServiceImp(); User user = rById(id); ribute("user",user); try { uestDispatcher(url).forward(req,resp); } catch (ServletException e) { tackTrace(); } catch (IOException e) { tackTrace(); } }}效果
@Overridepublic User getUserById(Connection connection, String id) throws SQLException { User user = null; PreparedStatement pstm = null; ResultSet rs = null; if(connection != null && id != null){ String sql = "select u.*,me userRoleName from smbms_user u,smbms_role r where = ? "; Object[] params = {id}; rs = e(connection, sql, params, rs,pstm); if(()){ user = new User(); (("id")); rCode(ing("userCode")); rName(ing("userName")); rPassword(ing("userPassword")); der(("gender")); thday(estamp("birthday")); ne(ing("phone")); ress(ing("address")); rRole(("userRole")); rRoleName(ing("userRoleName")); atedBy(("createdBy")); ationDate(estamp("creationDate")); ifyBy(("modifyBy")); ifyDate(estamp("modifyDate")); } (connection,pstm,null); } return user;}service层public User getUserById(String id);public User getUserById(String id) { User user = null; Connection connection = null; connection = nection(); if(connection != null){ try { user = rById(connection, id); } catch (SQLException e) { tackTrace(); } } (connection,null,null); return user;}servlet层
public void getUserById(HttpServletRequest req, HttpServletResponse resp,String url){ String id = ameter("uid"); if(!OrEmpty(id)){ UserService userService = new UserServiceImp(); User user = rById(id); ribute("user",user); try { uestDispatcher(url).forward(req,resp); } catch (ServletException e) { tackTrace(); } catch (IOException e) { tackTrace(); } }}修改密码修改密码同样也是需要来两个函数来实现dao层public boolean updatePwd(Connection connection,int id,String pwd) throws SQLException;
public boolean updatePwd(Connection connection, int id, String pwd) throws SQLException { boolean flag = false; PreparedStatement pstm = null; int execute = 0; if (connection != null) { String sql = "update smbms_user set userPassword = ? where id = ? "; Object[] params = {pwd,id}; execute = e(connection, sql, params, pstm); if (execute > 0) { flag = true; } (connection,pstm,null); } return flag;}service层public boolean updatePwd(int id,String pwd);public boolean updatePwd(int id, String pwd) { Connection connection = null; boolean flag = false; try { connection = nection(); flag = Pwd(connection,id,pwd); } catch (SQLException e) { tackTrace(); }finally{ (connection,null,null); } return flag;}servlet层
rCode(ing("userCode")); rName(ing("userName")); rPassword(ing("userPassword")); der(("gender")); thday(estamp("birthday")); ne(ing("phone")); ress(ing("address")); rRole(("userRole")); atedBy(("createdBy")); ationDate(estamp("creationDate")); ifyBy(("modifyBy")); ifyDate(estamp("modifyDate")); } (connection,pstm,rs); } return user; } public User getLoginUser(Connection connection, String userCode) throws SQLException { ResultSet rs = null; User user = null; PreparedStatement pstm = null; if(connection != null) { String sql = "select * from smbms_user where userCode = ?"; Object[] params = {userCode}; rs = e(connection, sql, params, rs, pstm); if (()) { user = new User(); (("id")); rCode(ing("userCode")); rName(ing("userName")); rPassword(ing("userPassword")); der(("gender")); thday(estamp("birthday")); ne(ing("phone")); ress(ing("address")); rRole(("userRole")); atedBy(("createdBy")); ationDate(estamp("creationDate")); ifyBy(("modifyBy")); ifyDate(estamp("modifyDate")); } (connection,pstm,rs); } return user; } public boolean updatePwd(Connection connection, int id, String pwd) throws SQLException { boolean flag = false; PreparedStatement pstm = null; int execute = 0; if (connection != null) { String sql = "update smbms_user set userPassword = ? where id = ? "; Object[] params = {pwd,id}; execute = e(connection, sql, params, pstm); if (execute > 0) { flag = true; } (connection,pstm,null); } return flag; }
atedBy(("createdBy")); ationDate(estamp("creationDate")); ifyBy(("modifyBy")); ifyDate(estamp("modifyDate")); (user); } (connection,pstm,rs); } return userList; } @Override public boolean add(Connection connection,User user) throws SQLException { boolean flag = false; PreparedStatement pstm = null; int execute = 0; if(connection != null){ n("add start"); String sql = "insert into smbms_user(userCode,userName,userPassword,gender,birthday,phone,address,userRole,creationDate,createdBy) " + "values(?,?,?,?,?,?,?,?,?,?)"; n("1.1"); Object[] params = {rCode(),rName(),rPassword(),der(), thday(), ne(),ress(),rRole(),ationDate(),atedBy()}; n(1.2); execute = e(connection,sql,params,pstm); n(execute); if(execute > 0){ flag = true; } } (connection,pstm,null); n("Dao层: " + flag); return flag; } @Override public boolean modify(Connection connection, User user) throws SQLException { boolean flag = false; PreparedStatement pstm = null; if(connection != null){ String sql = "update smbms_user as s set me=?,=?," + "ay=?,=?,s=?,le=? where =? "; Object[] params = {rName(),der(),thday(),ne(), ress(),rRole(),()}; int execute = e(connection, sql, params, pstm); if(execute > 0){ flag = true; } (connection,pstm,null); } return flag; } @Override public User getUserById(Connection connection, String id) throws SQLException { User user = null; PreparedStatement pstm = null; ResultSet rs = null; if(connection != null && id != null){ String sql = "select u.*,me userRoleName from smbms_user u,smbms_role r where = ? "; Object[] params = {id}; rs = e(connection, sql, params, rs,pstm); if(()){ user = new User(); (("id"));
版权声明:本文标题:smbms(超市管理系统)源码+分析 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1708214075h516908.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论