Integration with General mapper of springboot

pom.xml files found springboot works under the import dependency as follows jar package

<! - Configure Universal Mapper start ->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.1.5</version>
        </dependency>
        <! - Universal Mapper end ->

UserDao configuration interfaces, inheritance universal mapper, note generics

@Repository
public interface UserDao extends Mapper<User> {
 
}

Service implementation layer

@Service("userService")
public calss UserServiceImpl implements UserService{
    @Autowired
    private UserDao userDao;

    @Override
    public List<User> list(){
    return userDao.selectALL();
    }

}
    

User entity class configuration file mapper common primary key and primary key return policy

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private  String name;
    private  Integer age;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

}

Configuring Application inlet Class

tk.mybatis.spring.annotation.MapperScan Import; // the introduction path MapperScan replaced tk.mybatis.spring.annotation.MapperScan 
Import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableTransactionManagement // Open House latest version management mode annotation may be omitted 
@MapperScan ( " com.xz.springboot.mapper " ) // scan all the interfaces and the packet interface implementation class for the generated 
public  class Springboot01Application {

    public static void main(String[] args) {
        SpringApplication.run(Springboot01Application.class, args);
    }

}

 

 

Guess you like

Origin www.cnblogs.com/sitian2050/p/11824825.html