齐鲁云门户springMVC+facade+maven配置笔记

门户分为四层结构(controll->facade->service->dao),采用springMVC框架,facade设计模式,用maven管理jar包。分为1个父项目,和7个子项目

举例dao层代码

public interface IUserGuideDao extends GenericDao<SysNews>{
public static final String DAO_NAME="userGuideDao";
}
@Repository(value = IUserGuideDao.DAO_NAME)
public class UserGuideDaoImpl extends GenericDaoHibernateSupport<SysNews>
        implements IUserGuideDao {

}

service层代码

public interface IUserGuideService {
    public static final String SERVICE_NAME = "userGuideService";

   /**
     * 根据新闻标题查询新闻详情
     */
    public SysNews getNewsById(String id) throws Exception;

    /**
     * 根据用户指南对应的paramCode查询新闻标题
     */
    public List<SysNews> queryByParamcode(String paramCode) throws Exception;

}
@Service(value = IUserGuideService.SERVICE_NAME)
public class UserGuideServiceImpl implements IUserGuideService {
    @Resource(name = IUserGuideDao.DAO_NAME)
    private IUserGuideDao userGuideDao;
/**
     * 根据id返回用户指南详情
     * @return
     * @throws Exception
     */
    @Override
    public SysNews getNewsById(String id) throws Exception {
        SysNews sysNews = userGuideDao.findById(id);
        return sysNews;
    }

    @Override
    public List<SysNews> queryByParamcode(String paramCode) throws Exception {
        String hql = "from SysNews s where s.sysParamInfo.paramCode= ? order by s.orderNum asc";
        List<SysNews> sysNews = userGuideDao.findByHQLAndParams(hql, paramCode);
        return sysNews;
    }
}

facade层代码

@Path(value = "/userGuide")
public interface IUserGuideFacade extends CommonFacade{
    public static final String FACADE_NAME = "userGuideFacade";
    public static final String NEWPARAMCODE = "00001304"; // 用户指南参数编码

  /**
     * 加载用户指南详情
     * @return
     * @throws Exception
     */
    @POST
    @Path(value="/getUserGuideById")
    public RSUserGuide getUserGuideById(RSUserGuideDetailQueryReq req) throws Exception;

    @POST
    @Path(value="/queryByParamCode")
    public List<RSUserGuide> queryByParamCode(String paramCode) throws Exception; 

}
@Service(value = IUserGuideFacade.FACADE_NAME)
public class UserGuideFacadeImpl implements IUserGuideFacade {
    @Resource(name = IUserGuideService.SERVICE_NAME)
    private IUserGuideService userGuideService;

    @Override
    public RSUserGuide getUserGuideById(RSUserGuideDetailQueryReq req)
            throws Exception {
        SysNews sysNews = userGuideService.getNewsById(req.getId());
        RSUserGuide reUserGuide = null;
        if (sysNews != null) {
            reUserGuide = new RSUserGuide(sysNews);
        }
        return reUserGuide;
    }

    @Override
    public List<RSUserGuide> queryByParamCode(String paramCode)
            throws Exception {
        List<SysNews> sysNewsList = userGuideService.queryByParamcode(paramCode);
        List<RSUserGuide> rsUserGuideList = new ArrayList<RSUserGuide>();
        for (SysNews sysNews : sysNewsList) {
            rsUserGuideList.add(new RSUserGuide(sysNews));
        }
        return rsUserGuideList;
    }

}

controller层代码

@Controller
@RequestMapping(value="/userGuide")
public class UserGuideController {
    private static final Logger _LOG = Logger.getLogger(UserGuideController.class);
    @Resource(name = IUserGuideFacade.FACADE_NAME)
    private IUserGuideFacade userGuideFacade;

    @RequestMapping
    public String index(Model model) throws Exception {
        model.addAttribute("userGuideCode", NewChannel.USERGUIDE_CODE);
        return "userGuide/userGuide";
    }

  /**
     * 根据id查询用户指南详情
     */
    @RequestMapping(value = "info")
    public
    @ResponseBody
    RSUserGuide newsDetailById(UserGuideForm userGuideForm) throws Exception {
        RSUserGuide resp = null;
        try {
            RSUserGuideDetailQueryReq req = new RSUserGuideDetailQueryReq();
            req.setId(userGuideForm.getId());
            resp = userGuideFacade.getUserGuideById(req);
        } catch (Exception e) {
            _LOG.error(e);
            resp = null;
        }

        return resp;
    }

    /**
     * 根据paramCode查询所有标题
     */

    @RequestMapping(value = "queryByparamCode")
    public
    @ResponseBody
    List<RSUserGuide> queryByParamCode(RSUserGuideDetailQueryReq req) throws Exception {
        List<RSUserGuide> rsuserGuide  = userGuideFacade.queryByParamCode(req.getParamCode());
        return  rsuserGuide;

    }
}

后台代码写完后需要把facade添加到cxf配置文件中去

dataserver

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:cxf="http://cxf.apache.org/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    <import resource="classpath:META-INF/cxf/applicationContext-cxf-config.xml"/>

    <jaxrs:server id="rest-container" address="/">
        <jaxrs:providers>
            <bean class="com.iss.cloud.portal.common.provider.ISSJacksonJaxbJsonProvider">
                <constructor-arg type="com.fasterxml.jackson.databind.ObjectMapper">
                    <bean class="com.fasterxml.jackson.databind.ObjectMapper">
                        <property name="serializationInclusion" value="NON_NULL"/>
                    </bean>
                </constructor-arg>
            </bean>
            <bean class="com.iss.cloud.portal.common.rs.provider.FaultOutHandleProvider"/>

        </jaxrs:providers>
        <jaxrs:serviceBeans>
            <ref bean="userGuideFacade"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

</beans>

UserPortal

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
">

    <http-conf:conduit name="{WSDL Namespace}portName.http-conduit">
        <http-conf:client ConnectionTimeout="30000" ReceiveTimeout="30000" />
    </http-conf:conduit>

    <cxf:bus>
        <cxf:features>
            <cxf:logging />
            <!--<cxf:fastinfoset force="false" />-->
        </cxf:features>

        <!-- compress the exchange data size -->
        <cxf:inInterceptors>
            <bean class="org.apache.cxf.transport.common.gzip.GZIPInInterceptor" />
        </cxf:inInterceptors>
        <cxf:outInterceptors>
            <bean class="org.apache.cxf.transport.common.gzip.GZIPOutInterceptor" />
        </cxf:outInterceptors>
    </cxf:bus>

    <jaxrs:client id="userGuideFacade" address="${dataserver.rs.address}"
                  serviceClass="com.iss.cloud.portal.modules.userGuide.facade.IUserGuideFacade"
                  inheritHeaders="true">
        <jaxrs:headers>
            <entry key="Accept" value="application/json" />
            <entry key="Content-Type" value="application/json;charset=UTF-8" />
            <entry key="Authorization" value="Basic dG9tOjEyMzQ1Njc4"/>
        </jaxrs:headers>
        <jaxrs:providers>
            <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" />
        </jaxrs:providers>
</beans>
时间: 2024-10-31 03:26:10

齐鲁云门户springMVC+facade+maven配置笔记的相关文章

Maven配置笔记

android-m2e插件与maven 自定义用户配置路径 不管插件还是maven,默认的用户配置路径是统一的:${user.home}/.m2/settings.xml 但是插件可以通过eclipse设置用户配置的路径(配置方法参考<ADT+Android-m2e环境搭建>):而maven不能永久指定,只能在每次使用mvn命令时加上"-s 新路径"参数. 依赖 如果使用android-m2d,在eclipse中写好依赖配置(<dependency>),保存之后

SpringMVC框架入门配置 IDEA下搭建Maven项目

,初衷:本人初学SpringMVC的时候遇到各种稀奇古怪的问题,网上各种技术论坛上的帖子又参差不齐,难以一步到位达到配置好的效果,这里我将我配置的总结写到这里供大家初学SpringMVC的同僚们共同学习使用! 关于SpringMVC的介绍我就不在此赘述了,想必每一个配置Spring的人都已经或多或少了解过一些SpringMVC的基础知识,可能有的人用的myeclipse或者eclipse进行项目的搭建,我会告诉你这里步骤是很相似的,在myeclipse里面需要建立web项目,然后加入Spring

SpringMVC+Spring+Mybatis整合,使用druid连接池,声明式事务,maven配置

一直对springmvc和mybatis挺怀念的,最近想自己再搭建下框架,然后写点什么. 暂时没有整合缓存,druid也没有做ip地址的过滤.Spring的AOP简单配置了下,也还没具体弄,不知道能不能用,log也不知道能不能用,`(*∩_∩*)′哈哈,有点不负责任...... 直接上代码: 使用的eclipse和eclipse自带的maven,参考了网上的资料,有些代码是拷贝的,不过都自己测试过了.嗯,可以跑起来... 先上项目结构: 新建maven项目,选择web,然后配置pom: <pro

IDEA配置maven(配置阿里云中央仓库)

前言 idea配置maven后如果不修改中央仓库地址创建maven则出奇的慢,不管你用MyEclipse还是idea都慢的不要不要的,实在不能忍受. 这种条件下发现一个阿里云中央仓库来点福利,有福利了就必须给阿里云点个赞. 配置Maven 下载maven,我用的版本是3.3.9. 配置环境变量.设置Repository. 这时你创建maven项目时settings.xml默认是用/User/.m2/settings.xml. 打开maven/conf/settings.xml, 找到mirror

Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 以及 IntelliJ IDEA 怎样打开依赖视图

Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 配置原则: 利用依赖,将所需的jar包加载到project中. 先依赖主要jar包 Spring + Spring MVC + MyBatis + database 再依赖次要jar包 C3p0连接池.log4j,Junit 外围jar包 POI jFreeCharts jxl 样例: 通常仅仅使用Spring时,将spring-context依赖到pom中. <dependency> <groupId&

Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 以及 IntelliJ IDEA 如何打开依赖视图

Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 配置原则: 利用依赖,将所需的jar包载入到工程中. 先依赖主要jar包 Spring + Spring MVC + MyBatis + database 再依赖次要jar包 C3p0连接池,log4j,Junit 外围jar包 POI jFreeCharts jxl 例子: 通常只使用Spring时,将spring-context依赖到pom中. <dependency> <groupId>org

java之Maven配置和springMvc的简单应用

初始springMvc这个框架,非常的陌生,而且幸好公司是通过maven这个代码管理工具,可以随时添加依赖.解决了很多问题在以后深入开发中. 项目结构: 通过结构中,pom.xml这个文件其实就说明这个项目是通过maven构建的,pom.xml里是主要负责构建jar或者war的依赖.其代码如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XML

settings 全局默认设置 Maven配置使用阿里云镜像

在settings.xml文件中的mirrors下添加mirror标签 <!-- 阿里云仓库 --> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/<

Log4j2 配置笔记(Eclipse+maven+SpringMVC)

Log4j2相关介绍可以百度看下,这里只注重配置Log4j2 能够马上跑起来: 1.pom.xml文件中添加Log4j2的相关Maven配置信息 <!-- log4j2 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.1</version> &l