大二下开学课堂测试之新闻发布系统
一:整体的页面要求
(1)通过浏览器查看,能适应常用分辨率;
(2)布局合理、结构清晰、页面完整;
(3)网站页面整体风格统一;
(4)首页为用户登录页面,不同角色用户登录后,进入相应的功能页,要求密码在数据库中加密;
(5)新闻撰稿人功能页:在线撰写与修改稿件、查看已写稿件及修改意见;
(6)普通用户功能页:浏览相应栏目新闻、用户评论新闻(可匿名)、浏览其他用户评论;
(7)新闻栏目管理员功能页:浏览与管理本栏目待发与已发新闻;
(8)系统管理功能页:用户注册、用户权限管理、新闻栏目管理;
(9)对每页中的查询结果推荐采用分页显示。
二:功能要求
(1)在线撰写新闻稿件:新闻撰稿人在线撰写新闻,选择栏目,正式提交;
(2)查看修改意见:新闻撰稿人查看新闻栏目管理员提出的修改意见;
(3)修改新闻稿件:新闻撰稿人根据修改意见可以对新闻进行修改;
(4)查询已经撰写的新闻:新闻撰稿人可以查看自己已经撰写的新闻;
(5)浏览新闻:普通用户可以浏览栏目的新闻(按照时间倒排);
(6)发表评论回复:普通用户可以对新闻进行发表评论,可选择匿名回复;
(7)按照一定条件查询新闻:栏目管理员可以按照时间段,新闻关键字等条件进行查询;
(8)管理待发与已发新闻:新闻栏目管理员可以批准新闻发布、删除不合适新闻、给出撰稿人修改意见、对已发的过时新闻进行删除;
(9)管理新闻评论回复:新闻栏目管理员可以查看、删除、禁止新闻的回复;
(10)管理新闻栏目:新开新闻栏目、删除新闻栏目、合并新闻栏目、更改新闻栏目的基本信息;
(11)用户管理:管理员可以查询用户、批准新用户、暂停用户、为用户赋予角色,普通用户可以修改用户资料。
根据图片中所示的新闻发布流程分析系统所需要的角色以及其拥有的权限以及功能。
浏览完题目之后,在本题中的核心就是角色功能之间的联系以及逻辑关系。目前对于这方面还是很生疏,没法短时间内完成梳理所以我打算从用户角色的单个功能开始做,
设计数据库这方面,我从简单的开始做没有涉及到角色功能权限这方面就仅仅做了两个表一个是普通用户的表,另一个是新闻撰稿人的数据表里面是其对应的账号密码以及其他数据。
首先就是用户角色登录,这方面来说比较简单,首先现获取表单数据然后传入后方在与数据库进行链接在用sql语句进行比对是否正确,然后返回布尔值即可登录。
注册这方面以及管理员添加用户角色参考增删改查中的增加数据来写。这些以前都写过比较简单。
新闻撰稿人这方面注册以及添加角色与普通用户类似参考做即可。然后 根据功能面要求的完成一系列增删改查。
对于系统管理员的简单功能就是可以全面的预览的其他用户角色的信息数据并进行增删改查。以下是代码部分。
点击查看代码
<%@ page import="Bean.*" %>
<%@ page import="java.util.List" %>
<%@ page import="Dao.Dao1" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新闻稿件管理</title>
<style type="text/css">
*{font-style: "微软雅黑"}
#table th{background-color: #fff7d5;border: 1px solid black;}
#table td{background-color: #cfecfc;border: 1px solid black;padding: 15px;color: #000;}
#table a{text-decoration: none;font-weight: bold;}
#table a:hover {text-decoration: underline;}
</style>
</head>
<body>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<form name="form1" method="get" action="houtai.jsp" class="form-login" onsubmit="return check()">
<h2 style="text-align: center;">新闻稿件系统</h2>
<br>
<div style="text-align: center;">
<tr>
<td>身份:
<select name="profession">
<option value="1">系统管理员</option>
<option value="2"selected>普通用户</option>
<option value="3" >新闻撰稿人</option>
<option value="4" >栏目管理员</option>
</select>
</td>
</tr>
<div style="text-align: center;">
<tr><td>
用户名:<input type="text" id="uid" name="uid"><br></tr>
<tr><td>
密码:<input pattern="[a-zA-Z0-9]{6,12}" type="password" id="password" name="password"></td> </tr>
</div>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="登录"></div></td> </tr>
<input type="button" value="普通用户注册" onclick="location.href='zhuce.jsp'" />
<input type="button" value="新闻撰稿人注册" onclick="location.href='xzhuce.jsp'" />
</div>
</form>
</div>
<script type="text/javascript">
function check() {
var username=document.form1.username.value;
var password = document.form1.password.value;
//非空
if(username == '') {
alert('用户姓名为空');
return false;
}
if(password == '') {
alert('密码为空');
return false;
}
</script>
</body>
</html><details>
<summary>点击查看代码</summary>
<%@ page import="java.sql.*" contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="Dao.Dao1" %>
switch(profession) {
case "1":
if(util.judgeguanli(uid, mima)){
response.sendRedirect("guanli.jsp");break;
}
else {
out.print("<script language='javaScript'> alert('密码错误');</script>");
response.sendRedirect("index.jsp");
}
break;
case "2": if(util.judgecommon(uid, mima)){
response.sendRedirect("common.jsp");break;
}
else {
out.print("<script language='javaScript'> alert('密码错误');</script>");
response.sendRedirect("index.jsp");
}break;
case "3": if(util.judgewrite(uid, mima)){
response.sendRedirect("write.jsp");break;
}
else {
out.print("<script language='javaScript'> alert('密码错误');</script>");
response.sendRedirect("index.jsp");
}break;
case "4": if(util.judgelguanli(uid, mima)){
response.sendRedirect("lguanli.jsp");break;
}
else {
out.print("<script language='javaScript'> alert('密码错误');</script>");
response.sendRedirect("index.jsp");
}break;
}
%>
```点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<style>
<body background="背景.jpg">
body{
background-size:100%;
}
</style>
<table align="center" border="3" width="500">
<tr >
<td colspan="2">
<input type="button" onclick="window.location.href='swriter.jsp';" value="查询新闻"/>
<input type="button" onclick="window.location.href='delete.jsp';" value="删除新闻"/>
<input type="button" onclick="window.location.href='Servlet?method=slist';" value="浏览新闻"/>
<input type="button" onclick="window.location.href='修改.jsp';" value="修改信息信息"/>
</td>
</tr>
</table>
</body>
</html><details>
<summary>点击查看代码</summary>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>按新闻撰稿人查询</title>
</head>
<body>
<%
Object message = request.getAttribute("message");
if(message!=null && !"".equals(message)){
%>
<script type="text/javascript">
alert("<%=request.getAttribute("message")%>");
</script>
<%} %>
<div align="center">
<h1>按照新闻撰稿人查询</h1>
<a href="common.jsp">返回主页</a>
<form name="form1" action="Servlet?method=swrite" method="post" onsubmit="return check()">
<div class="a">
新闻撰稿人名称<input type="text" id="name" name="name" />
</div>
<div class="a">
<button type="submit" class="b">查询</button>
</div>
</form>
</div>
<script type="text/javascript">
function check() {
var name=document.form1.name.value;
var type = document.form1.type.value;
var address = document.form1.address.value;
var year = document.form1.year.value;
//非空
if(name == ''&&type==''&&address==''&&year=='') {
alert('请输入!');
return false;
}
}
</script>
</body>
</html><details>
<summary>点击查看代码</summary>
package servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Bean.bean2;
import Bean.bean1;
import service.Service;
@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Service service = new Service();
/**
- 方法选择
*/
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String method = req.getParameter("method");
if ("add".equals(method)) {
add(req, resp);
}else if ("add1".equals(method)) {
add1(req, resp);
}else if ("add2".equals(method)) {
add2(req, resp);
}
else if ("addgaojian".equals(method)) {
addgaojian(req, resp);
}else if ("del".equals(method)) {
del(req, resp);
} else if ("update".equals(method)) {
update(req, resp);
} else if ("swrite".equals(method)) {
swrite(req, resp);
}
else if ("slist".equals(method)) {
slist(req, resp);
}
else if ("sbiaoti".equals(method)) {
sbiaoti(req, resp);
}
else if ("getbyname".equals(method)) {
getByName(req, resp);
}
else if ("clist".equals(method)) {
clist(req, resp);
}else if ("jlist".equals(method)) {
jlist(req, resp);
}else if ("gsearch".equals(method)) {
gsearch(req, resp);
}else if ("gsearch1".equals(method)) {
gsearch1(req, resp);
}else if ("getbyname02".equals(method)) {
getByName02(req, resp);
}
else if("search1".equals(method))
{
search1(req,resp);
}
}
/**
- 添加
- @param req顾客信息注册
- @param resp
- @throws IOException
- @throws ServletException
*/
private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
req.setCharacterEncoding("utf-8");
//获取数据
String name = req.getParameter("name");
String uid = req.getParameter("uid");
String password = req.getParameter("password");
bean1 people = new bean1(name,uid,password);
/跳转到添加信息界面/
if(service.add(people)) {
req.setAttribute("message", "注册成功");
//req.getRequestDispatcher("Servlet?method=list").forward(req,resp);//在这里直接跳转到下面那个list来输出所有信息
} else {
req.setAttribute("message", "注册失败,请重新录入");
req.getRequestDispatcher("zhuce.jsp").forward(req,resp);
}
}
private void addgaojian(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
req.setCharacterEncoding("utf-8");
//获取数据
String name = req.getParameter("name");
String gaojian = req.getParameter("gaojian");
String biaoti = req.getParameter("biaoti");
bean2 people = new bean2(name,gaojian,biaoti);
/跳转到添加信息界面/
if(service.addgaojian(people)) {
req.setAttribute("message", "保存成功");
//req.getRequestDispatcher("Servlet?method=list").forward(req,resp);//在这里直接跳转到下面那个list来输出所有信息
} else {
req.setAttribute("message", "保存失败,请重新录入");
req.getRequestDispatcher("write.jsp").forward(req,resp);
}
}
//房屋信息录入
private void add1(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
req.setCharacterEncoding("utf-8");
//获取数据
String name = req.getParameter("name");
String uid = req.getParameter("uid");
String password = req.getParameter("password");
bean2 people = new bean2(name,uid,password);
/跳转到添加信息界面/
if(service.add1(people)) {
req.setAttribute("message", "注册成功");
//req.getRequestDispatcher("Servlet?method=list").forward(req,resp);//在这里直接跳转到下面那个list来输出所有信息
} else {
req.setAttribute("message", "注册失败,请重新录入");
req.getRequestDispatcher("xzhuce.jsp").forward(req,resp);
}
}
private void add2(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
req.setCharacterEncoding("utf-8");
//获取数据
String name = req.getParameter("name");
String gonghao = req.getParameter("gonghao");
String password = req.getParameter("password");
String address = req.getParameter("address");
String phone = req.getParameter("phone");
Bean2 people = new Bean2(name,gonghao,password,address,phone);
/跳转到添加信息界面/
if(service.add2(people)) {
req.setAttribute("message", "注册成功");
//req.getRequestDispatcher("Servlet?method=list").forward(req,resp);//在这里直接跳转到下面那个list来输出所有信息
} else {
req.setAttribute("message", "注册失败,请重新录入");
req.getRequestDispatcher("addjingji.jsp").forward(req,resp);
}
}
/**
- 全部
- 房产信息的浏览
/
private void slist(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
Listpeoples = service.slist(); *
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("list.jsp").forward(req,resp);
}
/ - 全部
- 顾客信息的浏览
/
private void clist(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
Listpeoples = service.clist(); *
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("clist.jsp").forward(req,resp);
}
/ - 全部
- 经纪人信息的浏览
*/
private void jlist(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
Listpeoples = service.jlist();
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("jlist.jsp").forward(req,resp);
}
/**
- 通过名字查找
- 跳转至删除
- 然后跳转到细节1进行确定删除操作
*/
private void getByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
Bean1 people =service.getByName(name);
if(people == null) {
req.setAttribute("message", "查无此人!");
req.getRequestDispatcher("del.jsp").forward(req,resp);
} else {
req.setAttribute("people", people);
req.getRequestDispatcher("detail.jsp").forward(req,resp);
}
}
/**
- 删除
- 从细节1里面跳转过来的
*/
private void del(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
service.del(name);
req.setAttribute("message", "删除成功!");
req.getRequestDispatcher("del.jsp").forward(req,resp);
}
/用于修改的时候查询姓名然后跳转到细节2 页面/
private String getByName02(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
Bean1 people =service.getByName(name);
if(people == null) {
req.setAttribute("message", "查无此人!");
req.getRequestDispatcher("updata.jsp").forward(req,resp);
} else {
req.setAttribute("people", people);
req.getRequestDispatcher("detail2.jsp").forward(req,resp);
}
return name;
}
/**
- 修改
- @param req
- @param resp
- @throws IOException
- @throws ServletException
/
private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
String idc = req.getParameter("idc");
String min_zu = req.getParameter("min_zu");
String jiao_yu = req.getParameter("jiao_yu");
String sex = req.getParameter("sex");
/Bean1 people = new Bean1(name,idc,min_zu,jiao_yu,sex);
if(name=="")
req.setAttribute("message", "姓名为空");
if(service.update(people))
req.setAttribute("message", "修改成功");
req.getRequestDispatcher("Servlet?method=list").forward(req,resp);*/
}
/**
- 查找房产
- @param req
*详细的显示信息
*/
private void swrite(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
List
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("list.jsp").forward(req,resp);
}
private void sbiaoti(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String biaoti = req.getParameter("biaoti");
List
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("list2.jsp").forward(req,resp);
}
/**从查询界面来然后可以转到不是那么细节的显示信息界面list
- 然后在list中点击姓名在跳转到上面那个search那个 房产信息
- 转到list2里面这是详细的显示所有信息**/
private void search1(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String houseid = req.getParameter("houseid");
String type = req.getParameter("type");
String address = req.getParameter("address");
String area = req.getParameter("area");
List
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("flist.jsp").forward(req,resp);
}
/**
- 查找房产
- @param req
*详细的显示信息
*/
private void gsearch(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
String id = req.getParameter("id");
String password = req.getParameter("password");
String sex = req.getParameter("sex");
List
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("glist2.jsp").forward(req,resp);
}
/**从查询界面来然后可以转到不是那么细节的显示信息界面list
- 然后在list中点击姓名在跳转到上面那个search那个 房产信息
- 转到list2里面这是详细的显示所有信息**/
private void gsearch1(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
req.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
String id = req.getParameter("id");
String password = req.getParameter("password");
String sex = req.getParameter("sex");
List
req.setAttribute("peoples", peoples);
req.getRequestDispatcher("glist.jsp").forward(req,resp);
}
}
点击查看代码
package service;
import java.util.List;
import Dao.Dao1;
import Bean.bean1;
import Bean.bean2;
/**
* Service
* 服务层
* @author Hu
*
*/
public class Service {
Dao1 cDao = new Dao1();
/**
* 添加
* @param course
* @return
*/
public boolean add(bean1 people) {
boolean f = false;
if(!cDao.leibie(people.getname())) {
cDao.add(people);
f = true;
}
return f;
}
public boolean addgaojian(bean2 people) {
boolean f ;
cDao.addgaojian(people);
f = true;
return f;
}
//房产信息添加
public boolean add1(bean2 people) {
boolean f = false;
if(!cDao.leibie(people.getname())) {
cDao.add1(people);
f = true;
}
return f;
}
//经纪人信息添加
public boolean add2(Bean2 people) {
boolean f = false;
if(!cDao.leibie2(people.getname())) {
cDao.add2(people);
f = true;
}
return f;
}
/**
* 删除
*/
public void del(String name) {
cDao.delete(name);
}
/**
* 修改
* @return
*/
public boolean update(Bean1 people) {
return cDao.update(people);
}
/**
* 通过ID得到一个Course
public Bean1 getById(int id) {
return cDao.getById(id);
}* @return
*/
/**
* 通过Name得到一个Course
* @return
*/
public Bean1 getByName(String name) {
return cDao.getByName(name);
}
/**
* 查找房产
* @return
*/
public List<bean2> swrite(String name) {
return cDao.swrite(name);
}
public List<bean2> sbiaoti(String biaoti) {
return cDao.sbiaoti(biaoti);
}
/**
* 查找顾客
* @return
*/
public List<Bean1> gsearch(String name, String id, String password,String sex) {
return cDao.gsearch(name,id,password,sex);
}
/**
* 全部数据
* 房产信息的浏览
*/
public List<bean2> slist() {
return cDao.slist();
}
/**
* 全部数据
* 房产信息的浏览
*/
public List<bean1> clist() {
return cDao.clist();
}
/**
* 全部数据
* 经纪人信息的浏览
*/
public List<Bean2> jlist() {
return cDao.jlist();
}
}<details>
<summary>点击查看代码</summary>
package Dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import Bean.bean1;
import Bean.bean2;
import Bean.bean3;
import util.DBUtil;
/**
- 课程Dao
- Dao层操作数据
- @author Hu
*/
public class Dao1 {
private ResultSet rs;
private Statement state;
private Connection conn;
/**
- 添加注册
- @param course
- @return顾客信息
*/
public boolean add(bean1 people) {
String sql = "insert into common values('" + people.getname() + "','" + people.getuid() + "','" + people.getpassword() + "')";
//创建数据库链接
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0;
try {
state = conn.createStatement();
a = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
/**
- 添加注册
- @param course
- @return房产信息
*/
public boolean add1(bean2 people) {
String sql = "insert into zuojia(name,uid,password) values('" + people.getname() + "','" + people.getuid() + "','" + people.getpassword() + "')";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0;
try {
state = conn.createStatement();
a = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
public boolean addgaojian(bean2 people) {
String sql = "insert into zuojia(name,biaoti,gaojian) values('" + people.getname() + "','" + people.getbiaoti() + "','" + people.getgaojian() + "')";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0;
try {
state = conn.createStatement();
a = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
/**
- 添加注册
- @param course
- @return经纪人信息
*/
public boolean add2(Bean2 people) {
String sql = "insert into agent values('" + people.getname() + "','" + people.getgonghao() + "','" + people.getpassword() + "','" + people.getaddress() + "','" + people.getphone() + "')";
//创建数据库链
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0;
try {
state = conn.createStatement();
a = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
/**
- 删除
- @param id
- @return
*/
public boolean delete (String name) {
boolean f = false;
String sql = "delete from zhufang where name='" + name + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
int a = 0;
try {
state = conn.createStatement();
a = state.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
/**
- 修改
- @param name
- @param pass
/
/* - @param people
- @return
*/
public boolean update(Bean1 people) {
String sql = "update zhufang set idc='" + people.getIdc() + "', sex='" + people.getSex() + "', min_zu='" + people.getMin_zu() + "', jiao_yu='" + people.getJiao_yu()
- "' where name='" + people.getname() + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
boolean f = false;
int a = 0;
try {
state = conn.createStatement();
a = state.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(state, conn);
}
if (a > 0) {
f = true;
}
return f;
}
/**
- 验证课程名称是否唯一
- true --- 不唯一
- @param name
- @return
*/
public boolean leibie(String uid) {
boolean flag = false;
String sql = "select uid from common where uid = '" + uid + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
flag = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return flag;
}
/**
- 验证房屋信息是否唯一
- @param name
- @return
*/
public boolean leibie1(String uid) {
boolean flag = false;
String sql = "select uid from zuojia where uid = '" + uid + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
flag = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return flag;
}
public boolean leibie2(String name) {
boolean flag = false;
String sql = "select name from agent where name = '" + name + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
flag = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return flag;
}
/**
- 通过ID得到课程信息
- @param id
- @return
public Bean1 getById(int id) {
String sql = "select * from zhufang where id ='" + id + "'";
Connection conn = DBUtil1.getConn();
Statement state = null;
ResultSet rs = null;
Bean1 people = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
String name = rs.getString("name");
String min_zu = rs.getString("min_zu");
String jiao_yu = rs.getString("jiao_yu");
String idc = rs.getString("idc");
String sex = rs.getString("sex");
int ida = rs.getInt("id");
people = new Bean1(ida,name,idc,min_zu,jiao_yu,sex);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil1.close(rs, state, conn);
}
return people;
}**/
/**
- 通过name得到Course
- @param name
- @return
*/
public Bean1 getByName(String name) {
String sql = "select * from zhufang where name ='" + name + "'";
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
Bean1 people = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
String name1 = rs.getString("name");
String zhu_fang_lei_bie = rs.getString("zhu_fang_lei_bie");
String hu_bie = rs.getString("hu_bie");
String idc = rs.getString("idc");
String jiao_yu = rs.getString("jiao_yu");
String min_zu = rs.getString("min_zu");
String S = rs.getString("S");
String N = rs.getString("N");
String sex = rs.getString("sex");
people = new Bean1(hu_bie,zhu_fang_lei_bie,name1,idc,min_zu,jiao_yu,sex,S,N);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return people;
}
/**
- 查找部门人员信息
- @param name
- @param teacher
- @param classroom
- @return
*/
public Listswrite(String name) {
String sql = "select * from zuojia where name ='" + name + "'";
List
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
bean2 bean = null;
while (rs.next()) {
String name2 = rs.getString("name");
String uid = rs.getString("uid");
String type = rs.getString("type");
String biaoti = rs.getString("biaoti");
bean = new bean2( name2, uid, type,biaoti);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return list;
}
public List
String sql = "select * from zuojia where biaoti ='" + biaoti + "'";
List
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
bean2 bean = null;
while (rs.next()) {
String name2 = rs.getString("name");
String uid = rs.getString("uid");
String type = rs.getString("type");
String biaoti2 = rs.getString("biaoti");
String gaojian = rs.getString("gaojian");
String yijian = rs.getString("yijian");
bean = new bean2( name2, uid, type,biaoti2,gaojian,yijian);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return list;
}
public List
String sql = "select * from user where ";
if (name != "") {
sql += "name like '%" + name + "%'";
}
else if (id != "") {
sql += "id like '%" + id + "%'";
}
else if (password != "") {
sql += "password like '%" + password + "%'";
}
else if (sex != "") {
sql += "sex like '%" + sex + "%'";
}
else
{
}
List
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
Bean1 bean = null;
while (rs.next()) {
String name2 = rs.getString("name");
String id2 = rs.getString("id");
String password2 = rs.getString("password");
String sex2 = rs.getString("sex");
String idnum = rs.getString("idnum");
String phone = rs.getString("phone");
String address = rs.getString("address");
bean = new Bean1( name2, id2, password2, sex2, idnum, phone, address);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return list;
}
/**
- 全部数据房产
- @param name
- @param teacher
- @param classroom
- @return
*/
public Listslist() {
String sql = "select * from zuojia";
Listlist = new ArrayList<>();
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
bean2 bean = null;
while (rs.next()) {
String name = rs.getString("name");
String type = rs.getString("type");
String gaojian = rs.getString("gaojian");
String yijian = rs.getString("yijian");
String uid = rs.getString("uid");
String biaoti = rs.getString("biaoti");
bean = new bean2( name, uid, gaojian, type, yijian, biaoti);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return list;
}
/**
- 全部数据顾客
- @param name
- @param teacher
- @param classroom
- @return
*/
public Listclist() {
String sql = "select * from common";
Listlist = new ArrayList<>();
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
bean1 bean = null;
while (rs.next()) {
String name = rs.getString("name");
String uid = rs.getString("uid");
bean = new bean1( name, uid);
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return list;
}
/**
- 全部数据顾客
- @param name
- @param teacher
- @param classroom
- @return
*/
public Listjlist() {
String sql = "select * from agent";
Listlist = new ArrayList<>();
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
try {
state = conn.createStatement();
rs = state.executeQuery(sql);
Bean2 bean = null;
while (rs.next()) {
String name = rs.getString("name");
String gonghao = rs.getString("gonghao");
String password = rs.getString("password");
String address = rs.getString("address");
String phone = rs.getString("phone");
bean = new Bean2( name, gonghao, password, address,phone );
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return list;
}
//判断普通人
public boolean judgecommon(String name,String mima)
{
boolean flag=false;
try {
Connection conn = DBUtil.getConn();
Statement state = null ;
ResultSet rs = null;
state = conn.createStatement();
rs = state.executeQuery("select * from common");
while(rs.next())
{
if((name.equals(rs.getString("uid")))&& (mima.equals(rs.getString("password"))))
{
flag=true;
}
}
}
catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return flag;
}
//新闻撰稿人
public boolean judgewrite(String name,String mima)
{
boolean flag=false;
try {
Connection conn = DBUtil.getConn();
Statement state = null ;
ResultSet rs = null;
state = conn.createStatement();
rs = state.executeQuery("select * from zuojia");
while(rs.next())
{
if((name.equals(rs.getString("uid")))&& (mima.equals(rs.getString("password"))))
{
flag=true;
}
}
}
catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs, state, conn);
}
return flag;
}
//判断管理员登录信息是否正确judgeguanli()
public boolean judgeguanli(String name,String mima){
boolean flag=false;
if (("系统管理员".equals(name))&&("123456".equals(mima))){
flag = true;
}
return flag;
}
public boolean judgelguanli(String name,String mima){
boolean flag=false;
if (("栏目管理员".equals(name))&&("123456".equals(mima))){
flag = true;
}
return flag;
}
}
</details>