origin
This commit is contained in:
14
src/main/java/com/example/DemoApplication.java
Normal file
14
src/main/java/com/example/DemoApplication.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.example;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@MapperScan("com.example.mapper") //扫描的mapper
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
28
src/main/java/com/example/controller/UserController.java
Normal file
28
src/main/java/com/example/controller/UserController.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.entity.User;
|
||||
import com.example.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @Author:wjup
|
||||
* @Date: 2018/9/26 0026
|
||||
* @Time: 14:42
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/testBoot")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@RequestMapping("getUser/{id}")
|
||||
public String GetUser(@PathVariable int id){
|
||||
return userService.Sel(id).toString();
|
||||
}
|
||||
}
|
||||
55
src/main/java/com/example/entity/User.java
Normal file
55
src/main/java/com/example/entity/User.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.example.entity;
|
||||
|
||||
/**
|
||||
* @Author:wjup
|
||||
* @Date: 2018/9/26 0026
|
||||
* @Time: 14:39
|
||||
*/
|
||||
public class User {
|
||||
private Integer id;
|
||||
private String userName;
|
||||
private String passWord;
|
||||
private String realName;
|
||||
|
||||
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 getPassWord() {
|
||||
return passWord;
|
||||
}
|
||||
|
||||
public void setPassWord(String passWord) {
|
||||
this.passWord = passWord;
|
||||
}
|
||||
|
||||
public String getRealName() {
|
||||
return realName;
|
||||
}
|
||||
|
||||
public void setRealName(String realName) {
|
||||
this.realName = realName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", userName='" + userName + '\'' +
|
||||
", passWord='" + passWord + '\'' +
|
||||
", realName='" + realName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
16
src/main/java/com/example/mapper/UserMapper.java
Normal file
16
src/main/java/com/example/mapper/UserMapper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.entity.User;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @Author:wjup
|
||||
* @Date: 2018/9/26 0026
|
||||
* @Time: 15:20
|
||||
*/
|
||||
@Repository
|
||||
public interface UserMapper {
|
||||
|
||||
User Sel(int id);
|
||||
}
|
||||
20
src/main/java/com/example/service/UserService.java
Normal file
20
src/main/java/com/example/service/UserService.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.example.service;
|
||||
|
||||
import com.example.entity.User;
|
||||
import com.example.mapper.UserMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author:wjup
|
||||
* @Date: 2018/9/26 0026
|
||||
* @Time: 15:23
|
||||
*/
|
||||
@Service
|
||||
public class UserService {
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
public User Sel(int id){
|
||||
return userMapper.Sel(id);
|
||||
}
|
||||
}
|
||||
20
src/main/resources/application-dev.yml
Normal file
20
src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
username: sgk
|
||||
password: 070915
|
||||
url: jdbc:mysql://127.0.0.1:3306/user?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
|
||||
mybatis:
|
||||
mapper-locations: classpath:mapping/*Mapping.xml
|
||||
type-aliases-package: com.example.entity
|
||||
|
||||
#showSql
|
||||
logging:
|
||||
level:
|
||||
com:
|
||||
example:
|
||||
mapper : debug
|
||||
3
src/main/resources/application.yml
Normal file
3
src/main/resources/application.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
16
src/main/resources/mapping/UserMapping.xml
Normal file
16
src/main/resources/mapping/UserMapping.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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.example.mapper.UserMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.example.entity.User">
|
||||
<result column="id" jdbcType="INTEGER" property="id" />
|
||||
<result column="userName" jdbcType="VARCHAR" property="userName" />
|
||||
<result column="passWord" jdbcType="VARCHAR" property="passWord" />
|
||||
<result column="realName" jdbcType="VARCHAR" property="realName" />
|
||||
</resultMap>
|
||||
|
||||
<select id="Sel" resultType="com.example.entity.User">
|
||||
select * from user where id = #{id}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
13
src/test/java/com/example/demo/DemoApplicationTests.java
Normal file
13
src/test/java/com/example/demo/DemoApplicationTests.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class DemoApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user