Eclipse IDE で mvc を使用して 1 つのカスタム ポートレットを開発しています。
以下は私のシナリオです:
テーブル名が1つ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
たものが 1 つのテーブルに挿入され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);
}