e3mall项目:首页(前台)

e3mall项目:首页

一、子模块创建

(1)pom.xml中打包方式为war

(2)包结构如下:

e3mall项目:首页(前台)_第1张图片


二、相关配置文件

(1)springmvc.xml

xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

    
    <context:property-placeholder location="classpath:other/resource.properties"/>

    
    <context:component-scan base-package="cn.e3mall.portal.controller" />

    
    <mvc:annotation-driven />

    
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        name="prefix" value="/WEB-INF/jsp/"/>
        name="suffix" value=".jsp"/>
    

    
    <dubbo:application name="e3-portal-web"/>
    <dubbo:registry protocol="zookeeper" address="192.168.25.130:2181"/>
    <dubbo:reference interface="cn.e3mall.content.service.ContentService" id="contentService" />




(2)resource.properties

#首页轮播图对应的categoryid
CONTENT_AD1_CATEGORYID=89
CONTENT_AD2_CATEGORYID=96


(3)web.xml

xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
  e3-p-web
  
    index.html
  

  
  
    e3-manager
    org.springframework.web.servlet.DispatcherServlet
    
      contextConfigLocation
      classpath:spring/springmvc.xml
    
    1
  
  
    e3-manager
    
    *.html
  

  
  
    encoding
    org.springframework.web.filter.CharacterEncodingFilter
    
      encoding
      utf-8
    
  
  
    encoding
    /*
  

(4)pom.xml

xml version="1.0" encoding="UTF-8"?>

xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
        e3-parent
        cn.e3mall
        1.0-SNAPSHOT
    
    4.0.0
    e3-portal-web
    war

    e3-portal-web

    
        
            cn.e3mall
            e3-manager-interface
            1.0-SNAPSHOT
        
        
            cn.e3mall
            e3-content-interface
            1.0-SNAPSHOT
        
        
            cn.e3mall
            e3-manager-dao
            1.0-SNAPSHOT
        
        
        
            org.springframework
            spring-context
        
        
            org.springframework
            spring-beans
        
        
            org.springframework
            spring-webmvc
        
        
            org.springframework
            spring-jdbc
        
        
            org.springframework
            spring-aspects
        
        
            org.springframework
            spring-jms
        
        
            org.springframework
            spring-context-support
        
        
        
            jstl
            jstl
        
        
            javax.servlet
            servlet-api
            provided
        
        
            javax.servlet
            jsp-api
            provided
        
    

    
        
            
            
                org.apache.tomcat.maven
                tomcat7-maven-plugin
                2.2
                
                    8082
                    /
                
            
        
    


三、代码实现

(1)PageController

package cn.e3mall.portal.controller;

import cn.e3mall.content.service.ContentService;
import cn.e3mall.entity.TbContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 页面跳转控制层
 * Author: xushuai
 * Date: 2018/5/17
 * Time: 10:07
 * Description:
 */
@Controller
public class PageController {

    @Value("${CONTENT_AD1_CATEGORYID}")
    private Long CONTENT_AD1_CATEGORYID;

    @Value("${CONTENT_AD2_CATEGORYID}")
    private Long CONTENT_AD2_CATEGORYID;

    @Autowired
    private ContentService contentService;

    /*
     * 前往主页
     */
    @RequestMapping("/index.html")
    public String toHome(Model model){
        //使用内容分类id查询轮播图信息
        List ad1ContentList = contentService.getContentList(CONTENT_AD1_CATEGORYID);
        List ad2ContentList = contentService.getContentList(CONTENT_AD2_CATEGORYID);
        //将内容列表保存并发送到页面
        model.addAttribute("ad1List",ad1ContentList);
        model.addAttribute("ad2List",ad2ContentList);

        return "index";
    }
}


(2)ContentService、ContentServiceImpl(新增方法及其实现)

/**
 * 按内容分类id查询内容列表
 * @auther: xushuai
 * @date: 2018/5/21 16:46
 */
List getContentList(Long categoryId);
@Override
public List getContentList(Long categoryId) {
    //创建查询条件对象
    TbContentExample example = new TbContentExample();
    //封装查询条件
    example.createCriteria().andCategoryIdEqualTo(categoryId);
    //执行查询获取结果
    List tbContents = contentMapper.selectByExampleWithBLOBs(example);

    return tbContents;
}

四、页面部分(关键代码)

e3mall项目:首页(前台)_第2张图片





你可能感兴趣的:(个人成长,实战项目,e3mall,ssm,soa架构)