标签:xmlns source inter lookup pat import enc beans vat
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>springbootdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springbootdemo</name>
<description>Demo project for Spring
Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--添加mybatis依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.4</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!--添加mysql依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
server.port=8088
#配制mysql数据库映射
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/yz?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT
spring.datasource.username=root
spring.datasource.password=yzltz_0324
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#配制mapper映射文件
mybatis.mapper-locations=classpath:/mappers/*.xml
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
@MapperScan(basePackages = "com.example.springbootdemo.mapper.SpringBootTestMapper")
public class SpringbootdemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringbootdemoApplication.class, args);
}
}
@RestController
public class SpringBootTest {
@RequestMapping("/home")
public String home() {
return "Hello Spring Boot!";
}
@Autowired
private SpringBootTestService springBootTestService;
@RequestMapping("/testList")
public List<SpringBootTestPojo> getTestList(){
List<SpringBootTestPojo> list=springBootTestService.getTestList();
return list;
};
}
public interface SpringBootTestService {
public List<SpringBootTestPojo> getTestList();
}
import java.util.List;
@Service
public class SpringBootTestServiceImpl implements SpringBootTestService {
@Autowired
private SpringBootTestMapper springBootTestMapper;
@Override
public List<SpringBootTestPojo> getTestList() {
List<SpringBootTestPojo> list=springBootTestMapper.getTestList();
return list;
}
}
import java.util.List;
@Mapper
public interface SpringBootTestMapper {
public List<SpringBootTestPojo> getTestList();
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.example.springbootdemo.mapper.SpringBootTestMapper">
<select id="getTestList" resultType="com.example.springbootdemo.pojo.SpringBootTestPojo">
SELECT * FROM `tb_springboot`
</select>
</mapper>
标签:xmlns source inter lookup pat import enc beans vat
原文地址:https://www.cnblogs.com/txf0324/p/11127238.html