java+mysql+ssm小区物业管理系统

基于JSP的小区物业管理系统-java系统mysql数据源 

开发环境:
Eclipse ,MySQL 5.1,JDK1.7,Tomcat 7
涉及技术点:
MVC模式、JavaWeb、JDBC、HTML、CSS、JQUERY、分页、等。
使用工具:

 代码已经上传github,下载地址:https://github.com/21503882

java+mysql+ssm小区物业管理系统_第1张图片

java+mysql+ssm小区物业管理系统_第2张图片

 

java+mysql+ssm小区物业管理系统_第3张图片

java+mysql+ssm小区物业管理系统_第4张图片

java+mysql+ssm小区物业管理系统_第5张图片

java+mysql+ssm小区物业管理系统_第6张图片

java+mysql+ssm小区物业管理系统_第7张图片

 

 

 

 

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zsga.kbms.entity.Article;
import com.zsga.kbms.entity.User;
import com.zsga.kbms.lucene.ArticleIndex;
import com.zsga.kbms.service.ArticleService;
import com.zsga.kbms.service.CommentService;
import com.zsga.kbms.utils.StringUtil;

/**
 * 文章Controller
 * @author admin
 *
 */
@Controller
@RequestMapping("/article")
public class ArticleController {
    
    @Autowired
    private ArticleService articleService;
    
    @Autowired
    private CommentService commentService;
    
    //文章索引
    private ArticleIndex articleIndex = new ArticleIndex();
    
    /**
     * 请求文章信息
     * @param id
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/articles/{id}")
    public ModelAndView details(@PathVariable("id")Integer id,HttpServletRequest request) throws Exception {
        ModelAndView mav=new ModelAndView();
        Article article = articleService.findArticleById(id);
        //获取文章类型ID
        Integer articleTypeId = article.getArticleType().getId();
        User currentUser = (User) request.getSession().getAttribute("currentUser");
        String role = currentUser.getRole();
        if (role.contains(Integer.toString(articleTypeId))) {  //有权查看
            String keyWords=article.getKeyWord();
            if(StringUtil.isNotEmpty(keyWords)){
                String arr[]=keyWords.split(" ");
                mav.addObject("keyWords",StringUtil.filterWhite(Arrays.asList(arr)));            
            }else{
                mav.addObject("keyWords",null);            
            }
            mav.addObject("article", article);
            article.setClickHit(article.getClickHit()+1); // 文章点击次数加1
            articleService.editArticle(article);
            Map map=new HashMap();
            map.put("articleId", article.getId());
            //map.put("state", 1); // 查询审核通过的评论
            mav.addObject("commentList", commentService.list(map)); 
            mav.addObject("pageCode", this.genUpAndDownPageCode(articleService.getLastArticle(id),articleService.getNextArticle(id),request.getServletContext().getContextPath()));
            mav.addObject("mainPage", "foreground/article/view.jsp");
            mav.addObject("pageTitle",article.getTitle()+"_系统");
            mav.setViewName("mainTemp");
        } else { //无权限查看
            mav.setViewName("noaccess");
        }
        
        return mav;
    }
    
    /**
     * 获取下一篇文章和下一篇文章代码
     * @param lastArticle
     * @param nextArticle
     * @param projectContext
     * @return
     */
    private String genUpAndDownPageCode(Article lastArticle,Article nextArticle,String projectContext){
        StringBuffer pageCode = new StringBuffer();
        if(lastArticle == null || lastArticle.getId() == null){
            pageCode.append("

上一篇:没有了

");
        }else{
            pageCode.append("

上一篇:"+lastArticle.getTitle()+"

");
        }
        if(nextArticle == null || nextArticle.getId() == null){
            pageCode.append("

下一篇:没有了

");
        }else{
            pageCode.append("

下一篇:"+nextArticle.getTitle()+"

");
        }
        return pageCode.toString();
    }
    
    /**
     * 根据关键字查询相关文章信息
     * @param q
     * @param page
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/q")
    public ModelAndView search(@RequestParam(value="q", required=false)String q, @RequestParam(value="page", required=false)String page,
            HttpServletRequest request) throws Exception {
        if(StringUtil.isEmpty(page)){
            page="1";
        }
        ModelAndView mav=new ModelAndView();
        mav.addObject("mainPage", "foreground/article/result.jsp");
        List
articleList=articleIndex.searchArticle(q.trim());
        Integer toIndex=articleList.size()>=Integer.parseInt(page)*10?Integer.parseInt(page)*10:articleList.size();
        mav.addObject("articleList",articleList.subList((Integer.parseInt(page)-1)*10, toIndex));
        mav.addObject("pageCode",this.genUpAndDownPageCode(Integer.parseInt(page), articleList.size(), q,10,request.getServletContext().getContextPath()));
        mav.addObject("q",q);
        mav.addObject("resultTotal",articleList.size());
        mav.addObject("pageTitle","搜索关键字'"+q+"'结果页面_系统");
        mav.setViewName("mainTemp");
        return mav;
    }
    
    /**
     * 获取上一页,下一页代码 查询文章用到
     * @param page 当前页
     * @param totalNum 总记录数
     * @param q 查询关键字
     * @param pageSize 每页大小
     * @param projectContext
     * @return
     */
    private String genUpAndDownPageCode(Integer page,Integer totalNum,String q,Integer pageSize,String projectContext){
        long totalPage=totalNum%pageSize==0?totalNum/pageSize:totalNum/pageSize+1;
        StringBuffer pageCode=new StringBuffer();
        if(totalPage==0){
            return "";
        }else{
            pageCode.append("");
        }
        return pageCode.toString();
    }
    
}
 代码已经上传github,下载地址:https://github.com/21503882
————————————————

你可能感兴趣的:(java+mysql+ssm小区物业管理系统)