我正在 Eclipse IDE 中使用 mvc 开发一个自定义 portlet。
以下是我的场景:
我有一个表名restaurant
,从addrestaurant.jsp
页面开始,我在餐厅表中添加数据。
在我的addrestaurant.jsp
页面中,我有以下选择控件代码,它需要选择多个值:
<label>Select Ad Type<span class="f_req">*</span></label>
<select data-placeholder="- Select Ad Type -" class="chzn-select" multiple name="ad_type" value="<%=restaurantOBJ.getAdtypeId()%>">
<option value="1">Standby Ad</option>
<option value="2">Homepage Ad</option>
<option value="3">Slider Ad</option>
<option value="4">Event Based Ad</option>
</select>
现在这个adtype
选择的addrestaurant.jsp
将被插入到一个rest_map_adtype
表中,我想将这些选择的值与最后创建的餐厅主键的引用一起添加。
那么我怎样才能得到restaurant
最后编辑的主键
更多解释让我给出一些代码片段:
public void addRestaurant(ActionRequest request, ActionResponse response) {
log.info("Inside addRegistration");
List<String> errors = new ArrayList<String>();
restaurant rest = RestaurantActionUtil
.getRestaurantFromRequest(request);
boolean restValid = RestaurantValidator
.validateRestaurant(rest, errors);
if (restValid) {
try {
log.info(rest);
restaurant test = restaurantLocalServiceUtil
.addrestaurant(rest);
//Above Code will add the all data which is in my addrestaurant.jsp accept just selected control values
String[] adtype_ID=request.getParameterValues("ad_Type");
//here am taking the select tag's multiple value in one string array
因此,在这一行之后,我需要将rest_map_Adtype
表中的所有值添加到餐厅主键的引用中,该主键是使用addrestaurant(rest)
上面一行的方法创建的。
我怎样才能使它成为可能?
或者在表中插入行后如何获得主键?
我的 ActionUtil.class 如下
public restaurant addRestaurant(restaurant restParam) {
restaurant restVar;
try {
restVar = restaurantPersistence.create(counterLocalService
.increment(restaurant.class.toString()));
} catch (SystemException e) {
e.printStackTrace();
return restVar = null;
}
try {
resourceLocalService.addResources(restParam.getGroupId(),restParam.getGroupId(), restParam.getUserId(),
restaurant.class.getName(),restParam.getPrimaryKey(), false,true,true);
} catch (PortalException e) {
e.printStackTrace();
return restVar = null;
} catch (SystemException e) {
e.printStackTrace();
return restVar = null;
}
restVar.setName(restParam.getName());
restVar.setAdress(restParam.getAdress());
restVar.setCity(restParam.getCity());
restVar.setPin(restParam.getPin());
restVar.setState(restParam.getState());
restVar.setCountry(restParam.getCountry());
restVar.setContactno(restParam.getContactno());
restVar.setEmail(restParam.getEmail());
restVar.setWebsite(restParam.getWebsite());
restVar.setCuisinetype(restParam.getCuisinetype());
restVar.setPersonalmail(restParam.getPersonalmail());
restVar.setPersonalname(restParam.getPersonalname());
restVar.setPersonalPhone(restParam.getPersonalPhone());
restVar.setNoofemenuagent(restParam.getNoofemenuagent());
restVar.setLicensekey(restParam.getLicensekey());
restVar.setRestregId(restParam.getRestregId());
restVar.setNoofdiningtable(restParam.getNoofdiningtable());
restVar.setAvgnoofcustomermonthly(restParam.getAvgnoofcustomermonthly());
restVar.setAveragroupagevisit(restParam.getAveragroupagevisit());
restVar.setImpoflocation(restParam.getImpoflocation());
restVar.setAvgmonthlycheckamount(restParam.getAvgmonthlycheckamount());
restVar.setCostperthousandimpression(restParam.getCostperthousandimpression());
restVar.setAdtypeId(restParam.getAdtypeId());
//restVar.setNoofdiningtable(restParam.getNoofdiningtable());
//restVar.setAvgnoofcustomermonthly(restParam.getAvgnoofcustomermonthly());
restVar.setIsactive(restParam.getIsactive());
restVar.setCreateddate(restParam.getCreateddate());
restVar.setLastmodifiedby(restParam.getLastmodifiedby());
restVar.setModifieddate(restParam.getModifieddate());
restVar.setGroupId(restParam.getGroupId());
restVar.setUserId(restParam.getUserId());
restVar.setIsdeleted(restParam.getIsdeleted());
restVar.setRestregId(restParam.getRestregId());
//restVar.setOrganizationId(restParam.getOrganizationId());
try {
return restaurantPersistence.update(restVar, false);
} catch (SystemException e) {
e.printStackTrace();
return restVar = null;
}
}
以下是我的对象餐厅,添加餐厅后返回以下值 {restId=0, name=aaaa, isactive=false, userId=10158, groupId=10180, createddate=Fri Oct 26 12:40:53 GMT 2012, lastmodifiedby=10158, modifieddate=Fri Oct 26 12:40:53 GMT 2012, restregId=12333, adress=, city=AHMEDABAD, pin=, state=, country=, contactno=, email=, website=, cuisinetype=, noofemenuagent=0, personalname=, personalPhone=, personalmail=, adtypeId=0, isdeleted=false, licensekey=12333, noofdiningtable=0, averagroupagevisit=0, impoflocation=, avgnoofcustomermonthly=0, avgmonthlycheckamount=0, costperthousandimpression=0.0}
restaurantLocalServiceUtil 类
public static emenu.advertise.database.model.restaurant addrestaurant(
emenu.advertise.database.model.restaurant restaurant)
throws com.liferay.portal.kernel.exception.SystemException {
return getService().addrestaurant(restaurant);
}
/**
* Creates a new restaurant with the primary key. Does not add the restaurant to the database.
*
* @param restId the primary key for the new restaurant
* @return the new restaurant
*/
public static emenu.advertise.database.model.restaurant createrestaurant(
long restId) {
return getService().createrestaurant(restId);
}