门户分为四层结构(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