正常的和数据库交互获取数据

master
e 5 months ago
commit 1d6e2ed0b2

15
.gitignore vendored

@ -0,0 +1,15 @@
.idea
*.iml
# Created by .ignore support plugin (hsz.mobi)
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

@ -0,0 +1,40 @@
<?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.3.12.RELEASE</version>
<relativePath />
</parent>
<groupId>com.mashibing</groupId>
<artifactId>read_write_lock</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,18 @@
package com.mashibing;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author zjw
* @description
*/
@SpringBootApplication
@MapperScan(basePackages = "com.mashibing.mapper")
public class ReadWriteLockStarterApp {
public static void main(String[] args) {
SpringApplication.run(ReadWriteLockStarterApp.class,args);
}
}

@ -0,0 +1,24 @@
package com.mashibing.controller;
import com.mashibing.entity.Air;
import com.mashibing.service.AirService;
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;
/**
* @author zjw
* @description
*/
@RestController
public class AirController {
@Autowired
private AirService airService;
@GetMapping("/air/{id}")
public Air getById(@PathVariable Long id){
return airService.getById(id);
}
}

@ -0,0 +1,17 @@
package com.mashibing.entity;
import lombok.Data;
/**
* @author zjw
* @description
*/
@Data
public class Air {
private Long id;
private int pm25;
private String monitoringStation;
}

@ -0,0 +1,15 @@
package com.mashibing.mapper;
import com.mashibing.entity.Air;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* @author zjw
* @description
*/
public interface AirMapper {
@Select("select * from air where id = #{id}")
Air findById(@Param("id") Long id);
}

@ -0,0 +1,11 @@
package com.mashibing.service;
import com.mashibing.entity.Air;
/**
* @author zjw
* @description
*/
public interface AirService {
Air getById(Long id);
}

@ -0,0 +1,24 @@
package com.mashibing.service.impl;
import com.mashibing.entity.Air;
import com.mashibing.mapper.AirMapper;
import com.mashibing.service.AirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author zjw
* @description
*/
@Service
public class AirServiceImpl implements AirService {
@Autowired
private AirMapper airMapper;
@Override
public Air getById(Long id) {
Air air = airMapper.findById(id);
return air;
}
}

@ -0,0 +1,8 @@
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/air
mybatis:
configuration:
map-underscore-to-camel-case: true
Loading…
Cancel
Save