工程结构
最终完成后的工程结构:
下面开始详细的讲解项目的开发过程。
1、新建spring-boot项目
点击next,记得要联网
选择这几个jar包
点击Finish完成
2.创建之后的项目如图所示,我们需要在这之上新建一些目录。
然后在resources包下面把application.properties改成application.yml
2、application.yml配置文件代码:
server:
port: 8989
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/jpademo?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
username: root
password: "0000"
mybatis:
mapper-locations: classpath*:mapper/*.xml
pagehelper:
helper-dialect: mysql
params: count=countSql
reasonable: true
support-methods-arguments: true
3、自定义java
- 在entity里面创建Prople.java
@Data
public class Prople {
private int id;
private String city;
private int num;
}
- 在mapper包中新建接口 PropleMapper:
@Repository
@Mapper
public interface PropleMapper {
List<Prople> getCity();
int sum();
}
- 在service包中新建接口 PropleService:
public interface PropleService {
;
List<Prople> getCity();
int sum();
}
- 在service包中新建 类 PropleServiceImpl 实现接口:PropleService
@Service
public class PropleServiceImpl implements PropleService {
@Autowired
private PropleMapper propleMapper;
@Override
public List<Prople> getCity() {
return propleMapper.getCity();
}
@Override
public int sum() {
return propleMapper.sum();
}
}
- 在controller包中新建 类 PropleController:
@Controller
public class PropleController {
@Autowired
private PropleService propleService