工程pom.xml文件增加如下依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.21</version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<scope>provided</scope>
</dependency>
main/resources增加mybatis.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
main/resources增加application.yaml
spring :
profile :
active : dev
datasource :
# type : com.alibaba.druid.poolDruidDataSource
driver-class-name : com.ibm.db2.jcc.DB2Driver
url : jdbc:db2://127.0.0.1:50000/ruoyidb
username : db2inst1
password : 123456
mybatis :
config-location : classpath:mybatis.xml
mapper-locations: classpath:mapper/**/*.xml
type-aliases-package: classpath*:com.wz.gjjdemo.domain
server :
tomcat :
uri-encoding: UTF-8
port : 8080
main/resources/mapper增加UserMapper.xml
<?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="com.wz.gjjdemo.dao.UserDao">
<select id="getAllUser" resultType="com.wz.gjjdemo.domain.User">
select * from user
</select>
</mapper>
新建controller/UserController
@RestController
@RequestMapping("/test")
public class UserController {
@Resource
private IUserService userService;
@RequestMapping("/getAllUser")
@ResponseBody
public List<User> getAllUser() {
return userService.getAllUser();
}
}
新建dao/UserDao
@Mapper
public interface UserDao {
List<User> getAllUser();
}
新建domain/User
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class User {
private long userId;
private String userName;
private String mobile;
private String email;
}
新建service/impl/UserServiceImpl
@Service
public class UserServiceImpl implements IUserService {
@Resource
private UserDao userDao;
@Override
public List<User> getAllUser(){
return userDao.getAllUser();
}
}
新建service/IUserService
public interface IUserService {
List<User> getAllUser();
}
完整代码参看本人csdn资源
标签:jackson,springboot,getAllUser,private,mybatis,db2,com,public From: https://blog.csdn.net/qq_29346437/article/details/140151963