提交 931986aa 编写于 作者: 武汉红喜's avatar 武汉红喜

transaction

上级 b583f245
......@@ -6,7 +6,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
@EnableScheduling
@SpringBootApplication
@EnableConfigurationProperties({UserConfig.class})
......
......@@ -3,6 +3,8 @@ package org.hongxi.whatsmars.spring.boot.service;
import com.github.pagehelper.Page;
import org.hongxi.whatsmars.spring.boot.model.User;
import java.util.List;
/**
* Created by shenhongxi on 2017/6/26.
*/
......@@ -18,4 +20,8 @@ public interface UserService {
Page<User> query(int offset, int limit);
void insertBatch(List<User> users);
void add(List<User> users);
}
......@@ -9,6 +9,9 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* Created by shenhongxi on 2017/6/21.
......@@ -46,4 +49,17 @@ public class UserServiceImpl implements UserService {
public Page<User> query(int offset, int limit) {
return PageHelper.offsetPage(offset, limit).doSelectPage(() -> userMapper.query());
}
@Override
public void insertBatch(List<User> users) {
userMapper.insertBatch(users);
}
@Transactional
@Override
public void add(List<User> users) {
for (User user : users) {
userMapper.insert(user);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册