repositories {
...
maven { url "https://raw.githubusercontent.com/jgaybjone/mvnrepo/master" }
mavenCentral()
}
dependencies {
//下面根据情况三选一
compile 'cn.jgayb:mybatis-service:1.3-RELEASE' //mybatis项目使用
compile 'cn.jgayb:tk-mybatis-service:1.4-RELEASE' //通用mapper项目使用
compile 'cn.jgayb:jpa-service:1.3-RELEASE' //spring data jpa项目使用
}
<repositories>
<repository>
<id>jgayb</id>
<name>jgayb Repository</name>
<url>https://raw.githubusercontent.com/jgaybjone/mvnrepo/master</url>
</repository>
</repositories>
<dependencies>
<!--下面根据情况三选一 -->
<dependency>
<groupId>cn.jgayb</groupId>
<artifactId>mybatis-service</artifactId>
<version>1.3-RELEASE</version>
</dependency>
<dependency>
<groupId>cn.jgayb</groupId>
<artifactId>tk-mybatis-service</artifactId>
<version>1.4-RELEASE</version>
</dependency>
<dependency>
<groupId>cn.jgayb</groupId>
<artifactId>jpa-service</artifactId>
<version>1.3-RELEASE</version>
</dependency>
</dependencies>
public interface UserMapper extends IMapper<User> {
User selectById(String id);
void update(User user);
}
@Service
public class UserServiceImpl implements UserService{
@Autowird
private UserMapper userMapper;
@Override
public UserMapper getMapper(){
return this.userMapper;
}
@Override
@Transactional
public void crudAndConsumer(Consumer<UserMapper> consumer){
consumer.accept(userMapper);
}
...
}
public interface UserMapper extends BaseMapper<User> {
/**
* 通用mapper已经很有很多方法了
*/
UserDto selectById(String id);
}
@Service
public class UserServiceImpl implements UserService{
@Autowird
private UserMapper userMapper;
@Override
public UserMapper getMapper(){
return this.userMapper;
}
@Override
@Transactional
public void crudAndConsumer(Consumer<UserMapper> consumer){
consumer.accept(userMapper);
}
...
}
public interface UserService extends BaseService<User, String, UserRepository> {
}
@Service
public class UserServiceImpl implements UserService{
@Autowird
private UserRepository userRepository;
@Override
public UserRepository getRepository(){
return this.userRepository;
}
@Override
@Transactional
public void crudAndConsumer(Consumer<UserRepository> consumer){
consumer.accept(userRepository);
}
...
}