河北科技政策查询系统2

发布时间 2023-04-10 23:29:29作者: 云边上打盹

源码:

Bean.bean.java.

package Bean;

public class bean {

private String name;//政策名称
private String document;//政策文号
private String organ;//发文机构
private String type;//政策类型
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDocument() {
return document;
}
public void setDocument(String document) {
this.document = document;
}
public String getOrgan() {
return organ;
}
public void setOrgan(String organ) {
this.organ = organ;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}

}

Dao.dao.java.

package Dao;
import Bean.Menu;
import Bean.bean;
import Bean.policy;
import DBUtil.dbutil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class dao {

public List<bean> searchAll( ){
List<bean> list = new ArrayList<bean>();
try {
Connection conn = dbutil.getConn();
Statement state = null;
String sql="select * from policy";
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
System.out.println("搜索全部政策");
while(rs.next()){
bean lu = new bean();

lu.setId(rs.getString("id"));
lu.setType(rs.getString("type"));
lu.setOrgan(rs.getString("organ"));
lu.setPubdata(rs.getString("pubdata"));
lu.setName(rs.getString("name"));
list.add(lu);

}
rs.close();
pstmt.close();
conn.close();
}catch(SQLException e) {

System.out.println("发生错误");
e.printStackTrace();


}


return list;

}


public List<bean> search(String name,String document,String organ){
List<bean> list = new ArrayList<bean>();
try {
Connection conn = dbutil.getConn();
Statement state = null;

 

String sql = "select * from policy where name REGEXP '"+name+"' and document REGEXP '"+document+"' and organ REGEXP '"+organ+"'";

PreparedStatement pstmt = conn.prepareStatement(sql);

ResultSet rs = pstmt.executeQuery();
System.out.println("多项条件搜索运行中");
while(rs.next()){

bean lu = new bean();

lu.setId(rs.getString("id"));
lu.setType(rs.getString("type"));
lu.setOrgan(rs.getString("organ"));
lu.setPubdata(rs.getString("pubdata"));
lu.setName(rs.getString("name"));
list.add(lu);


}
rs.close();
pstmt.close();
conn.close();
}catch(SQLException e) {

System.out.println("发生错误");
e.printStackTrace();


}


return list;

}

public static bean getOne(String id){
bean lu = new bean();
try {
Connection conn = dbutil.getConn();
Statement state = null;
String sql="select * from policy where id=?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1,id);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){

lu.setId(rs.getString("id"));
lu.setType(rs.getString("type"));
lu.setCategory(rs.getString("category"));
lu.setOrgan(rs.getString("organ"));
lu.setPubdata(rs.getString("pubdata"));
lu.setName(rs.getString("name"));
lu.setDocument(rs.getString("document"));
lu.setRange(rs.getString("range"));
lu.setPerdata(rs.getString("perdata"));
lu.setViadata(rs.getString("viadata"));
lu.setText(rs.getString("text"));

}
rs.close();
pstmt.close();
conn.close();
}
catch(SQLException e) {

e.printStackTrace();
}
return lu;

}

}

DBUtil.dbulit.java.

package DBUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class dbutil {

public static Connection getConnection() throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/policy", "root", "lzz001525");
return con;

}


public static void close (PreparedStatement state, Connection conn) {
if (state != null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

public static void close (ResultSet rs, PreparedStatement state, Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

if (state != null) {
try {
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

}

test1.

<%@page import="DBUtil.dbutil"%>
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
int row=0;
int zongye=0;
String name = request.getParameter("name");
String document = request.getParameter("document");
String organ = request.getParameter("organ");
if (name == "" || name == null) {
name = "";
}
if (document == "" || document == null) {
document = "";
}
if (organ == "" || organ == null) {
organ = "";
}
String yema0 = request.getParameter("yema");
int yema = 0;
if (yema0 == "0"||yema0 == "" || yema0 == null) {
yema = 1;
} else {
yema = Integer.parseInt(yema0);
}
String shuliang0 = request.getParameter("shuliang");
int shuliang = 0;
if (shuliang0 == "" || shuliang0 == null) {
shuliang = 10;
} else {
shuliang = Integer.parseInt(shuliang0);
}
%>


<div id="app-header" align="center">
<img src="LOGO.png" style="height: 40px; margin-bottom: 7px"> <span
style="font-size: 27px; color: #1c4786; font-family: 黑体; font-weight: bold">&nbsp;科技政策查询系统</span>
</div>
<form action="test.jsp">
<div id="title" align="center">
政策名称:<input type="text" name="name" size="10" value="<%=name %>" /> 发文字号:<input
type="text" name="document" size="10" value="<%=document %>" /> 发文机构:<input type="text"
name="organ" size="10" value="<%=organ %>" />
<input type="submit" value="搜索" />
</div>
<div id="jieguo" style="float: left; width: 100%">
<table border="1" style="table-layout: fixed;" width="100%" align="center" vertical-align="middle" frame=void rules=none>
<tr
style="text-align: center; color: black; font-family: 宋体; font-size: 20px">
<td align="center" width=40%>政策名称</td>
<td align="center" width=30%>发文机构</td>
<td align="center" width=20%>颁发日期</td>
<td align="center" width=20%>政策分类</td>
<td align="center" width=20%>操作</td>
</tr>
<%
try {
Connection connection = dbutil.getConnection();
PreparedStatement preparedStatement = null;
ResultSet rs = null;
String sql = " select id , name , organ , pubdata , type from policy where name like ? and document like ? and organ like ? ";
preparedStatement = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
preparedStatement.setString(1, "%" + name + "%");
preparedStatement.setString(2, "%" + document + "%");
preparedStatement.setString(3, "%" + organ + "%");
rs = preparedStatement.executeQuery();
//out.write(""+(yema - 1));

rs.absolute((yema - 1) * shuliang);
for (int i = 0; i < shuliang; i++) {
if(!rs.next())
break;
%>
<tr>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis" align="center"><%=rs.getObject("name")%></td>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis" align="center"><%=rs.getObject("organ")%></td>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis" align="center"><%=rs.getObject("pubdata")%></td>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis" align="center"><%=rs.getObject("type")%></td>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis" align="center"><input type="button" value="查看"
onclick="location.href='test2.jsp?id=<%=rs.getObject("id")%>'" /></td>

</tr>
<%
}
rs.last();
row=rs.getRow();
if(row%shuliang==0)
zongye=row/shuliang;
else
zongye=row/shuliang+1;
//out.print(row);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
%>
</table>
</div>

<div id="app-header" align="center">
<%
String str1="<input type=\"button\" value=\"";
String str2="\" onclick=\"location.href='test.jsp?name="+name+"&document="+document+"&organ="+organ+"&yema=";
String str3="'\" />";
if(yema!=1)
out.print(str1+"<"+str2+(yema-1)+str3);
if(yema>3&&yema<zongye-3){
out.print(str1+"1"+str2+"1"+str3);
out.print("...");
out.print(str1+(yema-1)+str2+(yema-1)+str3);
out.print(str1+(yema)+str2+(yema)+str3);
out.print(str1+(yema+1)+str2+(yema+1)+str3);
out.print("...");
out.print(str1+zongye+str2+zongye+str3);
}
else if(yema<=3&&yema<zongye-3){
out.print(str1+"1"+str2+"1"+str3);
out.print(str1+"2"+str2+"2"+str3);
out.print(str1+"3"+str2+"3"+str3);
out.print(str1+"4"+str2+"4"+str3);
out.print("...");
out.print(str1+zongye+str2+zongye+str3);
}
else if(yema>3&&yema>=zongye-3){
out.print(str1+"1"+str2+"1"+str3);
out.print("...");
for(int i=yema-1;i<=zongye;i++){
out.print(str1+i+str2+i+str3);
}
}
else if(yema<=3&&yema>=zongye-3){
for(int i=1;i<=zongye;i++){
out.print(str1+i+str2+i+str3);
}
}
if(yema!=zongye)
out.print(str1+">"+str2+(yema+1)+str3);

out.print(" 共"+row+"条");
out.print(" 共"+zongye+"页");
out.print(" 到第<input type=\"text\" name=\"yema\" size=\"10\" value=\""+yema+"\" />页");
%>
<select name="shuliang"lay-ignore=""><option value="10" selected="">10 条/页</option><option value="20">20 条/页</option><option value="30">30 条/页</option><option value="40">40 条/页</option><option value="50">50 条/页</option><option value="60">60 条/页</option><option value="70">70 条/页</option><option value="80">80 条/页</option><option value="90">90 条/页</option></select>
<%

out.print("<input type=\"submit\" value=\"确定\" /> ");

 


%>

</div>
</form>
<div class="layui-col-md12 layui-col-sm12 layui-col-xs12">
<!--background: #393E46;-->
<!--<div class="layui-row">-->

</div>
<!--</div>-->
</div>
</body>
</html>

test2.

<%@page import="DBUtil.dbutil"%>
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String id = request.getParameter("id");
Connection connection = DBUtil.dbutil.getConnection();
PreparedStatement preparedStatement = null;
ResultSet rs = null;
String sql = " select name,text from policy where id=? ";
preparedStatement = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
preparedStatement.setString(1, id);
rs = preparedStatement.executeQuery();
rs.next();
out.print("<h1>");
out.print(rs.getObject("name"));
out.print("</h1>");
out.print(rs.getObject("text"));
%>
</body>
</html>