当前位置 : 主页 > 编程语言 > c++ >

java开发过程的测试类的作用

来源:互联网 收集:自由互联 发布时间:2021-06-30
UserDaoImpl.java package dao.impl;import java.util.List;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import org.apache.catalina.User;import bean.UserInfo;import bean.Users;import dao.IUserDao;import tool
UserDaoImpl.java
package dao.impl;
import java.util.List;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.apache.catalina.User;

import bean.UserInfo;
import bean.Users;
import dao.IUserDao;
import tools.DBTools;

public class UserDaoImpl implements IUserDao{

	@Override
	public Users getUserByNameAndPwd(String name, String pwd) {
		String sql="select users.name as users_name,users.pwd as users_pwd,users.id as users_id, users.roleid as users_roleid,roles.id as roles_id,roles.name as roles_name from users,roles where users.name=? and users.pwd=? and users.roleid=roles.id";
		List plist=new ArrayList(); plist.add(name); plist.add(pwd); return DBTools.getObject(Users.class, sql, plist); } @Override public List
   
     getUserPage(int pageIndex, int pageSize) { String sql="select * from (select roles.id as r_id,users.id as users_id,users.name as users_name,users.pwd as users_pwd,users.roleid as users_roleid,roles.id as roles_id,roles.name as roles_name from users,roles where users.roleid=roles.id) where r_id>? and r_id
     plist=new ArrayList
    (); plist.add((pageIndex-1)*pageSize); plist.add(pageIndex*pageSize+1); return DBTools.getListBySql(Users.class, sql, plist); } @Override public boolean getUserName(String name) { String sql="select * from users where name=?"; List list=new ArrayList(); list.add(name); ResultSet rs=DBTools.getResultSet(sql, list); try { if (rs.next()) return true; } catch (SQLException e) { e.printStackTrace(); }finally{ DBTools.close(); } return false; } @Override public int deleteUsers(int id) { return DBTools.deleteObject(Users.class, id); } } 
       
        test.java
        
package test;

import dao.IUserDao;
import dao.impl.UserDaoImpl;

public class test {
	public static void main(String[] args) {
		IUserDao dao=new UserDaoImpl();
		//dao.getUserName("qqq");
		//dao.getUserPage(1, 10);
		dao.deleteUsers(33);
	}
}
网友评论