I. Dependencies to be used in the introduction of projects
<dependencies> <dependency> <groupId>junit</groupId> <artifactid& Gt;junit</artifactid> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-web</artif actid> </dependency> <dependency> <groupid>org.springframework.boot</grou Pid> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> ; </dependency> <!--mybatis--<dependency> <groupid>org.mybatis.spring.b Oot</groupid> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</versi on> </dependency> <dependency> <groupid>org.springframework.boot</groupid > <artifactId>spring-boot-starter-logging</artifactId> </dependency> <DEP Endency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-st arter-jdbc</artifactid> </dependency> <dependency> <groupid>org.springfra Mework.boot</groupid> <artifactId>spring-boot-starter-thymeleaf</artifactId> </depe ndency> <!--page plug-in <!--https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-s Pring-boot-starter-<!--page plug-ins-<dependency> <groupid>com.github.pagehe Lper</groupid> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> ; </dependency> <!--Alibaba Druid database Connection pool--<dependency> <groupid>com.alib Aba</groupid> <artifactId>druid</artifactId> <version>1.0.11</version> </dependency> <!--JDBC for MySQL---<dependency> <groupid>mysql </groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</ Scope> </dependency> </dependencies>
Two. Create an entity class
Public classAir {PrivateInteger ID; PrivateString District; @DateTimeFormat (Pattern="YYYY-MM-DD Hh:mm:ss") @JsonSerialize (using= Jsondateserializer.class) PrivateDate Monitortime; PrivateInteger PM10; PrivateInteger PM25; PrivateString monitoringstation; PrivateDate CreateDate; PublicInteger getId () {returnID; } Public voidsetId (Integer id) { This. ID =ID; } PublicString getdistrict () {returnDistrict; } Public voidsetdistrict (String district) { This. district =District; } PublicDate Getmonitortime () {returnMonitortime; } Public voidsetmonitortime (Date monitortime) { This. Monitortime =Monitortime; } PublicInteger GETPM10 () {returnPM10; } Public voidSETPM10 (Integer PM10) { This. PM10 =PM10; } PublicInteger getPm25 () {returnPM25; } Public voidsetPm25 (Integer pm25) { This. PM25 =PM25; } PublicString getmonitoringstation () {returnmonitoringstation; } Public voidsetmonitoringstation (String monitoringstation) { This. monitoringstation =monitoringstation; } PublicDate getcreatedate () {returnCreateDate; } Public voidsetcreatedate (Date createdate) { This. CreateDate =CreateDate; }}
Three. DAO Layer:
Here you only need to define an interface and then write a query method on the OK implementation class please look down
Public interface Iairdao { ///query All public list<air> findAll ();}
Four. The service layer is similar to the previous write
The service layer also needs to inject DAO
Public List<air> FindAll ();
@Service ("airservice")publicclass Iairserviceimpl Implements Iairservice { "iairdao") Private Iairdao DAO; @Override public list<air> findAll () { return Dao.findall (); }}
Five. Controller
@Controller Public classFirstcontroller {@Resource (name="Airservice") PrivateIairservice Iairservice; @RequestMapping ("/gohome") PublicString dohome () {return "Main"; } @RequestMapping ("/findall") @ResponseBody PublicObject FindAll (model model) {List<Air> all =Iairservice.findall (); returnAll ; }}
And then we didn't see where our SQL statements were written down we started writing under resources. Create a mapping package and then build an XML file with the same name as the interface underneath the DAO layer write the SQL statement in this
The project also does not need to use the JSP page, then where does the page put? And, of course, the resources below.
As follows:
Mapping below put is the original DAO layer put XML file, templates below is the front page
Project Focus: APPLICATION.YML File Link database statements are all stored here side
The contents are as follows:
Server:port:8080Spring:thymeleaf:prefix:classpath:/templates/MODE:HTML5 Cache:falsedatasource:name:test Url:jdbc:mysql:///Tableusername:root Password:123456Type:com.alibaba.druid.pool.DruidDataSource Driver-class-name:com.mysql.jdbc.Driver filters:stat maxactive: -initialsize:1maxwait:60000Minidle:1Timebetweenevictionrunsmillis:60000Minevictableidletimemillis:300000Validationquery:Select 'x'Testwhileidle:trueTestonborrow:falseTestonreturn:falsepoolpreparedstatements:truemaxopenpreparedstatements: -Mybatis:mapper-locations:classpath:mapping/*. xml type-aliases-package:cn.leon.entity
Springboot Integrated SSM Query