怎么做(我直接敲代码,有解释)===新闻发布系统(2)

2020-05-11 阴天

  我在上一随笔,菜鸡的介绍了我大概需要完成什么,什么技术,什么功能

  所以在这章开始我就直接敲代码,在敲代码的情况下,我会详细介绍功能(我理解的)

我可能会出现错误,希望大佬们看到问题,可以指点我,谢谢:

项目结构

    ├── README.md 
├── config -- 项目资源文件
| ├── news_table.sql 项目数据库创建和表创建的SQL语句
| ├── c3p0-config.xml c3p0连接池配置文件
| ├── dao.properties
| └── service.properties
└── src
| └── com
| └── jsj
| ├── servlet web
| ├── dao -- dao持久层
| ├── entity -- 实体类
| ├── factory -- 工厂类
| ├── filter -- 过滤器
| ├── utils -- 工具类
| └── service -- service业务层
└── web
└── WEB-INF
| ├── lib -- 项目相关依赖
| ├── view -- 视图页面目录
| └── web.xml -- web部署文件
└── static
├── bootstrap-4.3.1-dist -- bootstrap依赖文件
├── wangEditor -- 富文本编辑器依赖文件
├── css -- 样式文件
├── images -- 图片文件
└── js -- javascript脚本文件

我从数据库开始:

  数据库需要:admin(管理员表)user(用户表)new_cate(新闻分类)news(新闻内容)newst(没有用)

代码:(可以直接运行)

 1 /*
 2 SQLyog Ultimate v12.08 (64 bit)
 3 MySQL - 8.0.16 : Database - news
 4 *********************************************************************
 5 */
 6 
 7 
 8 /*!40101 SET NAMES utf8 */;
 9 
10 /*!40101 SET SQL_MODE=''*/;
11 
12 /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
13 /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
14 /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
15 /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
16 CREATE DATABASE /*!32312 IF NOT EXISTS*/`news` /*!40100 DEFAULT CHARACTER SET utf8 */ /*!80016 DEFAULT ENCRYPTION='N' */;
17 
18 USE `news`;
19 
20 /*Table structure for table `admin` */
21 
22 DROP TABLE IF EXISTS `admin`;
23 
24 CREATE TABLE `admin` (
25   `id` int(11) NOT NULL AUTO_INCREMENT,
26   `username` varchar(10) NOT NULL,
27   `password` varchar(24) NOT NULL,
28   PRIMARY KEY (`id`)
29 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
30 
31 /*Table structure for table `news` */
32 
33 DROP TABLE IF EXISTS `news`;
34 
35 CREATE TABLE `news` (
36   `id` int(11) NOT NULL AUTO_INCREMENT,
37   `cate_id` int(11) NOT NULL,
38   `title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
39   `time` date NOT NULL,
40   `author` varchar(15) NOT NULL,
41   `content` varchar(20000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
42   PRIMARY KEY (`id`)
43 ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
44 
45 /*Table structure for table `news_cate` */
46 
47 DROP TABLE IF EXISTS `news_cate`;
48 
49 CREATE TABLE `news_cate` (
50   `id` int(11) NOT NULL AUTO_INCREMENT,
51   `name` varchar(12) NOT NULL,
52   PRIMARY KEY (`id`)
53 ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
54 
55 /*Table structure for table `user` */
56 
57 DROP TABLE IF EXISTS `user`;
58 
59 CREATE TABLE `user` (
60   `id` int(11) NOT NULL AUTO_INCREMENT,
61   `username` varchar(10) NOT NULL,
62   `password` varchar(24) NOT NULL,
63   `birthday` date NOT NULL,
64   `email` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
65   `tel_number` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
66   PRIMARY KEY (`id`)
67 ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
68 
69 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
70 /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
71 /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
72 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
sql语句

数据库完成的图片:

 

然后我从实体层开始写

 创建com.jsj.entity包:

 

Admin.java

作用:管理员登录

代码:

 1 package com.jsj.entity;
 2 
 3 public class Admin{
 4 
 5     private Integer id;
 6 
 7     private String username;
 8 
 9     private String password;
10 
11     public Integer getId() {
12         return id;
13     }
14 
15     public void setId(Integer id) {
16         this.id = id;
17     }
18 
19     public String getUsername() {
20         return username;
21     }
22 
23     public void setUsername(String username) {
24         this.username = username;
25     }
26 
27     public String getPassword() {
28         return password;
29     }
30 
31     public void setPassword(String password) {
32         this.password = password;
33     }
34 
35 }
View Code

 

News.java

作用:就是新闻主题内容

代码:

 1 package com.jsj.entity;
 2 
 3 import java.util.Date;
 4 
 5 public class News {
 6 
 7     private Integer id;
 8 
 9     private Integer cateId;
10 
11     private String title;
12 
13     private Date time;
14 
15     private String author;
16 
17     private String content;
18 
19     public Integer getId() {
20         return id;
21     }
22 
23     public void setId(Integer id) {
24         this.id = id;
25     }
26 
27     public Integer getCateId() {
28         return cateId;
29     }
30 
31     public void setCateId(Integer cateId) {
32         this.cateId = cateId;
33     }
34 
35     public String getTitle() {
36         return title;
37     }
38 
39     public void setTitle(String title) {
40         this.title = title;
41     }
42 
43     public Date getTime() {
44         return time;
45     }
46 
47     public void setTime(Date time) {
48         this.time = time;
49     }
50 
51     public String getAuthor() {
52         return author;
53     }
54 
55     public void setAuthor(String author) {
56         this.author = author;
57     }
58 
59     public String getContent() {
60         return content;
61     }
62 
63     public void setContent(String content) {
64         this.content = content;
65     }
66 
67 }
View Code

 

NewCate.java

作用:新闻分类所属的新闻列表

代码:

 1 package com.jsj.entity;
 2 
 3 import java.util.List;
 4 
 5 /**
 6  * 新闻分类所属的新闻列表
 7  */
 8 public class NewsCateVo {
 9 
10     private Integer cateId;
11 
12     private String name;
13 
14     private List<News> news;
15 
16     public Integer getCateId() {
17         return cateId;
18     }
19 
20     public void setCateId(Integer cateId) {
21         this.cateId = cateId;
22     }
23 
24     public String getName() {
25         return name;
26     }
27 
28     public void setName(String name) {
29         this.name = name;
30     }
31 
32     public List<News> getNews() {
33         return news;
34     }
35 
36     public void setNews(List<News> news) {
37         this.news = news;
38     }
39 
40 }
View Code

 

NewVo.java

作用:实现新闻分类的操作

代码:

 1 package com.jsj.entity;
 2 
 3 public class NewsVo extends News {
 4 
 5     private NewsCate newsCate;
 6 
 7     public NewsCate getNewsCate() {
 8         return newsCate;
 9     }
10 
11     public void setNewsCate(NewsCate newsCate) {
12         this.newsCate = newsCate;
13     }
14 
15 }
View Code

 

Page.java

作用:封装分页结果集

代码:

 1 package com.jsj.entity;
 2 
 3 import java.io.Serializable;
 4 import java.util.List;
 5 
 6 /**
 7  * 封装分页结果集
 8  */
 9 public class Page<T> implements Serializable {
10 
11     //当前页
12     private int pageIndex;
13 
14     //总页数=总记录数/每页显示的记录数
15     private int totalPage;
16 
17     //总记录数
18     private int totalCount;
19 
20     //每页显示的记录数
21     private int pageSize;
22 
23     //每页显示的数据
24     private List<T> beanList;
25 
26     public int getPageIndex() {
27         return pageIndex;
28     }
29 
30     public void setPageIndex(int pageIndex) {
31         this.pageIndex = pageIndex;
32     }
33 
34     public int getTotalPage() {
35         return totalPage;
36     }
37 
38     public void setTotalPage(int totalPage) {
39         this.totalPage = totalPage;
40     }
41 
42     public int getTotalCount() {
43         return totalCount;
44     }
45 
46     public void setTotalCount(int totalCount) {
47         this.totalCount = totalCount;
48     }
49 
50     public int getPageSize() {
51         return pageSize;
52     }
53 
54     public void setPageSize(int pageSize) {
55         this.pageSize = pageSize;
56     }
57 
58     public List<T> getBeanList() {
59         return beanList;
60     }
61 
62     public void setBeanList(List<T> beanList) {
63         this.beanList = beanList;
64     }
65 
66 }
View Code

 

User.java

作用:用户的注册和登录需要用到的,存储数据,可以这么理解

代码:

 1 package com.jsj.entity;
 2 
 3 import java.util.Date;
 4 
 5 public class User {
 6 
 7     private Integer id;
 8 
 9     private String username;
10 
11     private String password;
12 
13     private Date birthday;
14 
15     private String email;
16 
17     private String telNumber;
18 
19     public Integer getId() {
20         return id;
21     }
22 
23     public void setId(Integer id) {
24         this.id = id;
25     }
26 
27     public String getUsername() {
28         return username;
29     }
30 
31     public void setUsername(String username) {
32         this.username = username;
33     }
34 
35     public String getPassword() {
36         return password;
37     }
38 
39     public void setPassword(String password) {
40         this.password = password;
41     }
42 
43     public Date getBirthday() {
44         return birthday;
45     }
46 
47     public void setBirthday(Date birthday) {
48         this.birthday = birthday;
49     }
50 
51     public String getEmail() {
52         return email;
53     }
54 
55     public void setEmail(String email) {
56         this.email = email;
57     }
58 
59     public String getTelNumber() {
60         return telNumber;
61     }
62 
63     public void setTelNumber(String telNumber) {
64         this.telNumber = telNumber;
65     }
66 
67 }
View Code

 

posted @ 2020-05-12 20:44  赚钱买个打印机  阅读(300)  评论(0编辑  收藏  举报