springboot整合JdbcTemplate笔记

springboot整合JdbcTemplate


第一步引入依赖的  jar 包

<!-- 引入父类工程 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RELEASE</version>
</parent>

<!-- springboot 整合 jdbc 模板 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>


第二步 直接写  servlec 层
package com.springboot_jdbcTemplate.Empservice;


@Service
public class EmpServlec {

@Autowired
private JdbcTemplate jdbcTemplate;

public void SaveEmp(String name,String sex){
System.out.println("添加");
jdbcTemplate.update(" insert into emp values(null,?,?) ",name,sex);
System.out.println("成功");
}


}


第三步 controller 视图控层
package com.springboot_jdbcTemplate.EmpController;

@Controller
public class EmpController {

@Autowired
private EmpServlec empservlec;

//添加员工
@RequestMapping("/SaveEmp")
@ResponseBody
public String SaveEmp(String name,String sex){
empservlec.SaveEmp(name, sex);
return "success";
}

}


第四步 启动 springboot整合 JdbcTemplate 的工程
package com.springboot_jdbcTemplate.RunSpringboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan(basePackages={"com.springboot_jdbcTemplate.EmpController","com.springboot_jdbcTemplate.Empservice"})
@EnableAutoConfiguration
public class BootTempRun {

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

}
}









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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值