DAO层: public interface AutoFZmessageMapper extends Mapper<AutoFZmessage>,IdsMapper<AutoFZmessage>,InsertListMapper<AutoFZmessage> { int batchInsert(List<AutoFZmessage> list); }
mapper.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.kinghis.burster.dao.test.AutoFZmessageMapper"> <insert id="batchInsert"> INSERT INTO AutoFZmessage (id,mdc,drg,detail,drgsFlag) VALUES <foreach collection="list" item="item" separator=","> (#{item.id},#{item.mdc},#{item.drg},#{item.detail},#{item.drgsFlag}) </foreach> </insert> </mapper>
服务层调用:
public int manyMedicalRecordGroup(List<SingleCalculateModel> list) { List<AutoFZmessage> la=new ArrayList<>(); try{ for (SingleCalculateModel singleCalculate : list) { JSONObject json= JSONUtil.toJSONObject(singleCalculate); DrgsArithService drgsArithService = (DrgsArithService) SpringUtil.getBean("drgsArithService"); String result = drgsArithService.fzq(json.toString()); JSONObject jsonObj = JSONObject.parseObject(result); Map<String, Object> outMap = jsonObj.getInnerMap(); AutoFZmessage resultSign=new AutoFZmessage(); resultSign.setDrg(outMap.get("drgid").toString()); resultSign.setMdc(outMap.get("mdcid").toString()); resultSign.setDrgsFlag(outMap.get("result").toString()); resultSign.setDetail(outMap.get("error_msg").toString()); resultSign.setId(singleCalculate.getId()); la.add(resultSign); } this.autoFZmessageMapper.batchInsert(la); }catch(Exception e){ e.printStackTrace(); } return 0; }