SpringBoot(二)

空气质量检测的一个小案例: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

 

相关文章
相关标签/搜索