commit 7f547d991df538cd8e7cf7edbaffab080c814499 Author: SteakJam Date: Fri Nov 15 09:35:00 2024 +0800 加入了一堆会报错的代码 diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..a410183 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,17 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..b7efd8e --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,32 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..56f5edb --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fcad111 --- /dev/null +++ b/pom.xml @@ -0,0 +1,81 @@ + + 4.0.0 + + cn.cartonideas + Demo + 1.0-ALPHA + jar + + Demo + https://maven.apache.org + + + UTF-8 + + + + + + org.springframework + spring-context + 5.3.19 + + + + junit + junit + 4.13.2 + test + + + + + org.mybatis + mybatis + 3.5.6 + + + + + org.mybatis + mybatis-spring + 2.0.6 + + + + + org.springframework + spring-jdbc + 5.3.19 + + + + + mysql + mysql-connector-java + 8.0.28 + + + + + com.alibaba + druid + 1.2.8 + + + + + + + org.springframework.boot + spring-boot-starter-web + 2.5.6 + + + + diff --git a/src/main/java/cn/cartonideas/controller/UserController.java b/src/main/java/cn/cartonideas/controller/UserController.java new file mode 100644 index 0000000..f85567d --- /dev/null +++ b/src/main/java/cn/cartonideas/controller/UserController.java @@ -0,0 +1,29 @@ +/* +package cn.cartonideas.controller; + + +import cn.cartonideas.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; + +import javax.annotation.Generated; + +@Controller +public class UserController { + @Autowired + private UserService userService; + + */ +/*用户查询请求处理*//* + + @GetMapping("/user") + public String findUser(@RequestParam("name") String name, String pwd) + { + return userService.printUserById(name).toString(); + } +} +*/ diff --git a/src/main/java/cn/cartonideas/mapper/UserMapper.java b/src/main/java/cn/cartonideas/mapper/UserMapper.java new file mode 100644 index 0000000..2fc235e --- /dev/null +++ b/src/main/java/cn/cartonideas/mapper/UserMapper.java @@ -0,0 +1,11 @@ +package cn.cartonideas.mapper; + +import cn.cartonideas.model.User; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +@Mapper +public interface UserMapper { + @Select("SELECT * FROM users WHERE id = #{id}") + User findById(Long id); +} diff --git a/src/main/java/cn/cartonideas/model/User.java b/src/main/java/cn/cartonideas/model/User.java new file mode 100644 index 0000000..dde2048 --- /dev/null +++ b/src/main/java/cn/cartonideas/model/User.java @@ -0,0 +1,24 @@ +package cn.cartonideas.model; + + +public class User { + private Long id; + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + diff --git a/src/main/java/cn/cartonideas/service/UserService.java b/src/main/java/cn/cartonideas/service/UserService.java new file mode 100644 index 0000000..d56d11e --- /dev/null +++ b/src/main/java/cn/cartonideas/service/UserService.java @@ -0,0 +1,28 @@ +package cn.cartonideas.service; + + +import cn.cartonideas.mapper.UserMapper; +import cn.cartonideas.model.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 User findUserById(Long id) { + return userMapper.findById(id); + } + + public void printUserById(Long id) { + User user = findUserById(id); + if (user != null) { + System.out.println("用户: " + user.getName()); + } else { + System.out.println("用户id: " + id); + } + } +} diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..3f73687 --- /dev/null +++ b/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,15 @@ + + + + + + + insert into users(id,name) values(#{id},#{name}) + + + + \ No newline at end of file diff --git a/src/main/resources/spring-ioc.xml b/src/main/resources/spring-ioc.xml new file mode 100644 index 0000000..0345de5 --- /dev/null +++ b/src/main/resources/spring-ioc.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/cn/cartonideas/MyApplication.java b/src/test/java/cn/cartonideas/MyApplication.java new file mode 100644 index 0000000..bcc65f9 --- /dev/null +++ b/src/test/java/cn/cartonideas/MyApplication.java @@ -0,0 +1,30 @@ +package cn.cartonideas; + + +import cn.cartonideas.service.UserService; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +//@MapperScan("cn.cartonideas.mapper") +public class MyApplication implements CommandLineRunner { + @Autowired + private UserService userService; + + public static void main(String[] args) { + SpringApplication.run(MyApplication.class, args); + } + + @Override + public void run(String... args) throws Exception { + if (args.length > 0) { + Long userId = Long.parseLong(args[0]); + userService.printUserById(userId); + } else { + System.out.println("Please provide a user ID as an argument."); + } + } +} \ No newline at end of file diff --git a/src/test/java/cn/cartonideas/Test_01.java b/src/test/java/cn/cartonideas/Test_01.java new file mode 100644 index 0000000..3886f61 --- /dev/null +++ b/src/test/java/cn/cartonideas/Test_01.java @@ -0,0 +1,12 @@ +//package cn.cartonideas; +// +//import junit.framework.TestCase; +//public class Test_01 extends TestCase { +// +// public void setUp() throws Exception { +// super.setUp(); +// } +// +// public void tearDown() throws Exception { +// } +//} \ No newline at end of file