對於List<T> 咱們先來一個簡單的說明html
List<T> :表示的是List集合中的元素都爲T類型,具體類型在運行期決定;List<T>能夠進行諸如add、remove等操做,由於它的類型是固定的T類型,在編碼期 不須要進行任何的轉型操做。java
想更多瞭解:轉載:Java中List<T>和List<?>的區別spring
在這裏 這個T是一個對象:json
public class ContractErrorLog implements Serializable {
private java.lang.Long id;//
private java.lang.Long borrowId;//
private java.lang.Long debtId;//
private java.lang.String docTitle;//
private java.lang.String customerId;//
private java.lang.Object json;//
private java.lang.String status;//
private java.lang.String isDel;//
private java.lang.String createTime;//
//省略get和set
}
Controller層app
//注入
@Autowired
private IContractErrorLogService contractErrorLogService;
//插入日誌集合 @RequestMapping("xxx_copy") @ResponseBody public JSONObject autoSign(HttpServletRequest request,HttpServletResponse response){ List<ContractErrorLog> errorLogs = new ArrayList<ContractErrorLog>(); ContractErrorLog errorLog1 = new ContractErrorLog(); ..... ContractErrorLog errorLog2 = new ContractErrorLog(); ..... ContractErrorLog errorLog3 = new ContractErrorLog(); ..... ContractErrorLog errorLog4 = new ContractErrorLog(); ..... ContractErrorLog errorLog5 = new ContractErrorLog(); .....//set值的部分省略 contractErrorLogService.insertList(errorLogs); }
接口IContractErrorLogService dom
public interface IContractErrorLogService extends IBaseService<ContractErrorLog>{ public Integer insertList(List<ContractErrorLog> list); }
IContractErrorLogService的實現類ide
package com.service.impl; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import com.alibaba.dubbo.config.annotation.Service;import com.mapper.ContractErrorLogMapper; import com.service.IContractErrorLogService; @Service(interfaceClass=IContractErrorLogService.class, timeout=30000, retries = 1) public class ContractErrorLogServiceImpl extends BaseServiceImpl<ContractErrorLog> implements IContractErrorLogService{ @Autowired private ContractErrorLogMapper mapper; @Override public Integer insertList(List<ContractErrorLog> arg0) { // TODO Auto-generated method stub return mapper.insertList(arg0); } }
MyBatis 接口對應的方法post
@MyBatisRepository public interface ContractErrorLogMapper extends BaseMapper<ContractErrorLog> { public Integer insertList(List<ContractErrorLog> list); }
ContractErrorLogMapper.xml編碼
<!--批量 插入記錄 --> <insert id="insertList" parameterType="java.util.ArrayList"> insert into T_CONTRACT_ERROR_LOG(id,borrow_id,debt_id,doc_title,customer_id,json,status,is_del,create_time) values <foreach collection="list" item="item" index="index" separator=","> (#{item.id},#{item.borrowId},#{item.debtId},#{item.docTitle},#{item.customerId},#{item.json},#{item.status},#{item.isDel},now()) </foreach> </insert>
<resultMap id="BaseResultMap" type="com.domain.ContractErrorLog" > <result column="id" property="id"/> <result column="borrow_id" property="borrowId"/> <result column="debt_id" property="debtId"/> <result column="doc_title" property="docTitle"/> <result column="customer_id" property="customerId"/> <result column="json" property="json"/> <result column="status" property="status"/> <result column="is_del" property="isDel"/> <result column="create_time" property="createTime"/> </resultMap>