From d3477a1eecf506f107c7b14856f15226eead54e1 Mon Sep 17 00:00:00 2001 From: syx_computer Date: Tue, 21 Oct 2025 17:24:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E5=91=8A=E4=B8=80=E6=AE=B5?= =?UTF-8?q?=E8=90=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springbootweb01/controller/UserController.java | 49 +++++++++++------- .../java/com/itheima/springbootweb01/dao/UserDao.java | 8 +++ .../itheima/springbootweb01/dao/impl/UserDaoImpl.java | 26 ++++++++++ .../itheima/springbootweb01/service/UserService.java | 9 ++++ .../springbootweb01/service/lmpl/UserServiceImpl.java | 35 +++++++++++++ .../springbootweb01/controller/UserController.class | Bin 3435 -> 1151 bytes .../com/itheima/springbootweb01/dao/UserDao.class | Bin 0 -> 227 bytes .../springbootweb01/dao/impl/UserDaoImpl.class | Bin 0 -> 1236 bytes .../itheima/springbootweb01/service/UserService.class | Bin 0 -> 260 bytes .../service/lmpl/UserServiceImpl.class | Bin 0 -> 2891 bytes 10 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/dao/UserDao.java create mode 100644 04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/dao/impl/UserDaoImpl.java create mode 100644 04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/service/UserService.java create mode 100644 04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/service/lmpl/UserServiceImpl.java create mode 100644 04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/dao/UserDao.class create mode 100644 04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/dao/impl/UserDaoImpl.class create mode 100644 04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/service/UserService.class create mode 100644 04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/service/lmpl/UserServiceImpl.class diff --git a/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/controller/UserController.java b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/controller/UserController.java index 1dfbad7..fb117be 100644 --- a/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/controller/UserController.java +++ b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/controller/UserController.java @@ -2,6 +2,8 @@ package com.itheima.springbootweb01.controller; import cn.hutool.core.io.IoUtil; import com.itheima.springbootweb01.pojo.User; +import com.itheima.springbootweb01.service.UserService; +import com.itheima.springbootweb01.service.lmpl.UserServiceImpl; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -22,28 +24,39 @@ import static java.lang.System.in; //用户信息控制器 @RestController //作用:将controller返回值直接作为响应数据返回给浏览器@ResponseBody public class UserController { - @RequestMapping("/hello"); + /** + * 接受请求 相应数据 + */ + private UserService userService = new UserServiceImpl(); + // @RequestMapping("/list") +// public List list() throws Exception{ +// //1.加载并读取user.txt文件,获取用户数据 +// // 绝对路径 +// //InputStream in = new FileInputStream(new File("C:\\Users\\syx\\Desktop\\JavaWeb\\04. 后端Web基础(基础知识)\\springboot-web-01\\src\\main\\resources\\user.txt")); +// //相对路径 +// InputStream in = this.getClass().getClassLoader().getResourceAsStream("user.txt"); +// ArrayList lines = IoUtil.readLines(in, StandardCharsets.UTF_8, new ArrayList<>()); +// //2.将用户数据封装成User对象 ->list集合 +// List UserList= lines.stream().map(line -> { +// String[] split = line.split(","); +// Integer id = Integer.parseInt(split[0]); +// String username = split[1]; +// String password = split[2]; +// String name = split[3]; +// Integer age = Integer.parseInt(split[4]); +// LocalDateTime updateTime = LocalDateTime.parse(split[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); +// return new User(id, username, password, name, age, updateTime); +// }).toList(); +// //3.返回数据(json) +// return UserList; +// } @RequestMapping("/list") public List list() throws Exception{ - //1.加载并读取user.txt文件,获取用户数据 - // 绝对路径 - //InputStream in = new FileInputStream(new File("C:\\Users\\syx\\Desktop\\JavaWeb\\04. 后端Web基础(基础知识)\\springboot-web-01\\src\\main\\resources\\user.txt")); - //相对路径 - InputStream in = this.getClass().getClassLoader().getResourceAsStream("user.txt"); - ArrayList lines = IoUtil.readLines(in, StandardCharsets.UTF_8, new ArrayList<>()); - //2.将用户数据封装成User对象 ->list集合 - List UserList= lines.stream().map(line -> { - String[] split = line.split(","); - Integer id = Integer.parseInt(split[0]); - String username = split[1]; - String password = split[2]; - String name = split[3]; - Integer age = Integer.parseInt(split[4]); - LocalDateTime updateTime = LocalDateTime.parse(split[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - return new User(id, username, password, name, age, updateTime); - }).toList(); + //1.调用service层数据 + List UserList= userService.findAll(); + //3.返回数据(json) return UserList; } diff --git a/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/dao/UserDao.java b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/dao/UserDao.java new file mode 100644 index 0000000..7b703ba --- /dev/null +++ b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/dao/UserDao.java @@ -0,0 +1,8 @@ +package com.itheima.springbootweb01.dao; + +import java.util.List; + +public interface UserDao { +// 加载用户数据 + public List findAll(); +} diff --git a/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/dao/impl/UserDaoImpl.java b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/dao/impl/UserDaoImpl.java new file mode 100644 index 0000000..3cc0992 --- /dev/null +++ b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/dao/impl/UserDaoImpl.java @@ -0,0 +1,26 @@ +package com.itheima.springbootweb01.dao.impl; + +import cn.hutool.core.io.IoUtil; +import com.itheima.springbootweb01.dao.UserDao; + +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +public class UserDaoImpl implements UserDao { + /** + * 数据层 + * @return 数据访问层数据 + */ + @Override + public List findAll() { + //1.加载并读取user.txt文件,获取用户数据 + // 绝对路径 + //InputStream in = new FileInputStream(new File("C:\\Users\\syx\\Desktop\\JavaWeb\\04. 后端Web基础(基础知识)\\springboot-web-01\\src\\main\\resources\\user.txt")); + //相对路径 + InputStream in = this.getClass().getClassLoader().getResourceAsStream("user.txt"); + ArrayList lines = IoUtil.readLines(in, StandardCharsets.UTF_8, new ArrayList<>()); + return lines; + } +} diff --git a/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/service/UserService.java b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/service/UserService.java new file mode 100644 index 0000000..5e0e867 --- /dev/null +++ b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/service/UserService.java @@ -0,0 +1,9 @@ +package com.itheima.springbootweb01.service; + +import com.itheima.springbootweb01.pojo.User; + +import java.util.List; + +public interface UserService { + public List findAll(); +} diff --git a/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/service/lmpl/UserServiceImpl.java b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/service/lmpl/UserServiceImpl.java new file mode 100644 index 0000000..f20fab7 --- /dev/null +++ b/04. 后端Web基础(基础知识)/springboot-web-01/src/main/java/com/itheima/springbootweb01/service/lmpl/UserServiceImpl.java @@ -0,0 +1,35 @@ +package com.itheima.springbootweb01.service.lmpl; + +import com.itheima.springbootweb01.dao.UserDao; +import com.itheima.springbootweb01.dao.impl.UserDaoImpl; +import com.itheima.springbootweb01.pojo.User; +import com.itheima.springbootweb01.service.UserService; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + +public class UserServiceImpl implements UserService { + /** + * 业务逻辑层 + */ + private UserDao userDao = new UserDaoImpl(); + @Override + public List findAll() { + //1.加载Dao层数据 + List lines = userDao.findAll(); + + //2.将用户数据封装成User对象 ->list集合 + List userList= lines.stream().map(line -> { + String[] split = line.split(","); + Integer id = Integer.parseInt(split[0]); + String username = split[1]; + String password = split[2]; + String name = split[3]; + Integer age = Integer.parseInt(split[4]); + LocalDateTime updateTime = LocalDateTime.parse(split[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + return new User(id, username, password, name, age, updateTime); + }).toList(); + return userList; + } +} diff --git a/04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/controller/UserController.class b/04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/controller/UserController.class index 68d5dc0b34e26edb795214ec18cde76a5b455c57..ce4c529f70f4652a6f404d4250eb0759d5d63b59 100644 GIT binary patch delta 474 zcmZus%TB^j6r2l`3#BNcpdvm{R4B$qHyDT}E=juckr>?&#iXVhBagV_8%#gKttJ{G zChqlD-1!0OwAJ9k#XVf2}k1;8d&Zd4;I5fRvM;!1Y4*|_Rh#|^_i zzqE}#vK?Qjk*kmhMiGN15!Wz;VW+QD60!EcCa`9@Ir-n5KM~a!Mv#;k)i8#XfZ-a~ z|1k>4Q|sbn+qMOgg`#;@@6?TU%d!pAYPPD*hjQ)QhRcpBYhvEnm9I`HdelXZn+5nO z!OGo;0>lc!tZA|>1c`uz-h|soa3yjcRzy=vX~&(d_N|UArqKFiZeHB zpUizr(;uKdAtBH;OLr847zC9WSn-0=zWFD}eI|=(M$EVo?7lKfG)E=Gp2GrB0C_C3 Z4^dg-Sw4hlqCmaqO?7YTez3%Cz5x=fO921? literal 3435 zcmbVOTUXRp6#fnj1je9<1w~s?iwX=F#aflIwu(||2ep7&wbq820D(+0CK(iazu)io z+Yjhl+Xtk&R#%_9`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wq7udQwD~E#!NNlIlDh@P2 zHCQ94<#Gj~I}H#ht)74kMv1|HL&x+JUY)XmeQ8 zw0@2mpZXQ8chGk67Pil0#~)}L>YhW#ZFB>_VQ&>54-1^``I#51m9iGv18hSBt!(4u z*hAL+oV%p*u1GUVFj0*P>nZHrTe_*hysc#NPGO6m`c^sd|si9P&_jIbJw=a>Z z?d_{cX)(R8HdWW#l$pord5rdHcW~)qcTa1gwWhVURl9{}q{9)qJCxvda6-myf} z%^|%*4ybgv3kQ)>&JRZh;CZ~jyBdyje0!1Rt>@tP5?-dXX3m+f@U)uu4ZO;?1f_K0 zHNMqwZNuy2tEI#yyn#0xMr^}RAuv8^mkNbn<><=j+-APoKj^Dj^rM&|Q7Tv{lIbX6o`BbBAP dzX6j^w@V;2?0kUio)%o|J?k8_t@3LXyaAdHJAMEF literal 0 HcmV?d00001 diff --git a/04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/dao/impl/UserDaoImpl.class b/04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/dao/impl/UserDaoImpl.class new file mode 100644 index 0000000000000000000000000000000000000000..4fc920f0d3c3d3c30c7884edef8eb962135bb006 GIT binary patch literal 1236 zcmah|Sx*yD6#gzP3@yWA3kbNBxLA+4hy0}NwF`~x>!?lp{8^&`hp z398H$k`kBqD)_X9^6HN`!f`*tP%Qyuyb z_IKZ{Gt9(3&Kf61riNLnSH#s(!Zo&ipC4C6Kv@-#%Hl5WX}GUr4)Y9CmS;3ON=nzT zr0*DEgz|u33>iwtt_sf~w{Mf2dJ?!ih*%T(uSnOWJ`3q}%g`&4+9L zf_7N8x|HgpQ(sv%Y%UGaYP-e(b!dmnJ$h?cWSGASl>ivh6=^#(C1FM{JFU9o@AJA# zl3Z0<+&$#J2>*#Nt(t=JUaMZk-y4<5puHEKz3oy7bKQB1G7ft{>OSGoNW}%}sVDW< zjSHUWBiz3R5_s}_u*dCgz{!N22W-S%qHRkiaf?VYHPP_6>iCrX+=UP?0cC5^obQUT zW@BgiupEvWiYU?MGAz*6hc_)dolEpH=w@{HFPwsXiPR714AsC8mg&@E12SEqAHyov zh$I9bBaIZ@#f1}SCm70IJ3+p>_!ZMXP4j~U*4 z^LXCw09F`!Xc0tW&Vubp@mY$hC^=7KW9(JM^M$BXdErEfy@Tk(9y)|kCNENGnWthG zXDYD-@5uRKqcveXnTE~0wyZ_Sl?@1kh|^r!x>SVVXJHxsvnWhv8iio(n*7MrWumsM gUDfEzZ1z6dBM{o|KY*NQ7d@9fms;pM8Z_j;0Q1X8)&Kwi literal 0 HcmV?d00001 diff --git a/04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/service/lmpl/UserServiceImpl.class b/04. 后端Web基础(基础知识)/springboot-web-01/target/classes/com/itheima/springbootweb01/service/lmpl/UserServiceImpl.class new file mode 100644 index 0000000000000000000000000000000000000000..b071f38ea3de47527d3c30c670f17f62a949ba20 GIT binary patch literal 2891 zcmb7GZFAE`5Pr^ftV9uD3<($tNz(v{ogheQ0V|}1&@^rxpg2G&E$!Ks69v5?$$|9! zV}DLN)0O};{Q;eR?ceEiPm+n$WIQyU={GBG2N*8(10mH-qou2652z6d1Q>(Vji4E( z>-|uKE3p^aFb<+9;gEvE7-2Z`ntEicW7zGhCYdcxP1i$ux`AP;b;Az`^$3niC@DCG z;|%-L)5M)0csjQjj;C}ZsoDr9wIc1r2?ZxH#xTHL*W6+lORev8?N(qowz?E|$ncw( zknom*Nt|LhvST=fO`B$Mm&l$?GS`l4tu zuHyp3a&KEhmAcd7X3s2f8xp~AFUi8hyzqzDODFd2>j~Gt% zJ0z~N5uGj>HPl7i&7R(aDTNin43F82&Ej)l2k-S8QzeTz=d&R(TUqm47k6oC{X4t7cjCATPR z;)GGcrp<4;Jr^ebqc*>r$_27=dDpUj)V$hCP3R6aj5V7FU5{wcQe{Z^Hs3e+G*ZFj zRqxk!@bYb2MuZaY5d45bKVkMyI34X5k1^d&>&&f!Fgi3{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