Full Stack Web Developer.
Syaku (샤쿠)

Java, JS (ES6+), Spring, Spring security, jQuery, Reactjs, Bootstrap.

        

02-26 17:26


Spring Boot 2 보기 Front-end 보기 DevOps 보기 Spring 3 보기 Spring Security 3 보기

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


댓글 남기기
◀ PREV 1···202122232425262728···37 NEXT ▶