springboot 整合jdbcTemplate
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了springboot 整合jdbcTemplate,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2406字,纯文字阅读大概需要4分钟。
内容图文
![springboot 整合jdbcTemplate](/upload/InfoBanner/zyjiaocheng/500/3a6fd3b890fa4b1ab2db0b65955cc615.jpg)
springboot 整合jdbcTemplate
〇、搭建springboot环境(包括数据库的依赖)
一、添加依赖
如果导入了jpa的依赖,就不用导入jdbctemplete的依赖了jpa的依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
如果没有导入jpa的包则要导入jdbcTemplete的包:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
二、配置文件
########################################################
###datasource
########################################################
spring.datasource.url = jdbc:mysql://localhost:3306/mine
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.max-active=20
spring.datasource.max-idle=8
spring.datasource.min-idle=8
spring.datasource.initial-size=10
三、持久层
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.xujie.pojo.User;
@Repository
public class UserDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public void save(User user) {
String sql = "insert into user (uname) values (‘"+user.getUname()+"‘)";
this.jdbcTemplate.update(sql);
}
}
四、service
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xujie.dao.UserDao;
import com.xujie.pojo.User;
import com.xujie.service.UserService;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public void save(User user) {
this.userDao.save(user);
}
}
五、Controller
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xujie.pojo.User;
import com.xujie.service.UserService;
@RestController
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/save")
public void save() {
User user = new User();
user.setUname("yuanxiliu");
this.userService.save(user);
}
}
springboot 整合jdbcTemplate
标签:set ide tco ini down jdbc 配置 factor data-
本文系统来源:https://www.cnblogs.com/xujie09/p/8466951.html
内容总结
以上是互联网集市为您收集整理的springboot 整合jdbcTemplate全部内容,希望文章能够帮你解决springboot 整合jdbcTemplate所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。