资源包下载https://download.csdn.net/download/afasdsdfgsdgf/15451390
首先创建一个maven项目
pom配置
<dependencies>
<!--web,servlet引入-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--mybatis依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<!--mysql依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--快速操作实体类-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--单元测试-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
application
server:
port: 8099
spring:
datasource:
url: jdbc:mysql://192.168.0.129:3306/order?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
# type-aliases-package批量设置别名作用:就是在mapper.xml文件中直接写类名,不配置就需要写类的全路径名
mybatis:
type-aliases-package: com.ticomm.web.entity
mapper-locations: classpath:mapper/*.xml
# 配置pagehelper参数
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
logging:
level:
com.ticomm.web.dao.OrderDao: #debug
controller
package com.ticomm.web.controller;
import com.ticomm.web.entity.Order;
import com.ticomm.web.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class OrderController {
@Autowired
private OrderService orderService;
@GetMapping(value = "getOrder")
public String getOrder(Order order){
System.out.println(order.getId());
return orderService.getOrder();
}
}
service
package com.ticomm.web.service;
public interface OrderService {
String getOrder();
}
serviceimpl
package com.ticomm.web.service.impl;
import com.github.pagehelper.PageHelper;
import com.ticomm.web.dao.OrderDao;
import com.ticomm.web.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class OrderServiceImpl implements OrderService {
@Resource
private OrderDao orderDao;
@Override
public String getOrder() {
PageHelper.startPage(1,10);
return orderDao.getOrder().getCount();
}
}
dao
package com.ticomm.web.dao;
import com.ticomm.web.entity.Order;
public interface OrderDao {
Order getOrder();
}
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="com.ticomm.web.dao.OrderDao">
<select id="getOrder" resultType="com.ticomm.web.entity.Order" parameterType="com.ticomm.web.entity.Order">
select id,count from sys_order_t
</select>
</mapper>
app
package com.ticomm.web;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan(value = {"com.ticomm.web.dao"})
public class App8099 {
public static void main(String[] args) {
SpringApplication.run(App8099.class,args);
}
}
entity
package com.ticomm.web.entity;
import lombok.Data;
@Data
public class Order {
private String id;
private String count;
}
启动即可