public class Country {
//实体类参考本人博客地址:https://blog.youkuaiyun.com/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