SpringBoot(二)

空气质量检测的一个小案例:

(1)创建数据库

       

(2)引入各种需要的依赖或者xml文件

      

          yml文件:

   

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:

效果图:

模糊查询:

点击添加:

点击提交后跳转到首页

猜你喜欢

转载自www.cnblogs.com/erci-520/p/9219745.html
今日推荐