javaweb农村管理系统之村民信息管理网站ssm和springboot框架mysql数据库idea开发

实体描述:

管理员实体:说明、管理员信息、用户名、密码

乡村建设实体:说明、乡村建设信息、日期、 备注、是否删除

村镇实体:说明、 名称 、是否删除

公告实体:说明、公告、日期、 备注、是否删除

 

村务实体:说明、村务、日期、村民ID、 备注、是否删除

选举结果实体:说明、选举结果、日期、村民ID、 备注、是否删除

土地实体:说明、土地、日期、村民ID、面积、备注、是否删除

公告实体:说明、公告信息、 日期、 备注、是否删除

村民实体:说明、村民信息、编号、姓名、性别、年龄、电话、地址、职务、身份证、日期、登录名、密码、是否删除、村镇

 

package com.action;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import com.dao.DB;
import com.orm.Chunzhen;
import com.orm.Chunzhen;
import com.orm.TAdmin; 
import com.util.chunmingService;
public class chunzhen_servlet extends HttpServlet
{
	public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException 
	{
        String type=req.getParameter("type");
		
		if(type.endsWith("chunzhenMana"))
		{
			chunzhenMana(req, res);
		}
		if(type.endsWith("chunzhenAdd"))
		{
			chunzhenAdd(req, res);
		}
		if(type.endsWith("chunzhenDel"))
		{
			chunzhenDel(req, res);
		}
		if(type.endsWith("chunzhenEdit"))
		{
			chunzhenEdit(req, res);
		}
		 	
	}
	
	
	 
		
	public void chunzhenAdd(HttpServletRequest req,HttpServletResponse res)
	{
		
		String chunzhenName=req.getParameter("chunzhenName");
		 	String del="no";
		
	
			String sql="insert into t_chunzhen values(?,?,?)";
			Object[] params={null,chunzhenName,del};
			DB mydb=new DB();
			mydb.doPstm(sql, params);
			mydb.closed();
			
			req.setAttribute("message", "操作成功");
			req.setAttribute("path", "chunzhen?type=chunzhenMana");
			
	        String targetURL = "/common/success.jsp";
			dispatch(targetURL, req, res);
		
	}
	
	public void chunzhenDel(HttpServletRequest req,HttpServletResponse res)
	{
		String sql="update t_chunzhen set del='yes' where chunzhenId="+Integer.parseInt(req.getParameter("chunzhenId"));
		Object[] params={};
		DB mydb=new DB();
		mydb.doPstm(sql, params);
		mydb.closed();
		
		req.setAttribute("message", "操作成功");
		req.setAttribute("path", "chunzhen?type=chunzhenMana");
		
        String targetURL = "/common/success.jsp";
		dispatch(targetURL, req, res);
	}

	public void chunzhenMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
	{
		String page1=req.getParameter("page");
		if(page1==null){
			page1="1";
		}
		//分页设置
		int EVERYPAGENUM=10;//每页条数
		int page=Integer.parseInt(page1);   //传递过来的当前页
		int cou = 1;//得到信息总数	
		int pagecount=1;  //总页数
		String sql1="select count(*) as cou from t_chunzhen where del='no'";
		Object[] params1={};
		DB mydb1=new DB();
		try
		{
			mydb1.doPstm(sql1, params1);
			ResultSet rs=mydb1.getRs();
			while(rs.next())
			{
			cou= rs.getInt("cou");
			}
			rs.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		mydb1.closed();
		
		
		
		if (cou % EVERYPAGENUM == 0) {
			pagecount= cou / EVERYPAGENUM;
        } else {
        	pagecount=cou / EVERYPAGENUM + 1;
        }	
		
		
		
		
		
		
		req.setAttribute("EVERYPAGENUM", EVERYPAGENUM);	
		req.setAttribute("page", page);
		req.setAttribute("cou", cou);
		req.setAttribute("pagecount", pagecount);
		
		List chunzhenList=new ArrayList();
		String sql="select * from t_chunzhen where del='no' order by chunzhenId desc";
		Object[] params={};
		DB mydb=new DB();
		try
		{
			mydb.doPstm(sql, params);
			ResultSet rs=mydb.getRs();
			 for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
	                rs.next();
	            }
	            for (int t = 0; t < EVERYPAGENUM; t++) {
	                if (rs.next()) {
				Chunzhen chunzhen=new Chunzhen();
				
				chunzhen.setChunzhenId(rs.getInt("chunzhenId"));
				chunzhen.setChunzhenName(rs.getString("chunzhenName"));
			 		
				chunzhenList.add(chunzhen);
	                } else {
	                    break; //减少空循环的时间
	                }
	            }
			rs.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		mydb.closed();
		
		req.setAttribute("chunzhenList", chunzhenList);
		req.getRequestDispatcher("admin/chunzhen/chunzhenMana.jsp").forward(req, res);
	}
	
	public void chunzhenEdit(HttpServletRequest req,HttpServletResponse res)
	{
		String chunzhenName=req.getParameter("chunzhenName");
		 	
		
		String sql="update t_chunzhen set chunzhenName=?  where chunzhenId="+Integer.parseInt(req.getParameter("chunzhenId"));
		Object[] params={chunzhenName};
		DB mydb=new DB();
		mydb.doPstm(sql, params);
		mydb.closed();
		req.setAttribute("message", "操作成功");
		req.setAttribute("path", "chunzhen?type=chunzhenMana");
        String targetURL = "/common/success.jsp";
		dispatch(targetURL, req, res);
		
		
	}
	
	
	
	public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) 
	{
		RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
		try 
		{
		    dispatch.forward(request, response);
		    return;
		} 
		catch (ServletException e) 
		{
                    e.printStackTrace();
		} 
		catch (IOException e) 
		{
			
		    e.printStackTrace();
		}
	}
	public void init(ServletConfig config) throws ServletException 
	{
		super.init(config);
	}
	
	public void destroy() 
	{
		
	}
}

 

猜你喜欢

转载自blog.csdn.net/a779289061/article/details/113742565