[Spring MVC + Hibernate]
@コントローラ
@Controller
public class COAMaintenanceController {
protected static Logger log = Logger
.getLogger(COAMaintenanceController.class);
@Resource(name = "COAMaintenanceService")
private COAMaintenanceService coaMaintenanceService;
@RequestMapping(value = "/addCoaMaintenance", method = RequestMethod.POST)
public @ResponseBody
JsonResponse addCoaCategory(@RequestParam("mainAccount") long mainAccount,
@RequestParam("subAccount") long subAccount,
@RequestParam("accountName") String accountName,
@RequestParam("coaCategoryId") long coaCategoryId,
@RequestParam("postingType") int postingType,
@RequestParam("typicalBalance") int typicalBalance,
@RequestParam("isActive") int isActive) {
Date sysdate = null;
JsonResponse response = null;
try {
sysdate = new Date();
response = new JsonResponse();
COAMaintenanceModel coaMaintenanceModel = new COAMaintenanceModel(
mainAccount, subAccount, accountName, coaCategoryId,
postingType, typicalBalance, isActive,
GetSessionValue.getSysUserId(),
GetSessionValue.getSysUserIp(), sysdate, 0);
coaMaintenanceService.AddCOAMaintenance(coaMaintenanceModel);
response.setStatus("Success");
} catch (Exception ex) {
log.error("Exception.." + ex);
response.setStatus("Fail");
}
return response;
}
}
@サービス
@Service("COAMaintenanceService")
@Transactional
public class COAMaintenanceService {
@Resource(name="sessionFactory")
private SessionFactory sessionFactory;
public void AddCOAMaintenance(COAMaintenanceModel obj) {
Session session = sessionFactory.getCurrentSession();
session.save(obj);
}
}
コントローラーで、レコードを複数回入力するループを記述しますが、次のコードは機能しません。レコードを 1 つだけ挿入します。
for(int i=0; i<50; i++){
coaMaintenanceService.AddCOAMaintenance(coaMaintenanceModel);
}
上記のシーンで複数のレコードを入力する方法!