博客网站系统-004Service层

Posted shamgod

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了博客网站系统-004Service层相关的知识,希望对你有一定的参考价值。

1.

 1 package com.sanqing.service;
 2 
 3 import java.util.List;
 4 
 5 import com.sanqing.fenye.Page;
 6 import com.sanqing.fenye.Result;
 7 import com.sanqing.po.Article;
 8 
 9 public interface ArticleService {
10     //进行文章的保存
11     public void addArticle(Article article);
12     
13     //取出用户所有的文章
14     public List<Article> showUserAllArticle(String username);
15     
16     //分页显示用户文章
17     public Result showUserArticleByPage(String username,Page page);
18     
19     //分页显示全部文章
20     public Result showArticleByPage(Page page);
21     
22     //显示文章
23     public Article showArticle(int id);
24     
25     //获得评论数
26     public int getCritiqueCount(int AId);
27 }

 

2.

 1 package com.sanqing.service;
 2 
 3 import java.util.List;
 4 
 5 import com.sanqing.dao.ArticleDAO;
 6 import com.sanqing.dao.CritiqueDAO;
 7 import com.sanqing.fenye.Page;
 8 import com.sanqing.fenye.PageUtil;
 9 import com.sanqing.fenye.Result;
10 import com.sanqing.po.Article;
11 
12 public class ArticleServiceImpl implements ArticleService {
13     private ArticleDAO articleDAO;
14     private CritiqueDAO critiqueDAO;
15     
16     
17     public CritiqueDAO getCritiqueDAO() {
18         return critiqueDAO;
19     }
20 
21 
22     public void setCritiqueDAO(CritiqueDAO critiqueDAO) {
23         this.critiqueDAO = critiqueDAO;
24     }
25 
26 
27     public ArticleDAO getArticleDAO() {
28         return articleDAO;
29     }
30 
31 
32     public void setArticleDAO(ArticleDAO articleDAO) {
33         this.articleDAO = articleDAO;
34     }
35 
36 
37     public void addArticle(Article article) {
38         articleDAO.add(article);
39     }
40 
41 
42     public List<Article> showUserAllArticle(String username) {
43         System.out.println(articleDAO.queryUserAllCount(username));
44         return articleDAO.queryUserAll(username);
45     }
46 
47 
48     public Result showUserArticleByPage(String username, Page page) {
49         page = PageUtil.createPage(page,articleDAO.queryUserAllCount(username));
50         List<Article> all = articleDAO.queryByPage(username, page);
51         Result result = new Result();
52         result.setPage(page);
53         result.setList(all);
54         return result;
55     }
56 
57 
58     public Result showArticleByPage(Page page) {
59         page = PageUtil.createPage(page,articleDAO.queryAllCount());
60         List<Article> all = articleDAO.queryAllByPage(page);
61         Result result = new Result();
62         result.setPage(page);
63         result.setList(all);
64         return result;
65     }
66 
67 
68     public Article showArticle(int id) {
69         return articleDAO.queryById(id);
70     }
71 
72 
73     public int getCritiqueCount(int AId) {
74         return critiqueDAO.queryCritiqueCount(AId);
75     }
76 
77 }

 

3.

 1 package com.sanqing.service;
 2 
 3 import com.sanqing.po.BlogInfo;
 4 
 5 public interface BlogInfoService {
 6     //设置博客个性化内容
 7     public void setBlogInfo(BlogInfo blogInfo);
 8     
 9     //获得博客个性化内容
10     public BlogInfo getBlogInfo(String name);
11 }

 

4.

 1 package com.sanqing.service;
 2 
 3 import com.sanqing.dao.BlogInfoDAO;
 4 import com.sanqing.po.BlogInfo;
 5 
 6 public class BlogInfoServiceImpl implements BlogInfoService {
 7     private BlogInfoDAO blogInfoDAO;
 8     
 9     public BlogInfo getBlogInfo(String username) {
10         return blogInfoDAO.get(username);
11     }
12 
13     public BlogInfoDAO getBlogInfoDAO() {
14         return blogInfoDAO;
15     }
16 
17     public void setBlogInfoDAO(BlogInfoDAO blogInfoDAO) {
18         this.blogInfoDAO = blogInfoDAO;
19     }
20 
21     public void setBlogInfo(BlogInfo blogInfo) {
22         //通过调用DAO组件来完成
23         blogInfoDAO.save(blogInfo);
24     }
25 
26 }

 

5.

 1 package com.sanqing.service;
 2 
 3 import com.sanqing.fenye.Page;
 4 import com.sanqing.fenye.Result;
 5 import com.sanqing.po.Critique;
 6 
 7 public interface CritiqueService {
 8     //添加评论
 9     public void addCritique(Critique critique);
10     
11     //分页显示评论
12     public Result showCritiqueByPage(int AId,Page page);
13     
14     //获得指定文章的评论数
15     public int getCritiqueCount(int AId);
16 }

 

6.

 1 package com.sanqing.service;
 2 
 3 import java.util.List;
 4 
 5 import com.sanqing.dao.CritiqueDAO;
 6 import com.sanqing.fenye.Page;
 7 import com.sanqing.fenye.PageUtil;
 8 import com.sanqing.fenye.Result;
 9 import com.sanqing.po.Article;
10 import com.sanqing.po.Critique;
11 
12 public class CritiqueServiceImpl implements CritiqueService {
13     private CritiqueDAO critiqueDAO;
14 
15     public CritiqueDAO getCritiqueDAO() {
16         return critiqueDAO;
17     }
18 
19     public void setCritiqueDAO(CritiqueDAO critiqueDAO) {
20         this.critiqueDAO = critiqueDAO;
21     }
22 
23     public void addCritique(Critique critique) {
24         critiqueDAO.addCritique(critique);
25     }
26 
27     public Result showCritiqueByPage(int AId, Page page) {
28         page = PageUtil.createPage(page,critiqueDAO.queryCritiqueCount(AId));
29         List<Critique> all = critiqueDAO.queryByPage(AId, page);
30         Result result = new Result();
31         result.setPage(page);
32         result.setList(all);
33         return result;
34     }
35 
36     public int getCritiqueCount(int AId) {
37         return critiqueDAO.queryCritiqueCount(AId);
38     }
39 }

 

7.

1 package com.sanqing.service;
2 
3 import java.util.Date;
4 
5 public interface DianjiliangService {
6     //ÅжÏÊÇ·ñµã»÷¹ý
7     public boolean isVistor(int AId,String IP,Date time);
8 }

 

8.

 1 package com.sanqing.service;
 2 
 3 import java.util.Date;
 4 
 5 import com.sanqing.dao.DianjiliangDAO;
 6 import com.sanqing.po.Dianjiliang;
 7 
 8 public class DianjiliangServiceImpl  implements DianjiliangService{
 9     private DianjiliangDAO dianjiliangDAO;
10 
11     public DianjiliangDAO getDianjiliangDAO() {
12         return dianjiliangDAO;
13     }
14 
15     public void setDianjiliangDAO(DianjiliangDAO dianjiliangDAO) {
16         this.dianjiliangDAO = dianjiliangDAO;
17     }
18 
19     public boolean isVistor(int AId, String IP, Date time) {
20         if(dianjiliangDAO.queryByAId(AId, IP, time).size() != 0) {
21             System.out.println("该IP今天点击过了");
22             //表示用户已经点击过了。
23             return true;
24         } else {
25             System.out.println("该IP今天没有点击过");
26             //表示用户没有点击过
27             Dianjiliang djl = new Dianjiliang();
28             djl.setAId(AId);
29             djl.setIp(IP);
30             djl.setTime(time);
31             //保存记录
32             dianjiliangDAO.addJilu(djl);
33             return false;
34         }
35     }
36     
37     
38 }

 

9.

 1 package com.sanqing.service;
 2 
 3 import com.sanqing.po.User;
 4 
 5 public interface UserService {
 6     //用户注册
 7     public boolean registerUser(User user);
 8     
 9     //用户登陆
10     public boolean loginUser(User user);
11 }

 

10.

 1 package com.sanqing.service;
 2 
 3 import com.sanqing.dao.UserDAO;
 4 import com.sanqing.po.User;
 5 
 6 public class UserServiceImpl implements UserService {
 7     private UserDAO userDAO;
 8     
 9     public boolean registerUser(User user) {
10         //判断用户是否存在
11         if(userDAO.queryByID(user.getUsername()) != null) {
12             return false;
13         }else {
14             userDAO.add(user);
15             return true;
16         }
17     }
18 
19     public UserDAO getUserDAO() {
20         return userDAO;
21     }
22 
23     public void setUserDAO(UserDAO userDAO) {
24         this.userDAO = userDAO;
25     }
26 
27     public boolean loginUser(User user) {
28         //判断用户是否存在
29         if(userDAO.queryByID(user.getUsername()) == null) {
30             return false;
31         } else {
32             User queryUser = userDAO.queryByID(user.getUsername());
33             if(queryUser.getPassword().equals(user.getPassword())) {
34                 return true;
35             } else {
36                 return false;
37             }
38         }
39     }
40     
41     
42 
43 }

 

11.

以上是关于博客网站系统-004Service层的主要内容,如果未能解决你的问题,请参考以下文章

Wordpress阻止访问wp admin€“wpsnipp.com网站你博客的Wordpress代码片段

博客网站系统-006View层

spring事务到底用于service层还是dao层

为 Blogger 上的博客格式化代码片段 [关闭]

秒杀系统-service

超级有用的9个PHP代码片段