parent
dc602f7317
commit
28afd9565c
@ -0,0 +1,93 @@
|
|||||||
|
<?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>3.4.3</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.cyberlanting</groupId>
|
||||||
|
<artifactId>Assignments</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>Assignments</name>
|
||||||
|
<description>Assignments</description>
|
||||||
|
<url/>
|
||||||
|
<licenses>
|
||||||
|
<license/>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer/>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection/>
|
||||||
|
<developerConnection/>
|
||||||
|
<tag/>
|
||||||
|
<url/>
|
||||||
|
</scm>
|
||||||
|
<properties>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.8.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>9.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<!-- <build>-->
|
||||||
|
<!-- <plugins>-->
|
||||||
|
<!-- <plugin>-->
|
||||||
|
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||||
|
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
|
||||||
|
<!-- <configuration>-->
|
||||||
|
<!-- <annotationProcessorPaths>-->
|
||||||
|
<!-- <path>-->
|
||||||
|
<!-- <groupId>org.projectlombok</groupId>-->
|
||||||
|
<!-- <artifactId>lombok</artifactId>-->
|
||||||
|
<!-- </path>-->
|
||||||
|
<!-- </annotationProcessorPaths>-->
|
||||||
|
<!-- </configuration>-->
|
||||||
|
<!-- </plugin>-->
|
||||||
|
<!-- <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>
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.cyberlanting.Assignments;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class AssignmentsApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(AssignmentsApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.cyberlanting.Assignments.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
public class SwaggerConfig implements WebMvcConfigurer {
|
||||||
|
// @Override
|
||||||
|
// public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
// log.info("静态资源映射");
|
||||||
|
// registry.addResourceHandler("/swagger-ui/**")
|
||||||
|
// .addResourceLocations("classpath:/META-INF/resources/webjars/springdoc-openapi-ui/")
|
||||||
|
// .resourceChain(false);
|
||||||
|
// }
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.cyberlanting.Assignments.mapper;
|
||||||
|
|
||||||
|
import com.cyberlanting.Assignments.pojo.User;
|
||||||
|
import org.apache.ibatis.annotations.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper {
|
||||||
|
|
||||||
|
@Select("select * from user")
|
||||||
|
public List<User> getUserList();
|
||||||
|
|
||||||
|
@Insert("insert into user(name, age) values(#{name}, #{age})")
|
||||||
|
public void save(User user);
|
||||||
|
|
||||||
|
@Select("select * from user where id = #{id}")
|
||||||
|
public User getUser(Long id);
|
||||||
|
|
||||||
|
public void update(Long id, User user);
|
||||||
|
|
||||||
|
@Delete("delete from user where id = #{id}")
|
||||||
|
public void remove(Long id);
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.cyberlanting.Assignments.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private Integer age;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.cyberlanting.Assignments.service;
|
||||||
|
|
||||||
|
import com.cyberlanting.Assignments.mapper.UserMapper;
|
||||||
|
import com.cyberlanting.Assignments.pojo.User;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
public List<User> getUserList() {
|
||||||
|
return userMapper.getUserList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(User user) {
|
||||||
|
userMapper.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser(Long id) {
|
||||||
|
return userMapper.getUser(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Long id, User user) {
|
||||||
|
userMapper.update(id, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Long id) {
|
||||||
|
userMapper.remove(id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: Assignments
|
||||||
|
datasource:
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
url: jdbc:mysql://localhost:3306/rjgc?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||||
|
username: root
|
||||||
|
password: 123456
|
||||||
|
|
||||||
|
mybatis:
|
||||||
|
#mapper配置文件
|
||||||
|
mapper-locations: mapper/*.xml
|
||||||
|
type-aliases-package: com.cyberlanting.Assignments.pojo
|
||||||
|
configuration:
|
||||||
|
#开启驼峰命名
|
||||||
|
map-underscore-to-camel-case: true
|
@ -0,0 +1,14 @@
|
|||||||
|
<?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.cyberlanting.Assignments.mapper.UserMapper">
|
||||||
|
|
||||||
|
<update id="update">
|
||||||
|
update user
|
||||||
|
<set>
|
||||||
|
<if test="user.name != null">name = #{user.name},</if>
|
||||||
|
<if test="user.age != null">age = #{user.age}</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
Loading…
Reference in new issue