springboot how things annotation mode

1. Add notes @EnableTransactionManagement start in class Application 

tk.mybatis.spring.annotation.MapperScan Import; 
Import org.springframework.boot.SpringApplication; 
Import org.springframework.boot.autoconfigure.SpringBootApplication; 
Import org.springframework.transaction.annotation.EnableTransactionManagement; 

@SpringBootApplication 
@EnableTransactionManagement // open House annotation management model the latest version can be omitted 
@MapperScan ( " com.xz.springboot.mapper " ) // scans the package at all interfaces and classes that implement the interface generates 
public  class Springboot01Application { 

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

}

2. Add in the business layer @Transactional

import com.xz.springboot.bean.User;
import com.xz.springboot.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {
        @Autowired
        private UserMapper userMapper;

        public List<User> queryAll(){
            System.out.println("热部署");
            return userMapper.findAll();
        }
    @Transactional
    public void deleteById(Integer id) {
           userMapper.deleteById(id);
         //  int c=10/0;
    }
}

 

Guess you like

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