> Hello World !!!

     

@syaku

Spring myBATIS forEach : 스프링 프레임워크

반응형

written by Seok Kyun. Choi. 최석균


myBATIS forEach

myBATIS Mapper

  <insert id="insertForeach">
    INSERT INTO spring_options_data (
      opts_idx, data_name, data_value, data_type, data_memo
    ) VALUES 
    <foreach item="item" collection="optionsDataVOList" separator=",">
      ( #{opts_idx}, #{item.data_name}, #{item.data_value}, #{item.data_type}, #{item.data_memo} )
    </foreach>
  </insert>

myBATIS Mapper interface

@Repository(value = "optionsDataMapper")
public interface OptionsDataMapper {
    void insertForeach(@Param("opts_idx") int opts_idx, @Param("optionsDataVOList") List<OptionsDataVO> optionsDataVOList);
}

Spring DAO

@Repository(value = "optionsDataDao")
public class OptionsDataDao {

    @Resource(name = "optionsDataMapper")
    private OptionsDataMapper optionsDataMapper;

    public void insertForeach(int opts_idx, List<OptionsDataVO> optionsDataVOList) {
        this.optionsDataMapper.insertForeach(opts_idx, optionsDataVOList);
    }
}

Spring Service

@Service(value = "optionsService")
public class OptionsService {

    @Autowired
    OptionsDataDao optionsDataDao;

    @Transactional
    public void insertOptions(Integer opts_idx, List<OptionsDataVO> optionsDataVOList) {
        optionsDataDao.insertForeach(opts_idx, optionsDataVOList);
    }
}


posted syaku blog

Syaku Blog by Seok Kyun. Choi. 최석균.

http://syaku.tistory.com


반응형