Springboot Integrated SSM Query

Source: Internet
Author: User

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&gt        ; </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> &LT;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&gt        ; </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.