Using the tool idea 2017.2 development, Gradle builds the project, using the technology spring-boot, MyBatis
1. New Project
Description: 1, src for the source path, the development is mainly under the SRC
2. Src/main/java the Java file
3, src/main/resources decentralized configuration file
4. Src/test/java Test Case
5. build.gradle file: Gradle configuration file
2. Configuring the Build.gradle File
Buildscript {//third-party plugins
ext {
springbootversion = ' 1.5.6.RELEASE '
}
Repositories {//MAVEN warehouse address
Maven{url ' http://xxxx/'}//Private library
Mavencentral ()
}
dependencies {//dependencies
Classpath ("Org.springframework.boot:spring-boot-gradle-plugin:${springbootversion}")
}
}
The declaration in Buildscript is the resource that the Gradle script itself needs to use
Apply plugin: ' java '//Java Project
Apply plugin: ' Eclipse '//Eclipse development environment built to generate the required. project,.classpath files
Apply plugin: ' Org.springframework.boot '
Jar {
BaseName = ' Shop-supplier '
Version = ' 1.0.0-snapshot '
}
Version = ' 1.0.0-snapshot '
sourcecompatibility = 1.8
targetcompatibility = 1.8
Repositories {//MAVEN warehouse address
Maven{url ' http://maven.aliyun.com/nexus/content/groups/public/'}
Mavencentral ()
}
dependencies {//dependencies
Web Thymeleaf
Compile (' Org.springframework.boot:spring-boot-starter-web ')
Compile (' org.springframework.boot:spring-boot-starter-thymeleaf ')
Test
Testcompile (' Org.springframework.boot:spring-boot-starter-test ')
Add Google QR code
Compile ' com.google.zxing:core:3.2.0 '
}
3. Configure MyBatis
Mybatis-config.xml:mybatis configuration file
Mybatis/mapper folder when MyBatis mapper.xml file
3.application.properties: Project configuration file with the following content:
# Database Configuration
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/dbname?useunicode=true&characterencoding=utf-8& Zerodatetimebehavior=round&transformedbitisboolean=true&autoreconnect=true&failoverreadonly=false &allowmultiqueries=true
Spring.datasource.username=rootspring.datasource.password=1Spring.datasource.driver-class-name=com.mysql.jdbc.driver
# MyBatis Configurationmybatis.config-location=classpath:mybatis-config.xml//configuration file location
Mybatis.typealiasespackage=com.my.domain//entity class package
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml//Mapper file location
#log
Logging.file=log.log
Logging.level.com=info
Logging.level.org=info
Logging.level.com.my=debug
Debug=true
Logging.level.com.my.web = Debug
4.mapper File:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace= "Com.my.dao.xxxDao" >
<!--Universal Result set--
<resultmap id= "Baseresultmap" type= "com.my.domain.xxx" >
<id column= "id" property= "id"/>
<result column= "user_name" property= "UserName"/>
<result column= "Field" property= "Properties"/>
</resultMap>
<!--insertion-
<insert id= "method name" Paramtype= "Com.my.domain. Entity class" >
INSERT into table name (ID, user_name) VALUES (#{Property ID}, #{property username})
</insert>
<!--removed-
<delete ... >
<!--Modified-
<update ... >
<!--query-
<select ... >
</mapper>
5.mybatis-config.xml configuration settings
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE configuration Public "-//mybatis.org//dtd Config 3.0//en" "Http://mybatis.org/dtd/mybatis-3-config.dtd" >
<configuration>
<settings>
<setting name= "Logimpl" value= "slf4j"/>
</settings>
</configuration>
6.main Method Entry
@SpringBootApplication//Entry notes
@MapperScan ("Com.my.dao")//MyBatis scan Path
public class Application {
public static void Main (string[] args) {
Springapplication.run (Application.class, args);
}
}
Note: 1.controller annotations:
Before @RestCotroller class--returns JSON equivalent to @Controller class before + @ResponseBody method
@RequestMapping (value = "/order" method = Requestmethod.get) before the class or method
Validate the entry parameter before @Valid the parameter, followed by the Bindingresult parameter, and receive the verification information
@NotNull @NotEmpty @Length @NotBlank @Min @Size before the parameter property
2.service:
Before @Service class
Before @Transactional (rollbackfor = Exception.class) method
3.dao:
Before @Mapper class
Before @Param parameters
Timer:
1. Java annotations in main portal @enablescheduling
2. Timer Java Annotations @component
3. Timing method Annotations @scheduled (cron = "second-time-of-day-month-week-year"
A cron expression has at least 6 (or possibly 7) time elements that have a space separation.
sequentially seconds (0~59)
Minutes (0~59)
Hours (0~23)
Days (months) (0~31, but you need to consider the number of days of your month)
Month (0~11)
Days (weeks) (1~7 1=sun or Sun,mon,tue,wed,thu,fri,sat)
7. Year (1970-2099)
Each of these elements can be a value (such as 6), a continuous interval (9-12), a time interval (8-18/4) (/= every 4 hours), a list (1,3,5), a wildcard
Idea Spring-boot Gradle MyBatis