[Spring MVC + 休眠]
@控制器
@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);
}
}
在控制器中,我编写循环多次输入记录,但以下不起作用,它只插入一条记录。
for(int i=0; i<50; i++){
coaMaintenanceService.AddCOAMaintenance(coaMaintenanceModel);
}
上述场景中的多条记录如何输入!