Position:Home > Mybatis 批量插入、模糊查询

Mybatis 批量插入、模糊查询

一、mybatis批量插入数据private void saveTicketServiceImpl(int count) {

List<Ticket> ticketList=new ArrayList<Ticket>();

for (int i = 1,i <= count; i++){

Ticket ticket = new Ticket();

ticket.setNumber("MG--" + count);

ticketList.add(ticket);

}

ticketMapper.insertTickList(ticketList);} ------------------TicketMapper.xml--------------------------<insert id=" insertTickList" parameterType="java.util.List">

insert into ticket(id,number,create_time)

VALUES

<foreach collection="list" item="item" index= "index" separator="," >

( #{item.id},

#{item.number},

now())

</foreach></insert> 二、mybatis模糊查询(***.xml)name like CONCAT('%',#{name},'%') 

Recommend:mybatis做like模糊查询

这个网站中有很多方法。https://code.google.com/p/mybatis/issues/detailid=85 自己试验了如下的方法。   1.  参数中直接加入%%   param.setUsername("%CD%");       param.setPassword("%11%"); <select id="selectPersons" resul

Your Answer
(Ctrl+Enter To Post)   
    Copyright © 2015-2017 163JAVA.COM All Rights Reserved.