5/25 16:27

This commit is contained in:
zyx 2023-05-25 16:27:45 +08:00
parent 6305cdf583
commit a0b9985df0
15 changed files with 320 additions and 0 deletions

2
.idea/compiler.xml generated
View File

@ -13,6 +13,7 @@
<module name="demo516" /> <module name="demo516" />
<module name="demo515" /> <module name="demo515" />
<module name="spring-mybatis01-522-523" /> <module name="spring-mybatis01-522-523" />
<module name="springboot525" />
<module name="springboot-524" /> <module name="springboot-524" />
<module name="mybatis519" /> <module name="mybatis519" />
<module name="springmvc-02-524" /> <module name="springmvc-02-524" />
@ -26,6 +27,7 @@
<component name="JavacSettings"> <component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE"> <option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="springboot-524" options="-parameters" /> <module name="springboot-524" options="-parameters" />
<module name="springboot525" options="-parameters" />
</option> </option>
</component> </component>
</project> </project>

View File

@ -305,6 +305,50 @@
</TableInfoDTO> </TableInfoDTO>
</value> </value>
</entry> </entry>
<entry key="person_info.user">
<value>
<TableInfoDTO>
<option name="fullColumn">
<list>
<ColumnInfoDTO>
<option name="comment" value="主键ID" />
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="id" />
<option name="type" value="java.lang.Long" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="comment" value="姓名" />
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="name" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="comment" value="年龄" />
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="age" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="comment" value="邮箱" />
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="email" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
</list>
</option>
<option name="name" value="User" />
<option name="preName" value="" />
<option name="saveModelName" value="springboot525" />
<option name="savePackageName" value="cn.czyx007" />
<option name="savePath" value="./springboot525/src/main/java/cn/czyx007" />
<option name="templateGroupName" value="Default" />
</TableInfoDTO>
</value>
</entry>
</map> </map>
</option> </option>
</component> </component>

2
.idea/encodings.xml generated
View File

@ -23,6 +23,8 @@
<file url="file://$PROJECT_DIR$/spring522/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/spring522/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springboot-524/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springboot-524/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springboot-524/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springboot-524/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springboot525/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springboot525/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springmvc-01-523/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springmvc-01-523/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springmvc-01-523/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springmvc-01-523/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/springmvc-02-524/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/springmvc-02-524/src/main/java" charset="UTF-8" />

1
.idea/misc.xml generated
View File

@ -24,6 +24,7 @@
<option value="$PROJECT_DIR$/springmvc-01-523/pom.xml" /> <option value="$PROJECT_DIR$/springmvc-01-523/pom.xml" />
<option value="$PROJECT_DIR$/springmvc-02-524/pom.xml" /> <option value="$PROJECT_DIR$/springmvc-02-524/pom.xml" />
<option value="$PROJECT_DIR$/springboot-524/pom.xml" /> <option value="$PROJECT_DIR$/springboot-524/pom.xml" />
<option value="$PROJECT_DIR$/springboot525/pom.xml" />
</list> </list>
</option> </option>
</component> </component>

64
springboot525/pom.xml Normal file
View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>springboot525</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot525</name>
<description>springboot525</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,15 @@
package cn.czyx007;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("cn.czyx007.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,20 @@
package cn.czyx007.bean;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author : 张宇轩
* @createTime : 2023/5/25 - 14:57
*/
@Data
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String userName;
private String password;
private String address;
private Integer age;
private String email;
}

View File

@ -0,0 +1,36 @@
package cn.czyx007.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* (User)实体类
*
* @author 张宇轩
* @since 2023-05-25 15:30:24
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User implements Serializable {
private static final long serialVersionUID = 872728960100083467L;
/**
* 主键ID
*/
private Long id;
/**
* 姓名
*/
private String name;
/**
* 年龄
*/
private Integer age;
/**
* 邮箱
*/
private String email;
}

View File

@ -0,0 +1,44 @@
package cn.czyx007.controller;
import cn.czyx007.bean.Person;
import cn.czyx007.bean.User;
import cn.czyx007.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author : 张宇轩
* @createTime : 2023/5/25 - 14:55
*/
@RestController
public class HelloController {
@Value("${person.username}")
private String userName;
@Autowired
private Person person;
@Autowired
private UserService userService;
@GetMapping("/getUser")
public List<User> getUser(){
return userService.findUser();
}
@GetMapping("/good")
private String good(){
System.out.println("userName = " + userName);
return "good,springboot!!!";
}
@GetMapping("/person")
public String person(){
System.out.println("person = " + person);
return "person";
}
}

View File

@ -0,0 +1,13 @@
package cn.czyx007.mapper;
import cn.czyx007.bean.User;
import java.util.List;
/**
* @author : 张宇轩
* @createTime : 2023/5/25 - 15:30
*/
public interface UserMapper {
List<User> getUser();
}

View File

@ -0,0 +1,13 @@
package cn.czyx007.service;
import cn.czyx007.bean.User;
import java.util.List;
/**
* @author : 张宇轩
* @createTime : 2023/5/25 - 15:46
*/
public interface UserService {
List<User> findUser();
}

View File

@ -0,0 +1,26 @@
package cn.czyx007.service.impl;
import cn.czyx007.bean.User;
import cn.czyx007.mapper.UserMapper;
import cn.czyx007.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author : 张宇轩
* @createTime : 2023/5/25 - 15:47
*/
@Service
@Transactional
public class UserServiceImpl implements UserService {
@Autowired(required = false)
private UserMapper userMapper;
@Override
public List<User> findUser() {
return userMapper.getUser();
}
}

View File

@ -0,0 +1,15 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/person_info?serverTimezone=Asia/Shanghai
username: root
password: zyx007
mybatis:
type-aliases-package: cn.czyx007.bean
mapper-locations: classpath:mappers/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
person:
username: abc

View File

@ -0,0 +1,11 @@
<?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="cn.czyx007.mapper.UserMapper">
<select id="getUser" resultType="cn.czyx007.bean.User">
select * from person_info.user
</select>
</mapper>

View File

@ -0,0 +1,14 @@
package cn.czyx007;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ApplicationTests {
@Test
void contextLoads() {
}
}