第一步:
创建工程添加3个依赖 Lombok,MySQL Driver,JDBC API
第二步:
在application.properties指定数据源
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/hhh
spring.datasource.username=root
spring.datasource.password=root
# 编译前always编译后never
spring.sql.init.mode=never
第三步:
在测试方法中编写
@SpringBootTest
class Springb00t09JdbcTplApplicationTests {
// 注入模版类
@Resource
private JdbcTemplate jdbcTemplate;
// 修改c_1表
@Test
public void test03(){
String sql="update c_1 set name=? where id=?";
//调update方法 传入sql语句,给占位符赋值
int jl = jdbcTemplate.update(sql, "泥猴奥", 3);
System.out.println("返回记录条数:"+jl);
}
}
运行结果
返回记录条数:1
使用JdbcTemplate修改表表单数据
最新推荐文章于 2024-07-28 19:41:52 发布