In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail how to solve the problem of SpringBoot's support for jdbc ", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article" how to solve the problem of SpringBoot's support for jdbc "can help you solve your doubts.
Pom.xml:
Spring-boot-02 com.keafmd 1.0-SNAPSHOT 4.0.0 spring-boot-08 org.springframework.boot spring-boot-starter-web org.apache.tomcat.embed tomcat-embed-jasper jstl jstl 1.2 org.springframework.boot spring-boot-starter-jdbc mysql mysql-connector-java 5.1.46 org.springframework.boot spring-boot-starter-test org. Springframework.boot spring-boot-devtools
Application.yml
Server: port: 80spring: datasource: url: jdbc:mysql://127.0.0.1:3306/ssm-java1?useSSL=false driver-class-name: com.mysql.jdbc.Driver username: root password: 18044229
Startup class
Package com.keafmd;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class App08 {public static void main (String [] args) {SpringApplication.run (App08.class, args);}}
Dao layer
UserDao:
Package com.keafmd.dao;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.stereotype.Repository;import java.util.List;@Repositorypublic class UserDao {@ Autowired JdbcTemplate jdbcTemplate; public List userList () {String sql = "select * from user"; return jdbcTemplate.queryForList (sql);}}
Service layer
IUserService:
Package com.keafmd.service;import java.util.List;public interface IUserService {List list ();}
UserServiceImpl:
Package com.keafmd.service.impl;import com.keafmd.dao.UserDao;import com.keafmd.service.IUserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;@Servicepublic class UserServiceImpl implements IUserService {@ Autowired UserDao userDao; @ Override public List list () {return userDao.userList ();}
Controller layer
UserController:
Package com.keafmd.controller;import com.keafmd.service.IUserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestControllerpublic class UserController {@ Autowired IUserService userService / * http://127.0.0.1/userlist * @ return * / @ RequestMapping ("userlist") List UserList () {return userService.list ();}} Test Class Test
UserDaoTest:
Package com.keafmd.dao;import com.keafmd.App08;import org.junit.jupiter.api.Test;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import java.util.List;import static org.junit.jupiter.api.Assertions.*;@SpringBootTest (classes = App08.class) class UserDaoTest {@ Autowired UserDao userDao; @ Test public void test () {List userlist = userDao.userList () For (Object o: userlist) {System.out.println (o);} read here, this article "how to solve the problem of SpringBoot's support for jdbc" has been introduced. If you want to grasp the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.