1.文件目录
2.App.java
package
com.app
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.ComponentScan
;
/**
* Created by Administrator on 2018/3/14.
*/
@ComponentScan
(
basePackages
= {
"com.controller"
,
"com.service"
})
@MapperScan
(
basePackages
=
"com.mapper"
)
@EnableAutoConfiguration
public class
App {
public static void
main
(String[] args) {
SpringApplication.
run
(App.
class,
args)
;
}
}
3.controller
package
com.controller
;
import
com.pojo.User
;
import
com.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.util.List
;
/**
* Created by Administrator on 2018/3/14.
*/
@Controller
public class
UserController {
@Autowired
private
UserService
userService
;
@RequestMapping
(
"/index"
)
public
String
index
(){
return
"index"
;
}
@ResponseBody
@RequestMapping
(
"/getUser"
)
public
List<User>
getUser
(){
List<User> users =
userService
.getAllUser()
;
return
users
;
}
}
4.mapper
package
com.mapper
;
import
com.pojo.User
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Select
;
import
java.util.List
;
/**
* Created by Administrator on 2018/3/14.
*/
@Mapper
public interface
UserMapper {
@Select
(
"select * from user"
)
List<User>
getAllUser
()
;
}
5.pojo
package
com.pojo
;
/**
* Created by Administrator on 2018/3/14.
*/
public class
User {
private
Integer
id
;
private
String
username
;
private
String
mobile
;
private
Integer
role
;
private
Integer
status
;
public
Integer
getId
() {
return
id
;
}
public void
setId
(Integer id) {
this
.
id
= id
;
}
public
String
getUsername
() {
return
username
;
}
public void
setUsername
(String username) {
this
.
username
= username
;
}
public
String
getMobile
() {
return
mobile
;
}
public void
setMobile
(String mobile) {
this
.
mobile
= mobile
;
}
public
Integer
getRole
() {
return
role
;
}
public void
setRole
(Integer role) {
this
.
role
= role
;
}
public
Integer
getStatus
() {
return
status
;
}
public void
setStatus
(Integer status) {
this
.
status
= status
;
}
}
6.UserService
package
com.service
;
import
com.pojo.User
;
import
java.util.List
;
/**
* Created by Administrator on 2018/3/14.
*/
public interface
UserService {
List<User>
getAllUser
()
;
}
7.UserServiceImpl
package
com.service
;
import
com.mapper.UserMapper
;
import
com.pojo.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* Created by Administrator on 2018/3/15.
*/
@Service
public class
UserServiceImpl
implements
UserService {
@Autowired
private
UserMapper
usermapper
;
@Override
public
List<User>
getAllUser
() {
return
usermapper
.getAllUser()
;
}
}
8.application.properties
spring.mvc.view.prefix
=
/WEB-INF/jsp/
spring.mvc.view.suffix
=
.jsp
spring.datasource.url
=
jdbc:mysql://localhost:3306
spring.datasource.username
=
root
spring.datasource.password
=
root
spring.datasource.driver-class-name
=
com.mysql.jdbc.Driver
9.index.jsp
略
10.web.xml
略。(保留创建出来的样子)
11.pom.xml
<?
xml version
="1.0"
encoding
="UTF-8"
?>
xsi
:schemaLocation
="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd";
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.springboot
</groupId>
<artifactId>
springboot-mybatis
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.5.3.RELEASE
</version>
</parent>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
jstl
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-tomcat
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.tomcat.embed
</groupId>
<artifactId>
tomcat-embed-jasper
</artifactId>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<dependency>
<groupId>
org.mybatis.spring.boot
</groupId>
<artifactId>
mybatis-spring-boot-starter
</artifactId>
<version>
1.1.1
</version>
</dependency>
</dependencies>
</project>