必威体育Betway必威体育官网
当前位置:首页 > IT技术

hybris程序搭建-总结文档.docx

时间:2019-06-19 02:42:06来源:IT技术作者:seo实验室小编阅读:80次「手机版」
 

hybris

目录

分页查询数据操作步骤 1

分页查询数据代码 3

扩展一个字段操作步骤 12

详情页操作步骤 14

条件搜索操作步骤 16

表单信息的录入与提交保存操作步骤 19

搭建B2C商城步骤 25

单击此处输入文字。

分页查询数据操作步骤

1. 在trainingStorefront工程中新建controller,例如(UserMessageController)仿照订单历史记录的controller代码编写,在类上加注解@Controller和@RequestMapping并继承extends AbstractSearchPageController

2. 需要在trainingfacade工程中编写自己的facade,(DefaultUserMessageFacade),并将其注入到controller中并加上注解@Resource(name=”defaultUserMessageFacade”)

3. 将新建的DefaultUserMessageFacade注入到trainingfacades工程中的trainingfacades-spring.xml文件中

4. 在trainingcore工程中新建service层,(UserMessageService和UserMessageServiceImpl),并将UserMessageServiceImpl注入到trainingfacades-spring.xml中对应的facade引用处

<bean id="defaultUserMessageFacade" class="org.training.facades.userMessage.impl.DefaultUserMessageFacade" parent="defaultCheckoutFacade">

  <property name="modelService" ref="modelService" />

  <property name="userMessageService" ref="userMessageService" />

  <property name="userMessagePageListtConverter" ref="userMessagePageListtConverter" />

</bean>

5. 在trainingcore工程中新建dao层(UserMessageDao和UserMessageDaoImpl),并将UserMessageDao注入到UserMessageServiceImpl并生成getter和setter方法,然后将UserMessageDaoImpl注入到trainingfacades-spring.xml中对应的facade引用处,并在trainingcore-spring.xml中加入service和dao的引用声明

<alias alias="userMessageService" name="userMessageService"/>

<bean id="userMessageService"

class="org.training.core.userservice.impl.UserMessageServiceImpl">

  <property name="userMessageDao" ref="userMessageDao"/>

</bean>

<bean name="userMessageDao" class="org.training.core.userDao.impl.UserMessageDaoImpl">

  <property name="pagedFlexibleSearchService" ref="pagedFlexibleSearchService"/>

<property name="flexibleSearchService" ref="flexibleSearchService"/>

  <property name="modelService" ref="modelService"/>

</bean>

6. 在controller 中调用facade中新建的方法,例如我的是getPagedUserMessageListForStatuses(PageableData pageableData)这个方法,

7. 在facade中加入Converter,例如userMessagePageListtConverter,并将其注入到trainingfacades-spring.xml中,新建getPagedUserMessageListForStatuses()方法,在该方法中调用service中的方法getUserMessagePageList(pageableData);引入的转换器可命名为如下:

Converter<UserMessageCodeModel, UserMessageData> userMessagePageListtConverter

8. 在UserMessageServiceImpl中调用UserMessageDaoImpl的findUserMessagePageListAndStore(pageableData)方法

9. 在UserMessageDaoImpl中编写SQL语句,注入

PagedFlexibleSearchService pagedFlexibleSearchService,并将其注入到trainingcore-spring.xml中

10. 在UserMessageDaoImpl中新建

findUserMessagePageListAndStore( final PageableData pageableData)方法,该方法又调用了getPagedFlexibleSearchService().search()方法,将查询结果查出保存到searchpagedata中并返回到相应的页面.

11. trainingfacade工程中新建populator,例如(UserMessagePopulator),实现 Populator<SOURCE, TARGET>,并将source改为UserMessageCodeModel,将target改为 UserMessageData,并将UserMessagePopulator注入到trainingfacades-spring.xml中

<alias name="defaultUserMessagePopulator" alias="userMessagePopulator"/>

<bean id="defaultUserMessagePopulator" class="org.training.facades.populators.userPopulator.UserMessagePopulator"  >

</bean>

12. 运行ant all和hybrisserver.bat启动服务,如果构建成功并且服务能正常启动起来,说明注入populator是没问题的.

13. 因为一个converter可包含多个populator,所以,此时需要在trainingfacades-spring.xml中将defaultUserMessagePopulator加入到 userMessagePageListtConverter中

<bean id="userMessagePageListtConverter" parent="abstractPopulatingConverter">

  <property name="targetClass" value="de.hybris.platform.commercefacades.order.data.UserMessageData"/>

  <property name="populators">

 <list>

<ref bean="userMessagePopulator"/>

 </list>

  </property>

</bean>

14. 然后再次运行ant all和hybrisserver.bat启动服务,如果都正常,说明converter引用populator成功

15. trainingStorefront工程中新建JSP页面,在页面上引入相关tag与template与分页组件,并用foreach遍历数据

<%@ taglib prefix="pagination" tagdir="/WEB-INF/tags/responsive/nav/pagination" %>

<%@ taglib prefix="nav" tagdir="/WEB-INF/tags/responsive/nav" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

分页组件

<p class="account-orderhistory-pagination">

<nav:pagination top="true" msgKey="text.account.orderHistory.page" showCurrentPageInfo="true" hideRefineButton="true" supportShowPaged="${isShowPageAllowed}" supportShowAll="${isShowAllAllowed}" searchPageData="${searchPageData}" searchUrl="${searchUrl}"  numberPagesShown="${numberPagesShown}"/>

</p>

分页查询数据代码

1. UserMessageController

package org.training.storefront.controllers.pages.checkout.steps;

import de.hybris.platform.acceleratorstorefrontcommons.annotations.PreValidateQuoteCheckoutStep;

import de.hybris.platform.acceleratorstorefrontcommons.annotations.RequireHardLogIn;

import de.hybris.platform.acceleratorstorefrontcommons.breadcrumb.ResourceBreadcrumbBuilder;

import de.hybris.platform.acceleratorstorefrontcommons.controllers.ThirdPartyConstants;

import de.hybris.platform.acceleratorstorefrontcommons.controllers.pages.checkout.steps.AbstractCheckoutStepController;

import de.hybris.platform.acceleratorstorefrontcommons.controllers.util.GlobalMessages;

import de.hybris.platform.acceleratorstorefrontcommons.forms.PlaceOrderForm;

import de.hybris.platform.cms2.exceptions.CMSItemNotFoundException;

import de.hybris.platform.commercefacades.order.data.OrderHistoryData;

import de.hybris.platform.commercefacades.order.data.UserMessageData;

import de.hybris.platform.commerceservices.order.CommerceCartModificationException;

import de.hybris.platform.commerceservices.search.pagedata.PageableData;

import de.hybris.platform.commerceservices.search.pagedata.SearchPageData;

import de.hybris.platform.order.InvalidCartException;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.RequestMapping;

import de.hybris.platform.acceleratorstorefrontcommons.controllers.pages.checkout.steps.AbstractCheckoutStepController;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import org.training.facades.userMessage.UserMessageFacade;

import org.training.storefront.controllers.ControllerConstants;

import org.training.storefront.controllers.model.UserMessageForm;

import javax.annotation.Resource;

import javax.servlet.http.HttpServletRequest;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.regex.Pattern;

@Controller

@RequestMapping(value = "/checkout/multi/userMessage")

public class UserMessageController extends AbstractCheckoutStepController {

private final String QUOTE_DETAILS_CMS_PAGE = "userMessagePageID";

private final String TEXT_ACCOUNT_PROFILE = "text.account.profile";

private static final String BREADCRUMBS_ATTR = "breadcrumbs";

@Resource(name = "accountBreadcrumbBuilder")

private ResourceBreadcrumbBuilder accountBreadcrumbBuilder;

@Resource(name="defaultUserMessageFacade")

private UserMessageFacade userMessageFacade;

@Override

public String enterStep(Model model, RedirectAttributes redirectAttributes) throws CMSItemNotFoundException, CommerceCartModificationException {

return null;

}

@Override

public String back(RedirectAttributes redirectAttributes) {

return null;

}

@Override

public String next(RedirectAttributes redirectAttributes) {

return null;

}

@RequestMapping(value="/toUserMessagePage")

public String toUserMessagePage(final Model model) throws Exception    {

System.out.print("555555555555555555555555");

UserMessageForm userMessageForm = new UserMessageForm();

model.addAttribute("userMessageForm",userMessageForm);

storeCmsPageInModel(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

setUpMetaDataForContentPage(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

model.addAttribute(BREADCRUMBS_ATTR, accountBreadcrumbBuilder.getBreadcrumbs(TEXT_ACCOUNT_PROFILE));

model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS, ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

return ControllerConstants.Views.Pages.MultiStepCheckout.UserMessagePage;

}

@RequestMapping(value = "/saveUserData")

public String saveUserData(final Model model,final UserMessageForm userMessageForm) throws Exception   {

System.out.println("name"+"11111111111111111111111111111111111111111111111111111111111111111111");

boolean b = validateOrderForm(userMessageForm,model);

if(b==false){

model.addAttribute("userMessageForm",userMessageForm);

storeCmsPageInModel(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

setUpMetaDataForContentPage(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

model.addAttribute(BREADCRUMBS_ATTR, accountBreadcrumbBuilder.getBreadcrumbs(TEXT_ACCOUNT_PROFILE));

model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS, ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

return ControllerConstants.Views.Pages.MultiStepCheckout.UserMessagePage;

}

UserMessageData userMessageData = new UserMessageData();

String longtime = String.valueOf(new Date().getTime());

userMessageData.setUserMessageID(String.valueOf(new Date().getTime()));

userMessageData.setBirthday(userMessageForm.getBirthday());

userMessageData.setHobby(userMessageForm.getHobby());

userMessageData.setMoney(userMessageForm.getMoney());

userMessageData.setRemark(userMessageForm.getRemark());

userMessageData.setSex(userMessageForm.getSex());

userMessageData.setTelphone(userMessageForm.getTelphone());

userMessageData.setUserName(userMessageForm.getUserName());

model.addAttribute(new UserMessageForm());

System.out.println("name:"+userMessageData.getUserName()+"11111111111111111111111111111111111111111111111111111111111111111111");

userMessageFacade.doUserMessage(userMessageData);

storeCmsPageInModel(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

setUpMetaDataForContentPage(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

model.addAttribute(BREADCRUMBS_ATTR, accountBreadcrumbBuilder.getBreadcrumbs(TEXT_ACCOUNT_PROFILE));

model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS, ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

//        return ControllerConstants.Views.Pages.MultiStepCheckout.UserMessageSuccessPage; //对应的接口里添加相应的变量  String MikeDetailPage = "pages/account/MKDetailPage";

return "redirect:" +  "/userMessagePageList/listusers"; //对应的接口里添加相应的变量  String MikeDetailPage = "pages/account/MKDetailPage";

}

protected boolean validateOrderForm(final UserMessageForm userMessageForm, final Model model) {

//        final String securityCode = userMessageForm.getSecurityCode();

boolean invalid = false;

//校验用户名

if(null==userMessageForm.getUserName() ||  "".equals(userMessageForm.getUserName())){

GlobalMessages.addErrorMessage(model, "checkForm.error.userName");

return invalid;

}

/**

* 正则表达式:验证手机号

*/

final String REGEX_MOBILE = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";

if(!Pattern.matches(REGEX_MOBILE, userMessageForm.getTelphone())){

GlobalMessages.addErrorMessage(model, "checkForm.error.mobile");

return invalid;

}

//校验生日

final String REGEX_BRITHDAY = "YYYY/MM/DD";

final String birthday = userMessageForm.getBirthday();

if (null==birthday || "".equals(birthday) || birthday.length()!=10 || birthday.split("/").length!=3){

GlobalMessages.addErrorMessage(model, "checkForm.error.birthday");

return invalid;

}

String year = birthday.substring(0,4);

String month = birthday.substring(5,7);

String day = birthday.substring(8,10);

if(Integer.parseInt(year)<1900 || Integer.parseInt(year)>2018){

GlobalMessages.addErrorMessage(model, "checkForm.error.year");

return invalid;

}

if(Integer.parseInt(month)<=0 || Integer.parseInt(month)>12){

GlobalMessages.addErrorMessage(model, "checkForm.error.month");

return invalid;

}

if(Integer.parseInt(day)<=0 || Integer.parseInt(day)>31){

GlobalMessages.addErrorMessage(model, "checkForm.error.day");

return invalid;

}

if(null==userMessageForm.getMoney() || "".equals(userMessageForm.getMoney())){

GlobalMessages.addErrorMessage(model, "checkForm.error.money");

return invalid;

}

if(null==userMessageForm.getHobby() || "".equals(userMessageForm.getHobby())){

GlobalMessages.addErrorMessage(model, "checkForm.error.hobby");

return invalid;

}

//        if (getCheckoutFlowFacade().hasNoDeliveryAddress()) {

//            GlobalMessages.addErrorMessage(model, "checkout.deliveryAddress.notSelected");

//            invalid = true;

//        }

invalid = true;

return invalid;

}

@RequestMapping(value = "/getUserMessage")

@PreValidateQuoteCheckoutStep

@RequireHardLogIn

public String getUserMessage(@ModelAttribute("userMessageForm") final UserMessageForm userMessageForm, final Model model,

      final HttpServletRequest request, final RedirectAttributes redirectModel) throws CMSItemNotFoundException, // NOSONAR

InvalidCartException, CommerceCartModificationException{

//        return redirectToOrderConfirmationPage(userMessageData);

return "";

}

}

2. DefaultUserMessageFacade

package org.training.facades.userMessage.impl;

import de.hybris.platform.commercefacades.order.data.OrderHistoryData;

import de.hybris.platform.commercefacades.order.data.UserMessageData;

import de.hybris.platform.commercefacades.order.impl.DefaultCheckoutFacade;

import de.hybris.platform.commerceservices.search.pagedata.PageableData;

import de.hybris.platform.commerceservices.search.pagedata.SearchPageData;

import de.hybris.platform.converters.Converters;

import de.hybris.platform.core.enums.OrderStatus;

import de.hybris.platform.core.model.order.OrderModel;

import de.hybris.platform.core.model.user.CustomerModel;

import de.hybris.platform.servicelayer.dto.converter.Converter;

import de.hybris.platform.servicelayer.exceptions.UnknownIdentifierException;

import de.hybris.platform.servicelayer.model.ModelService;

import de.hybris.platform.store.BaseStoreModel;

import org.training.core.model.UserMessageCodeModel;

import org.training.core.userservice.UserMessageService;

import org.training.facades.populators.userPopulator.UserMessagePopulator;

import org.training.facades.userMessage.UserMessageFacade;

public class DefaultUserMessageFacade  extends DefaultCheckoutFacade implements UserMessageFacade {

private ModelService modelService ;

private UserMessageService userMessageService ;

private UserMessagePopulator userMessagePopulator;

@Override

public ModelService getModelService() {

return modelService;

}

@Override

public void setModelService(ModelService modelService) {

this.modelService = modelService;

}

private Converter<UserMessageCodeModel, UserMessageData> userMessagePageListtConverter;

public Converter<UserMessageCodeModel, UserMessageData> getUserMessagePageListtConverter() {

return userMessagePageListtConverter;

}

public void setUserMessagePageListtConverter(Converter<UserMessageCodeModel, UserMessageData> userMessagePageListtConverter) {

this.userMessagePageListtConverter = userMessagePageListtConverter;

}

public UserMessageService getUserMessageService() {

return userMessageService;

}

public void setUserMessageService(UserMessageService userMessageService) {

this.userMessageService = userMessageService;

}

public UserMessagePopulator getUserMessagePopulator() {

return userMessagePopulator;

}

public void setUserMessagePopulator(UserMessagePopulator userMessagePopulator) {

this.userMessagePopulator = userMessagePopulator;

}

@Override

public UserMessageCodeModel doUserMessage(UserMessageData userMessageData) {

UserMessageCodeModel userMessageCodeModel = new UserMessageCodeModel();      userMessageCodeModel.setUserMessageID(userMessageData.getUserMessageID());

userMessageCodeModel.setBirthday(userMessageData.getBirthday());

userMessageCodeModel.setHobby(userMessageData.getHobby());

userMessageCodeModel.setMoney(userMessageData.getMoney());

userMessageCodeModel.setRemark(userMessageData.getRemark());

userMessageCodeModel.setSex(userMessageData.getSex());

userMessageCodeModel.setTelphone(userMessageData.getTelphone());

userMessageCodeModel.setUserName(userMessageData.getUserName());

modelService.save(userMessageCodeModel);

return userMessageCodeModel;

}

@Override

public SearchPageData<UserMessageData> getPagedUserMessageListForStatuses(final PageableData pageableData,final String userMessageID,final String userName)

{

final SearchPageData<UserMessageCodeModel> userMessageResults = getUserMessageService().getUserMessagePageList(pageableData,userMessageID,userName);

  return convertPageData(userMessageResults, getUserMessagePageListtConverter());

}

protected <S, T> SearchPageData<T> convertPageData(final SearchPageData<S> source, final Converter<S, T> converter)

{

final SearchPageData<T> result = new SearchPageData<T>();

result.setPagination(source.getPagination());

result.setSorts(source.getSorts());

result.setResults(Converters.convertAll(source.getResults(), converter));

return result;

}

private static final String USERMESSAGE_NOT_FOUND_FOR_USER_AND_BASE_STORE = "USERMESSAGE with userMessageID %s not found for current user in current BaseStore";

@Override

public UserMessageData getUsserMessageDetailByID(String userMessageID) {

final UserMessageCodeModel userMessageCodeModel = userMessageService.getUsserMessageDetailByID(userMessageID);

if (userMessageCodeModel == null)

{

throw new UnknownIdentifierException(String.format(USERMESSAGE_NOT_FOUND_FOR_USER_AND_BASE_STORE, userMessageID));

}

UserMessageData userMessageData = new UserMessageData();

userMessagePopulator.populate(userMessageCodeModel,userMessageData);

return userMessageData;

}

}

3. trainingfacades-spring.xml

<alias name="defaultUserMessagePopulator" alias="userMessagePopulator"/>

<bean id="defaultUserMessagePopulator" class="org.training.facades.populators.userPopulator.UserMessagePopulator"  >

</bean>

<bean id="userMessagePageListtConverter" parent="abstractPopulatingConverter">

  <property name="targetClass" value="de.hybris.platform.commercefacades.order.data.UserMessageData"/>

  <property name="populators">

 <list>

<ref bean="userMessagePopulator"/>

 </list>

  </property>

</bean>

4. UserMessageServiceImpl

package org.training.core.userservice.impl;

import de.hybris.platform.commercefacades.order.data.UserMessageData;

import de.hybris.platform.commerceservices.search.pagedata.PageableData;

import de.hybris.platform.commerceservices.search.pagedata.SearchPageData;

import de.hybris.platform.core.enums.OrderStatus;

import de.hybris.platform.core.model.order.OrderModel;

import de.hybris.platform.core.model.user.CustomerModel;

import de.hybris.platform.store.BaseStoreModel;

import org.training.core.model.UserMessageCodeModel;

import org.training.core.userDao.UserMessageDao;

import org.training.core.userservice.UserMessageService;

import static de.hybris.platform.servicelayer.util.ServicesUtil.validateParameterNotNull;

public class UserMessageServiceImpl implements UserMessageService {

private UserMessageDao userMessageDao;

public UserMessageDao getUserMessageDao() {

return userMessageDao;

}

public void setUserMessageDao(UserMessageDao userMessageDao) {

this.userMessageDao = userMessageDao;

}

public SearchPageData<UserMessageCodeModel> getUserMessagePageList( final PageableData pageableData,final String userMessageID,final String userName)

{

return getUserMessageDao().findUserMessagePageListAndStore( pageableData,userMessageID,userName);

}

@Override

public UserMessageCodeModel getUsserMessageDetailByID(String userMessageID) {

UserMessageCodeModel userMessageCodeModel = userMessageDao.getUsserMessageDetailByIDAndStore(userMessageID);

return userMessageCodeModel;

}

}

5. UserMessageDaoImpl

package org.training.core.userDao.impl;

import com.ctc.wstx.util.StringUtil;

import de.hybris.platform.commercefacades.order.data.UserMessageData;

import de.hybris.platform.commerceservices.search.flexiblesearch.PagedFlexibleSearchService;

import de.hybris.platform.commerceservices.search.flexiblesearch.data.SortQueryData;

import de.hybris.platform.commerceservices.search.pagedata.PageableData;

import de.hybris.platform.commerceservices.search.pagedata.SearchPageData;

import de.hybris.platform.core.enums.OrderStatus;

import de.hybris.platform.core.model.order.OrderModel;

import de.hybris.platform.core.model.user.CustomerModel;

import de.hybris.platform.servicelayer.internal.dao.AbstractItemDao;

import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;

import de.hybris.platform.store.BaseStoreModel;

import org.apache.commons.collections.CollectionUtils;

import org.apache.commons.lang.ArrayUtils;

import org.apache.commons.lang.StringUtils;

import org.training.core.jalo.UserMessageCode;

import org.training.core.model.UserMessageCodeModel;

import org.training.core.userDao.UserMessageDao;

import java.util.*;

import static de.hybris.platform.servicelayer.util.ServicesUtil.validateParameterNotNull;

public class UserMessageDaoImpl extends AbstractItemDao implements UserMessageDao {

private static final String SORT_ORDERS_BY_DATE = " ORDER BY {" + UserMessageCode.BIRTHDAY+ "} DESC, {" + UserMessageCode.PK + "}";

private static final String SORT_ORDERS_BY_CODE = " ORDER BY {" + UserMessageCode.USERNAME + "}  DESC, {" + UserMessageCode.PK + "}";

private static final String FIND_USERMESSAGE_BY_CUSTOMER_STORE_QUERY = "SELECT { PK  } FROM {  UserMessageCode  }" ;

private static final String FIND_USERMESSAGE_DETAIL_BY_CUSTOMER_STORE_QUERY = "SELECT { PK  } FROM {  UserMessageCode  } where {UserMessageCode.userMessageID}=?userMessageID" ;

private static final String FIND_BY_ID_OR_NAME = "WHERE 1=1 " + " AND {" + UserMessageCode.USERMESSAGEID + "} = ?userMessageID " + " AND {" + UserMessageCode.USERNAME + "} like ?userName ";

private static final String FIND_BY_NAME = "WHERE 1=1 " +   " AND {" + UserMessageCode.USERNAME + "} like ?userName ";

private static final String FIND_BY_ID = "WHERE 1=1 " + " AND {" + UserMessageCode.USERMESSAGEID + "} = ?userMessageID "  ;

private PagedFlexibleSearchService pagedFlexibleSearchService;

public PagedFlexibleSearchService getPagedFlexibleSearchService() {

return pagedFlexibleSearchService;

}

public void setPagedFlexibleSearchService(PagedFlexibleSearchService pagedFlexibleSearchService) {

this.pagedFlexibleSearchService = pagedFlexibleSearchService;

}

@Override

public SearchPageData<UserMessageCodeModel> findUserMessagePageListAndStore( final PageableData pageableData,final String userMessageID,final String userName) {

final Map<String, Object> queryParams = new HashMap<String, Object>();

final List<SortQueryData> sortQueries;

String filterClause = StringUtils.EMPTY;

if(StringUtils.isEmpty(userMessageID) && StringUtils.isNotEmpty(userName)){

filterClause = FIND_BY_NAME;

queryParams.put("userName", "%"+userName+"%");

}else if(StringUtils.isEmpty(userName) && StringUtils.isNotEmpty(userMessageID)){

filterClause = FIND_BY_ID;

queryParams.put("userMessageID", userMessageID);

} else if(StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(userMessageID)){

filterClause = FIND_BY_ID_OR_NAME;

queryParams.put("userName", "%"+userName+"%");

queryParams.put("userMessageID", userMessageID);

}

sortQueries = Arrays .asList( createSortQueryData("byDate",  createQuery(FIND_USERMESSAGE_BY_CUSTOMER_STORE_QUERY, filterClause, SORT_ORDERS_BY_DATE)),

           createSortQueryData("byOrderNumber",                              createQuery(FIND_USERMESSAGE_BY_CUSTOMER_STORE_QUERY, filterClause, SORT_ORDERS_BY_CODE)));

return getPagedFlexibleSearchService().search(sortQueries, "byDate", queryParams, pageableData);

}

protected SortQueryData createSortQueryData(final String sortCode, final String query) {

final SortQueryData result = new SortQueryData();

result.setSortCode(sortCode);

result.setQuery(query);

return result;

}

protected String createQuery(final String... queryClauses) {

final StringBuilder queryBuilder = new StringBuilder();

  for (final String queryClause : queryClauses)  {

queryBuilder.append(queryClause);

}

return queryBuilder.toString();

}

@Override

public UserMessageCodeModel getUsserMessageDetailByIDAndStore(final String userMessageID) {

final Map<String, Object> queryParams = new HashMap<String, Object>();

queryParams.put("userMessageID", userMessageID);

final UserMessageCodeModel result = getFlexibleSearchService()  .searchUnique(  new FlexibleSearchQuery(FIND_USERMESSAGE_DETAIL_BY_CUSTOMER_STORE_QUERY ,  queryParams));

return result;

}

}

6. 

扩展一个字段操作步骤

1.在trainingcore-item.xml文件中找到typegroup和相应的itemtype,例如

<typegroup name="UserMessage">

<itemtype code="UserMessageCode" autocreate="true" generate="true" >

<description>UserMessageTable</description>

<deployment table="usermessageinfo" typecode="30001"></deployment>

<attributes>

<attribute qualifier="userMessageID" type="java.lang.String" >

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true" unique="true"/>

</attribute>

<attribute qualifier="userName" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="sex" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="birthday" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="money" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="hobby" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="telphone" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="remark" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

</attributes>

</itemtype>

</typegroup>

2. 在model中添加字段

<attribute qualifier="userMessageID" type="java.lang.String" >

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true" unique="true"/>

</attribute>

3. 在data中添加字段,打开trainingfacades-bean.xml文件,找到对应的data标签,添加相应的字段属性

<bean class="de.hybris.platform.commercefacades.order.data.UserMessageData">

  <property name="userMessageID" type="String" />

  <property name="userName" type="String"/>

  <property name="sex" type="String"/>

  <property name="birthday" type="String"/>

  <property name="money" type="String"/>

  <property name="hobby" type="String"/>

  <property name="telphone" type="String"/>

  <property name="remark" type="String"/>

</bean>

4. 在populator中也要加上相应的字段

public class UserMessagePopulator implements  Populator<UserMessageCodeModel, UserMessageData> {

.........(其他字段此处已省略)

...........

//userMessageCodeModel中的unique ID

if(null != userMessageCodeModel.getUserMessageID()){

userMessageData.setUserMessageID(userMessageCodeModel.getUserMessageID());

}

}

5. 

6. 运行ant all和hybrisserver.bat启动服务,登录http://127.0.0.1:9001后,执行update,只勾选第一项

7. 在controller中设置该字段的值到data中,在facade层将data转为model

8. 在页面增加对应显示该字段的标签

<ycommerce:testId code="orderHistoryItem_orderDetails_link">

<td>

  <a href="${userDetailURL}/${userMessage.userMessageID}">    ${userMessage.userMessageID}  </a>

</td>

<spring:url value="/userMessagePageList/userDetail" var="userDetailURL"/>

详情页操作步骤

1. 在list列表页面上找到要加超链接的字段,加上超链接的URL地址以及所携带的参数,例如

<ycommerce:testId code="orderHistoryItem_orderDetails_link">

<td>

  <a href="${userDetailURL}/${userMessage.userMessageID}">    ${userMessage.userMessageID}  </a>

</td>

<spring:url value="/userMessagePageList/userDetail" var="userDetailURL"/>

2. 在controller中添加方法,例如userDetail();

@RequestMapping(value = "/userDetail/" + UserMessage_CODE_PATH_VARIABLE_PATTERN, method = RequestMethod.GET)

@RequireHardLogIn

public String userDetail(@PathVariable("userMessageID") final String userMessageID, final Model model,

            final RedirectAttributes redirectModel) throws CMSItemNotFoundException{

final UserMessageData userMessageData = userMessageFacade.getUsserMessageDetailByID(userMessageID);

model.addAttribute("userMessageData", userMessageData);

storeCmsPageInModel(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

setUpMetaDataForContentPage(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

model.addAttribute(BREADCRUMBS_ATTR, accountBreadcrumbBuilder.getBreadcrumbs(TEXT_ACCOUNT_PROFILE));

model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS, ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

return ControllerConstants.Views.Pages.MultiStepCheckout.UserMessageDetailPage; //对应的接口里添加相应的变量  String MikeDetailPage = "pages/account/MKDetailPage";

}

private static final String UserMessage_CODE_PATH_VARIABLE_PATTERN = "{userMessageID:.*}";

3. 在controller中调用facade中的方法,例如getUsserMessageDetailByID()

private static final String USERMESSAGE_NOT_FOUND_FOR_USER_AND_BASE_STORE = "USERMESSAGE with userMessageID %s not found for current user in current BaseStore";

@Override

public UserMessageData getUsserMessageDetailByID(String userMessageID) {

final UserMessageCodeModel userMessageCodeModel = userMessageService.getUsserMessageDetailByID(userMessageID);

if (userMessageCodeModel == null)

{

throw new UnknownIdentifierException(String.format(USERMESSAGE_NOT_FOUND_FOR_USER_AND_BASE_STORE, userMessageID));

}

UserMessageData userMessageData = new UserMessageData();

userMessagePopulator.populate(userMessageCodeModel,userMessageData);

return userMessageData;

}

4. 在facade中注入populater,并生成getter和setter方法;并将userMessagePopulator注入到spring的配置文件中,例如在trainingfacades-spring.xml中加入userMessagePopulator属性

private UserMessagePopulator userMessagePopulator;

在trainingfacades-spring.xml中加入userMessagePopulator属性

<bean id="defaultUserMessageFacade" class="org.training.facades.userMessage.impl.DefaultUserMessageFacade" parent="defaultCheckoutFacade">

 <property name="modelService" ref="modelService" />

 <property name="userMessageService" ref="userMessageService" />

 <property name="userMessagePageListtConverter" ref="userMessagePageListtConverter" />

 <property name="userMessagePopulator" ref="userMessagePopulator"/>

</bean>

5. 在facade中调用service,service又调用了dao层,dao从数据库中取出一个model对象来,在facade层调用populater的populate()方法,将model转为data,然后将data返回给controller,而controller将data中的数据存放到model中,例如model.addAttribute("userMessageData", userMessageData);然后返回到详情页面,

6. 在详情页面使用 ${userMessageData.userMessageID}将数据展示出来

7. Service层的方法

@Override

public UserMessageCodeModel getUsserMessageDetailByID(String userMessageID) {

UserMessageCodeModel userMessageCodeModel = userMessageDao.getUsserMessageDetailByIDAndStore(userMessageID);

return userMessageCodeModel;

}

8. dao层的方法

@Override

public UserMessageCodeModel getUsserMessageDetailByIDAndStore(final String userMessageID) {

final Map<String, Object> queryParams = new HashMap<String, Object>();

queryParams.put("userMessageID", userMessageID);

final UserMessageCodeModel result = getFlexibleSearchService()

.searchUnique(

       new FlexibleSearchQuery(FIND_USERMESSAGE_DETAIL_BY_CUSTOMER_STORE_QUERY ,

               queryParams));

return result;

}

private static final String FIND_USERMESSAGE_DETAIL_BY_CUSTOMER_STORE_QUERY = "SELECT { PK  } FROM {  UserMessageCode  } where {UserMessageCode.userMessageID}=?userMessageID" ;

9. 运行ant all和hybrisserver.bat启动服务

10. 浏览器访问列表页https://electronics.local:9002/trainingstorefront/userMessagePageList/listusers然后再点击列表中的序号ID即可跳转到详情页面,可看到详情页面地址为例如

https://electronics.local:9002/trainingstorefront/electronics/zh/userMessagePageList/userDetail/1511489591750

条件搜索操作步骤

1. 在list列表页面添加搜索form表单,添加搜索框和搜索按钮,提交地址仍为分页列表的分页方法,注意:提交方式为get方式,以下是通过userMessageID和userName这俩个字段来条件查询的,因为ID是唯一的,所以可以通过ID来查询唯一,也可通过name来模糊查询多个记录,也可以什么都不输入查询所有,也可同时输入两个字段后来查询满足此条件的唯一记录.

<p>

<form:form action="${searchUserMessageURL}" id="userMessageSearchForm" commandName="userMessageSearchForm" method="get">

<spring:theme code="checkout.summary.userMessageID" />

<input type="text" id="userMessageID" name="userMessageID"  value="${userMessageID}" />

<spring:theme code="checkout.summary.userName" text="userName"/>

<input type="text" id="userName" name="userName"   value="${userName}"  />

<label>

<input  class="btn btn-primary btn-place-order btn-block" type="submit" id="submit" value="搜索"  />

</label>

</form:form>

</p>

在分页工具条的jsp标签内新定义一个提交的URL的set标签,此时searchUrl要引用该地址即可,地址仍为分页列表的方法地址,只是要带上新加的这两个参数

<spring:url value="/userMessagePageList/listusers" var="searchUserMessageURL"/>

<c:set var="searchUrl" value="/userMessagePageList/listusers?userName=${userName}&userMessageID=${userMessageID}"/>

<p class="account-orderhistory-pagination">

<nav:pagination top="true" msgKey="text.account.orderHistory.page" showCurrentPageInfo="true" hideRefineButton="true" supportShowPaged="${isShowPageAllowed}" supportShowAll="${isShowAllAllowed}" searchPageData="${searchPageData}" searchUrl="${searchUrl}"  numberPagesShown="${numberPagesShown}"/>

</p>

2. 在controller中分页列表的方法中新加这两个参数,并且把 required = false设为默认不需要,并且将传过来的两个参数add到model中去,使得页面参数在分页时数据回显,

@RequestMapping(value = "/listusers", method = RequestMethod.GET)

@RequireHardLogIn

public String listusers(@RequestParam(value = "page", defaultValue = "0") final int page,

        @RequestParam(value = "show", defaultValue = "Page") final ShowMode showMode,

        @RequestParam(value = "sort", required = false) final String sortCode, final Model model,

           @RequestParam(value = "userMessageID", required = false) final String userMessageID,

           @RequestParam(value = "userName",  required = false) final String userName)

throws CMSItemNotFoundException

model.addAttribute("userMessageID", userMessageID);

model.addAttribute("userName", userName);

final PageableData pageableData = createPageableData(page, 3, sortCode, showMode);

final SearchPageData<UserMessageData> searchPageData = userMessageFacade.getPagedUserMessageListForStatuses(pageableData,userMessageID,userName);

populateModel(model, searchPageData, showMode);

3. 在facade层,service层,dao层 的方法上均加上这两个字段的参数,例如service中的方法如下,

public SearchPageData<UserMessageCodeModel> getUserMessagePageList( final PageableData pageableData,final String userMessageID,final String userName)

{

return getUserMessageDao().findUserMessagePageListAndStore( pageableData,userMessageID,userName);

}

4. 在dao层的方法中进行逻辑判断并且将传过来的参数的值进行赋值,拼接到where条件之后

@Override

public SearchPageData<UserMessageCodeModel> findUserMessagePageListAndStore( final PageableData pageableData,final String userMessageID,final String userName){

final Map<String, Object> queryParams = new HashMap<String, Object>();

final List<SortQueryData> sortQueries;

String filterClause = StringUtils.EMPTY;

if(StringUtils.isEmpty(userMessageID) && StringUtils.isNotEmpty(userName)){

filterClause = FIND_BY_NAME;

queryParams.put("userName", "%"+userName+"%");

}else if(StringUtils.isEmpty(userName) && StringUtils.isNotEmpty(userMessageID)){

filterClause = FIND_BY_ID;

queryParams.put("userMessageID", userMessageID);

} else if(StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(userMessageID)){

filterClause = FIND_BY_ID_OR_NAME;

queryParams.put("userName", "%"+userName+"%");

queryParams.put("userMessageID", userMessageID);

}

sortQueries = Arrays

.asList(

       createSortQueryData("byDate",

               createQuery(FIND_USERMESSAGE_BY_CUSTOMER_STORE_QUERY, filterClause, SORT_ORDERS_BY_DATE)),

       createSortQueryData("byOrderNumber",

               createQuery(FIND_USERMESSAGE_BY_CUSTOMER_STORE_QUERY, filterClause, SORT_ORDERS_BY_CODE)));

return getPagedFlexibleSearchService().search(sortQueries, "byDate", queryParams, pageableData);

}

private static final String FIND_BY_ID_OR_NAME = "WHERE 1=1 " + " AND {" + UserMessageCode.USERMESSAGEID + "} = ?userMessageID " + " AND {" + UserMessageCode.USERNAME + "} like ?userName ";

private static final String FIND_BY_NAME = "WHERE 1=1 " +   " AND {" + UserMessageCode.USERNAME + "} like ?userName ";

private static final String FIND_BY_ID = "WHERE 1=1 " + " AND {" + UserMessageCode.USERMESSAGEID + "} = ?userMessageID "  ;

private static final String FIND_USERMESSAGE_BY_CUSTOMER_STORE_QUERY = "SELECT { PK  } FROM {  UserMessageCode  }" ;

5. 运行ant all,起服务hybrisserver.bat debug

6. 在地址栏中输入访问列表页面的路径https://electronics.local:9002/trainingstorefront/userMessagePageList/listusers在打开的列表页面上输入相关条件进行搜索,即可查询出相应的记录并且带着分页显示的.

表单信息的录入与提交保存操作步骤

1. 新建JSP页面,并引入页面的模板与组件,userMessagePage.jsp的内容如下

<%@ page trimDirectiveWhitespaces="true"   contentType="text/html;charset=UTF-8"  %>

<%@ taglib prefix="template" tagdir="/WEB-INF/tags/responsive/template"%>

<%@ taglib prefix="cms" uri="http://hybris.com/tld/cmstags"%>

<%@ taglib prefix="multi-checkout" tagdir="/WEB-INF/tags/responsive/checkout/multi"%>

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<spring:url value="/checkout/multi/summary/placeOrder" var="placeOrderUrl"/>

<spring:url value="/checkout/multi/termsAndConditions" var="getTermsAndConditionsUrl"/>

<%@ taglib prefix="ycommerce" uri="http://hybris.com/tld/ycommercetags" %>

<%--  --%>

<template:page pageTitle="${pageTitle}">

<p class="account-section">

<cms:pageSlot position="UserMessageComponent" var="feature" element="p" class="account-section-content">

<cms:component component="${feature}" />

</cms:pageSlot>

</p>

</template:page>

2. 新建组件页面,内容如下userComponentPage.jsp

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<%@ page trimDirectiveWhitespaces="true"  contentType="text/html;charset=UTF-8" %>

 <spring:url value="/checkout/multi/userMessage/saveUserData" var="saveUserDataURL"/>

<p>

<form:form action="${saveUserDataURL}" id="userForm" commandName="userMessageForm">

<p class="checkbox">

 <label>

  <spring:theme code="checkout.summary.userName" text="userName"/>

  <form:input type="text" id="userName" path="userName" />

  <input type="hidden" name="userNameNotNULL" id="userNameNotNULL" value="${model}">

 </label>

</p>

<p class="checkbox">

 <label>  <spring:theme code="checkout.summary.sex" text="sex"/>  </label>

 <label>

  <spring:theme code="checkout.summary.sex1" text="man"/>

  <input type="radio" name="sex"  value="1" checked />

  <spring:theme code="checkout.summary.sex2" text="woman"/>

  <input type="radio" name="sex" value="2" />

  <spring:theme code="checkout.summary.sex3" text="security"/>

  <input type="radio" name="sex" value="3" />

 </label>

</p>

<p class="checkbox">

 <label>

  <spring:theme code="checkout.summary.birthday" text="birthday"/>

  <form:input type="text" id="birthday" path="birthday"/>

  <input type="hidden" name="birthdayNotNULL" id="birthdayNotNULL" value="${model}">

</label>

</p>

<p class="checkbox">

 <label>  <spring:theme code="checkout.summary.money" text="money"/>   </label>

  <select type="select" id="money" name="money" />

  <option value="1">1000-2000</option>

  <option value="2"/>2000-3000</option>

  <option value="3"/>3000-4000</option>

  <option value="4"/>4000-5000</option>

  </select>

</p>

<p class="checkbox">

 <label>   <spring:theme code="checkout.summary.hobby" text="hobby"/>  </label>

 <label>  <spring:theme code="checkout.summary.hobby1" text="football"/>   </label>

 <label>  <input type="checkbox" id="hobby1" name="hobby" value="足球"/>  </label>

 <label>  <spring:theme code="checkout.summary.hobby2" text="basketball"/>   </label>

 <label>  <input type="checkbox" id="hobby2" name="hobby" value="篮球"/>  </label>

 <label> <spring:theme code="checkout.summary.hobby3" text="pingpang"/>   </label>

 <label>  <input type="checkbox" id="hobby3" name="hobby" value="乒乓球"/> </label>

 <label>  <spring:theme code="checkout.summary.hobby4" text="yumaoqiu"/>  </label>

 <label>  <input type="checkbox" id="hobby4" name="hobby" value="羽毛球"/>    </label>

 </p>

 <p class="checkbox">

  <label>

<spring:theme code="checkout.summary.telphone" text="telphone"/>    <form:input path="telphone" type="text" />

  </label>

 </p>

 <p class="checkbox">

  <label>

<spring:theme code="checkout.summary.remark" text="remark"/>  <form:input path="remark" type="text" />

  </label>

 </p>

 <p class="checkbox">

  <label>

<input  class="btn btn-primary btn-place-order btn-block" type="submit" id="submit" value="提交"  />

  </label>

  <label>   <input  class="btn btn-primary btn-place-order btn-block" type="reset" id="cancel"  value="取消"/>   </label>

</p>

</form:form>

</p>

3. 当点击提交按钮时,将表单内容提交至UserMessageController,在接收到表单数据后要校验数据合法性,

@Controller

@RequestMapping(value = "/checkout/multi/userMessage")

public class UserMessageController extends AbstractCheckoutStepController {

private final String QUOTE_DETAILS_CMS_PAGE = "userMessagePageID";

private final String TEXT_ACCOUNT_PROFILE = "text.account.profile";

private static final String BREADCRUMBS_ATTR = "breadcrumbs";

@Resource(name = "accountBreadcrumbBuilder")

private ResourceBreadcrumbBuilder accountBreadcrumbBuilder;

@Resource(name="defaultUserMessageFacade")

private UserMessageFacade userMessageFacade;

@Override

public String enterStep(Model model, RedirectAttributes redirectAttributes) throws CMSItemNotFoundException, CommerceCartModificationException {    return null;   }

@Override

public String back(RedirectAttributes redirectAttributes) {   return null;  }

@Override

public String next(RedirectAttributes redirectAttributes) {   return null;  }

@RequestMapping(value="/toUserMessagePage")

public String toUserMessagePage(final Model model) throws Exception    {

UserMessageForm userMessageForm = new UserMessageForm();

model.addAttribute("userMessageForm",userMessageForm);

storeCmsPageInModel(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

setUpMetaDataForContentPage(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

model.addAttribute(BREADCRUMBS_ATTR, accountBreadcrumbBuilder.getBreadcrumbs(TEXT_ACCOUNT_PROFILE));

model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS, ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

return ControllerConstants.Views.Pages.MultiStepCheckout.UserMessagePage;

}

@RequestMapping(value = "/saveUserData")

public String saveUserData(final Model model,final UserMessageForm userMessageForm) throws Exception   {

boolean b = validateOrderForm(userMessageForm,model);

if(b==false){

model.addAttribute("userMessageForm",userMessageForm);

storeCmsPageInModel(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

setUpMetaDataForContentPage(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

model.addAttribute(BREADCRUMBS_ATTR, accountBreadcrumbBuilder.getBreadcrumbs(TEXT_ACCOUNT_PROFILE));

model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS, ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

return ControllerConstants.Views.Pages.MultiStepCheckout.UserMessagePage;

}

UserMessageData userMessageData = new UserMessageData();

String longtime = String.valueOf(new Date().getTime());

userMessageData.setUserMessageID(String.valueOf(new Date().getTime()));

userMessageData.setBirthday(userMessageForm.getBirthday());

userMessageData.setHobby(userMessageForm.getHobby());

userMessageData.setMoney(userMessageForm.getMoney());

userMessageData.setRemark(userMessageForm.getRemark());

userMessageData.setSex(userMessageForm.getSex());

userMessageData.setTelphone(userMessageForm.getTelphone());

userMessageData.setUserName(userMessageForm.getUserName());

model.addAttribute(new UserMessageForm()); System.out.println("name:"+userMessageData.getUserName()+"1111111111111111111111111111111111111111111111111111111111111");

userMessageFacade.doUserMessage(userMessageData);

storeCmsPageInModel(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

setUpMetaDataForContentPage(model, getContentPageForLabelOrId(QUOTE_DETAILS_CMS_PAGE));

model.addAttribute(BREADCRUMBS_ATTR, accountBreadcrumbBuilder.getBreadcrumbs(TEXT_ACCOUNT_PROFILE));

model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS, ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

//        return ControllerConstants.Views.Pages.MultiStepCheckout.UserMessageSuccessPage; //对应的接口里添加相应的变量  String MikeDetailPage = "pages/account/MKDetailPage";

return "redirect:" +  "/userMessagePageList/listusers"; //对应的接口里添加相应的变量  String MikeDetailPage = "pages/account/MKDetailPage";

}

4. controller中引入facade,并在spring配置文件中也引入(trainingfacades-spring.xml),并定义要跳转到的页面的pageID即页面模板的ID

<bean id="defaultUserMessageFacade" class="org.training.facades.userMessage.impl.DefaultUserMessageFacade" parent="defaultCheckoutFacade">

 <property name="modelService" ref="modelService" />

 <property name="userMessageService" ref="userMessageService" />

 <property name="userMessagePageListtConverter" ref="userMessagePageListtConverter" />

 <property name="userMessagePopulator" ref="userMessagePopulator"/>

</bean>

5. controller调用UserFacade中的代码,将data转为model,service调用save()方法进行保存到数据库

@Override

public UserMessageCodeModel doUserMessage(UserMessageData userMessageData) {

UserMessageCodeModel userMessageCodeModel = new UserMessageCodeModel();

userMessageCodeModel.setUserMessageID(userMessageData.getUserMessageID());

userMessageCodeModel.setBirthday(userMessageData.getBirthday());

userMessageCodeModel.setHobby(userMessageData.getHobby());

userMessageCodeModel.setMoney(userMessageData.getMoney());

userMessageCodeModel.setRemark(userMessageData.getRemark());

userMessageCodeModel.setSex(userMessageData.getSex());

userMessageCodeModel.setTelphone(userMessageData.getTelphone());

userMessageCodeModel.setUserName(userMessageData.getUserName());

modelService.save(userMessageCodeModel);

return userMessageCodeModel;

}

6. 在UserFacade中引入service,并将service加入spring配置文件中(trainingfacades-spring.xml)和(trainingfacades-beans.xml)

 <bean id="defaultUserMessageFacade" class="org.training.facades.userMessage.impl.DefaultUserMessageFacade" parent="defaultCheckoutFacade">

 <property name="modelService" ref="modelService" />

 <property name="userMessageService" ref="userMessageService" />

 <property name="userMessagePageListtConverter" ref="userMessagePageListtConverter" />

 <property name="userMessagePopulator" ref="userMessagePopulator"/>

</bean>

trainingfacades-beans.xml中的配置如下

<bean class="de.hybris.platform.commercefacades.order.data.UserMessageData">

  <property name="userMessageID" type="String" />

  <property name="userName" type="String"/>

  <property name="sex" type="String"/>

  <property name="birthday" type="String"/>

  <property name="money" type="String"/>

  <property name="hobby" type="String"/>

  <property name="telphone" type="String"/>

  <property name="remark" type="String"/>

</bean>

7. 在trainingcore-items.xml中创建数据库的data

<typegroup name="UserMessage">

<itemtype code="UserMessageCode" autocreate="true" generate="true" >

<description>UserMessageTable</description>

<deployment table="usermessageinfo" typecode="30001"></deployment>

<attributes>

<attribute qualifier="userMessageID" type="java.lang.String" >

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true" unique="true"/>

</attribute>

<attribute qualifier="userName" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="sex" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="birthday" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="money" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="hobby" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="telphone" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

<attribute qualifier="remark" type="java.lang.String">

   <persistence type="property"></persistence>

   <modifiers optional="true" write="true" read="true"/>

</attribute>

</attributes>

</itemtype>

</typegroup>

8. 在trainingcore-spring.xml中加入i18n

<alias alias="userMessageService" name="userMessageService"/>

<bean id="userMessageService"

class="org.training.core.userservice.impl.UserMessageServiceImpl">

  <property name="userMessageDao" ref="userMessageDao"/>

</bean>

<bean name="userMessageDao" class="org.training.core.userDao.impl.UserMessageDaoImpl">

  <property name="pagedFlexibleSearchService" ref="pagedFlexibleSearchService"/>

  <property name="flexibleSearchService" ref="flexibleSearchService"/>

  <property name="modelService" ref="modelService"/>

</bean>

9. 创建完data后,要运行ant all,起服务hybrisserver.bat  debug

10. 浏览器访问https://electronics.local:9002/trainingstorefront/checkout/multi/userMessage/toUserMessagePage页面即可填写用户信息进行提交,提交地址为https://electronics.local:9002/trainingstorefront/checkout/multi/userMessage/saveUserData

成功后到成功页面或列表页面

搭建B2C商城步骤

1. 解压文件HYBRISCOMM6500P_3-80003045.ZIP

2. 进入解压目录,cd C:\hybrise65003\hybris\bin\platform

3. 运行setantenv.bat设置环境变量

4. 执行 ant clean 出现下图

5. 选择develop回车,基本的开发模块如config等文件随即生成在hybris目录下了,与bin目录同级.

6. 结果如下图,

7. 安装b2c商城,在installer文件夹下执行(cd C:\hybrise65003\installer)install.bat -r b2c_acc

8. 生成扩展,回到bin目录下(cd C:\hybrise65003\hybris\bin\platform),运行ant modulegen,接下来会看到如下图所示,要求你选择模板为[accelerator]后回车然后选择输入新建项目名称以traing开头的,回车输入包名,默认新建的包名是org.traing,回车,你将看到如下结果

9. 控制台结果为:删除C:\hybrise65003\hybris\config/localextensions.xml这个文件中的yacceleratorfulfilmentprocess,yacceleratorcockpits,yacceleratorcore,yacceleratorfacades,yacceleratortest,yacceleratorinitialdata,yacceleratorstorefront,apparelstore(最后这个模块是与卖服装有关的,在这里也去掉)这几个部分,并且添加以下7个模块

<extension name='trainingfulfilmentprocess' />

<extension name='trainingcockpits' />

<extension name='trainingcore' />

<extension name='trainingfacades' />

<!--  <extension name='trainingtest' />  -->此行注掉,因为他里面有依赖服装的东西

<extension name='traininginitialdata' />

<extension name='trainingstorefront' />

10. 重新运行ant clean all

11. 初始化数据,运行ant initialize -Dtenant=master(参数为主线程)

12. 启动服务运行hybrisserver.bat

13. 浏览器访问https://electronics.local:9002/trainingstorefront打开商城首页如图

相关阅读

6个方面,总结B端IT咨询项目的实施流程

笔者在文中分享了他参与的一个B端IT咨询项目的实施流程,并分析了复盘后的心得体会。我做过的IT咨询项目不少,可真正收费的IT项目并

[算法总结] 二分查找

本文首发于我的个人博客:尾尾部落 二分查找法作为一种常见的查找方法,将原本是线性时间提升到了对数时间范围,大大缩短了搜索时间

ActiveMQ的作用总结(应用场景及优势)

业务场景说明:消息队列在大型电子商务类网站,如京东、淘宝、去哪儿等网站有着深入的应用,队列的主要作用是消除高并发访问高峰,加快

座头鲸识别比赛(Humpback Whale Identification)总结

Kaggle主办的座头鲸识别的比赛,持续了3个月,终于结束了。恭喜那些拿到金牌的团队,他们算法模型确实很出色。 比赛网站链接:https://w

SDRAM使用总结

最近stm32学到使用SDRAM了,板载SDRAM为IS42S16400J。SDRAM为一种可以运行存储在存储器上的代码的存储器,stm32内部有2M的代码运行空

分享到:

栏目导航

推荐阅读

热门阅读