1. pom.xml添加依赖
<!-- sqlite -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.21.0.1</version>
</dependency>
  1. .properties添加配置
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.datasource.url=jdbc:sqlite:C:/Users/catface/Desktop/user.db
  1. 编写代码
// pojo
public class User {
private String username;
private String password;
// setter&getter...
}
// Dao
@Repository
@Mapper
public interface LoginDao {
List<User> getUsers();
}
// mapper
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.catface.sbt_test.multi_sql_source.login.dao.LoginDao">
<select id="getUsers" resultType="cc.catface.sbt_test.multi_sql_source.pojo.User">
select username,password from user;
</select>
</mapper>
// service
@Service
public class LoginService {

@Autowired
LoginDao loginDao;

public List<User> getUsers() {
return loginDao.getUsers();
}
}
// controller
@Controller
public class LoginController {

@Autowired
LoginService loginService;

@ResponseBody
@RequestMapping("/getUsers")
public String getUsers() {
return loginService.getUsers().toString();
}
}
  1. 访问链接​​http://localhost:8080/getUsers​​查看数据结果