springboot集成mybatis添加注解事务

public class Country {
    //实体类参考本人博客地址:https://blog.csdn.net/yl_hahha/article/details/80208161
    private long id;
    private String countryname;
    private String countrycode;
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getCountryname() {
        return countryname;
    }
    public void setCountryname(String countryname) {
        this.countryname = countryname;
    }
    public String getCountrycode() {
        return countrycode;
    }
    public void setCountrycode(String countrycode) {
        this.countrycode = countrycode;
    }
    @Override
    public String toString() {
        return "Country [id=" + id + ", countryname=" + countryname + ", countrycode=" + countrycode + "]";
    }
}

/**
* service层是给controller调用,如果想写需要将dao包装成service,然后实现类来调用dao 来提供给controller调用
* Invalid bound statement (not found)
* 解决方法: @MapperScan(“com.demomybatistransational.demo”)
*/
public interface CountryMapper {

public int update(@Param("countryname") String countryname,@Param("id")long id);

}

@Service
public class CountryServiceImpl {
    @Autowired(required = false)
    private CountryMapper mapper;
    @Transactional
    public void testUpdate(){
        long id =2;
         mapper.update("dq",id);
         int i=1/0;
         mapper.update("hh",id);
    }
}

@SpringBootApplication
@MapperScan(“com.demomybatistransational.demo”)
public class DemoApplication {

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

}

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.show-sql=true

mybatis.type-aliases-package=com.demomybatistransational.demo

项目地址,点击

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值