空氣質量檢測的一個小案例:mysql
(1)建立數據庫ajax
(2)引入各類須要的依賴或者xml文件spring
yml文件:sql
server:
port: 8080
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
thymeleaf:
prefix: classpath:/templates/
mode: HTML5
cache: false
datasource:
name: test
url: jdbc:mysql://localhost:3306/air
username: root
password:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
mybatis:
mapper-locations: classpath:mapping/*.xml
type-aliases-package: com.wp.entity
(3)建立包
@Controller
public class AirController {
@Resource(name="airService")
private IAirService iAirService;
@RequestMapping("/main")
public String main(){
return "main";
}
//查詢全部
@RequestMapping("/allair")
@ResponseBody
public Object allair(Model model) throws Exception {
List<Air> list = iAirService.allair();
return list;
}
//根據區域查詢所在區域的全部檢測記錄
@RequestMapping("/disair")
@ResponseBody
public Object airbydis(Model model,String district) throws Exception {
List<Air> list = iAirService.airbydis(district);
return list;
}
//添加的頁面
@RequestMapping("/add")
public String add(){
return "addAir";
}
//添加檢測數據
public String addair(Air air) throws Exception {
int addair = iAirService.addair(air);
if (addair>0){
return "main";
}else {
return "addAir";
}
}
主頁的ajax:
效果圖:
模糊查詢:數據庫
點擊添加:mybatis
點擊提交後跳轉到首頁app