From fb98b738a1b2694b62cebbc06f49f742005adf03 Mon Sep 17 00:00:00 2001 From: Yiming Zeng Date: Tue, 20 Jun 2023 18:09:52 +0800 Subject: [PATCH 1/4] =?UTF-8?q?Java=20=E9=9B=86=E5=90=88=20=E5=8F=8D?= =?UTF-8?q?=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/hongyi/test/Test.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 javase/src/main/java/com/hongyi/test/Test.java diff --git a/javase/src/main/java/com/hongyi/test/Test.java b/javase/src/main/java/com/hongyi/test/Test.java new file mode 100644 index 0000000..8d24514 --- /dev/null +++ b/javase/src/main/java/com/hongyi/test/Test.java @@ -0,0 +1,21 @@ +package com.hongyi.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/20 16:38 + * @Version 1.0 + */ +public class Test { + public static void main(String[] args) { + ArrayList arrayList = new ArrayList(); + arrayList.add(123); + System.out.println(arrayList); + Map map = new HashMap<>(); + map.put(null, null); + System.out.println(map); + } +} -- Gitee From f4ba7999fd0b546f6ca5815062c231b80f0a0d58 Mon Sep 17 00:00:00 2001 From: Yiming Zeng Date: Wed, 21 Jun 2023 11:56:22 +0800 Subject: [PATCH 2/4] =?UTF-8?q?Java=20=E5=8A=A8=E6=80=81=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/hongyi/day24/ProxyTest.java | 81 +++++++++++++++++++ .../src/main/java/com/hongyi/proxy/Human.java | 12 +++ .../com/hongyi/proxy/MyInvocationHandler.java | 32 ++++++++ .../main/java/com/hongyi/proxy/ProxyTest.java | 16 ++++ .../main/java/com/hongyi/proxy/SuperMan.java | 19 +++++ .../main/java/com/hongyi/test/InvokeTest.java | 27 +++++++ 6 files changed, 187 insertions(+) create mode 100644 javase/src/main/java/com/hongyi/day24/ProxyTest.java create mode 100644 javase/src/main/java/com/hongyi/proxy/Human.java create mode 100644 javase/src/main/java/com/hongyi/proxy/MyInvocationHandler.java create mode 100644 javase/src/main/java/com/hongyi/proxy/ProxyTest.java create mode 100644 javase/src/main/java/com/hongyi/proxy/SuperMan.java create mode 100644 javase/src/main/java/com/hongyi/test/InvokeTest.java diff --git a/javase/src/main/java/com/hongyi/day24/ProxyTest.java b/javase/src/main/java/com/hongyi/day24/ProxyTest.java new file mode 100644 index 0000000..3f9ff90 --- /dev/null +++ b/javase/src/main/java/com/hongyi/day24/ProxyTest.java @@ -0,0 +1,81 @@ +package com.hongyi.day24; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/21 11:14 + * @Version 1.0 + */ + +interface Human { + String getBelief(); + + void eat(String food); +} + +// 被代理类 +class SuperMan implements Human { + + @Override + public String getBelief() { + return "I believe I can fly!"; + } + + @Override + public void eat(String food) { + System.out.println("I like eating " + food); + } +} + +// 代理类的工厂 +class ProxyFactory { + /** + * 通过被代理类对象 动态获取 代理类对象 + * @param obj 被代理类的对象 + * @return 代理类对象 + */ + public static Object getProxyInstance(Object obj) { + MyInvocationHandler handler = new MyInvocationHandler(); + handler.bind(obj); + return Proxy.newProxyInstance( + obj.getClass().getClassLoader(), + obj.getClass().getInterfaces(), + handler + ); + } +} + +class MyInvocationHandler implements InvocationHandler { + + private Object obj; + + public void bind(Object obj) { + this.obj = obj; + } + + /** + * 当通过代理类的对象,调用方法A时,就会动态调用这个方法 + * @param proxy 代理类对象 + * @param method 要调用的代理类对象的方法 + * @param args 方法参数 + * @return + * @throws Throwable + */ + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return method.invoke(obj, args); + } + +} + +public class ProxyTest { + public static void main(String[] args) { + // 代理类对象 + Human proxyInstance = (Human) ProxyFactory.getProxyInstance(new SuperMan()); + System.out.println(proxyInstance.getBelief()); + proxyInstance.eat("banana"); + } +} diff --git a/javase/src/main/java/com/hongyi/proxy/Human.java b/javase/src/main/java/com/hongyi/proxy/Human.java new file mode 100644 index 0000000..969a96c --- /dev/null +++ b/javase/src/main/java/com/hongyi/proxy/Human.java @@ -0,0 +1,12 @@ +package com.hongyi.proxy; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/21 11:44 + * @Version 1.0 + */ +public interface Human { + String getBelief(); + + void eat(String food); +} diff --git a/javase/src/main/java/com/hongyi/proxy/MyInvocationHandler.java b/javase/src/main/java/com/hongyi/proxy/MyInvocationHandler.java new file mode 100644 index 0000000..fbb5dd5 --- /dev/null +++ b/javase/src/main/java/com/hongyi/proxy/MyInvocationHandler.java @@ -0,0 +1,32 @@ +package com.hongyi.proxy; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/21 11:45 + * @Version 1.0 + */ +class MyInvocationHandler implements InvocationHandler { + + private Object obj; + + public void bind(Object obj) { + this.obj = obj; + } + + /** + * 当通过代理类的对象,调用方法A时,就会动态调用这个方法 + * @param proxy 代理类对象 + * @param method 要调用的代理类对象的方法 + * @param args 方法参数 + * @return + * @throws Throwable + */ + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return method.invoke(obj, args); + } + +} diff --git a/javase/src/main/java/com/hongyi/proxy/ProxyTest.java b/javase/src/main/java/com/hongyi/proxy/ProxyTest.java new file mode 100644 index 0000000..6084574 --- /dev/null +++ b/javase/src/main/java/com/hongyi/proxy/ProxyTest.java @@ -0,0 +1,16 @@ +package com.hongyi.proxy; + + +/** + * @Author Kisugi Takumi + * @Date 2023/6/21 11:44 + * @Version 1.0 + */ +public class ProxyTest { + public static void main(String[] args) { + // 代理类对象 + Human proxyInstance = (Human) ProxyFactory.getProxyInstance(new SuperMan()); + System.out.println(proxyInstance.getBelief()); + proxyInstance.eat("banana"); + } +} diff --git a/javase/src/main/java/com/hongyi/proxy/SuperMan.java b/javase/src/main/java/com/hongyi/proxy/SuperMan.java new file mode 100644 index 0000000..7d38bf9 --- /dev/null +++ b/javase/src/main/java/com/hongyi/proxy/SuperMan.java @@ -0,0 +1,19 @@ +package com.hongyi.proxy; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/21 11:44 + * @Version 1.0 + */ +// 被代理类 +public class SuperMan implements Human{ + @Override + public String getBelief() { + return "I believe I can fly!"; + } + + @Override + public void eat(String food) { + System.out.println("I like eating " + food); + } +} diff --git a/javase/src/main/java/com/hongyi/test/InvokeTest.java b/javase/src/main/java/com/hongyi/test/InvokeTest.java new file mode 100644 index 0000000..d794043 --- /dev/null +++ b/javase/src/main/java/com/hongyi/test/InvokeTest.java @@ -0,0 +1,27 @@ +package com.hongyi.test; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/20 18:00 + * @Version 1.0 + */ +public class InvokeTest { + + public void test(String[] arg){ + for (String string : arg) { + System.out.println(string); + } + } + + public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Class clazz = InvokeTest.class; + String[] s = new String[]{"Hello","World"}; + // test: 方法名 + // String[].class: test方法的形参类型 + Method method = clazz.getMethod("test", String[].class); + method.invoke(new InvokeTest(), (Object) s); + } +} -- Gitee From 8000e21f7c97a6b4aad4c3b60a80f5474b5765d2 Mon Sep 17 00:00:00 2001 From: Yiming Zeng Date: Sat, 24 Jun 2023 15:01:40 +0800 Subject: [PATCH 3/4] =?UTF-8?q?ssm=E6=95=B4=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hongyi/proxy/ProxyFactory.java | 26 +++++ ssm/ssm_demo/pom.xml | 94 +++++++++++++++++++ .../java/com/hongyi/config/JdbcConfig.java | 37 ++++++++ .../java/com/hongyi/config/MybatisConfig.java | 31 ++++++ .../java/com/hongyi/config/ServletConfig.java | 25 +++++ .../java/com/hongyi/config/SpringConfig.java | 19 ++++ .../com/hongyi/config/SpringMvcConfig.java | 17 ++++ .../src/main/resources/jdbc.properties | 4 + ssm/ssm_demo/src/main/webapp/WEB-INF/web.xml | 7 ++ ssm/ssm_demo/src/main/webapp/index.jsp | 5 + 10 files changed, 265 insertions(+) create mode 100644 javase/src/main/java/com/hongyi/proxy/ProxyFactory.java create mode 100644 ssm/ssm_demo/pom.xml create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/config/JdbcConfig.java create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/config/MybatisConfig.java create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/config/ServletConfig.java create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/config/SpringConfig.java create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/config/SpringMvcConfig.java create mode 100644 ssm/ssm_demo/src/main/resources/jdbc.properties create mode 100644 ssm/ssm_demo/src/main/webapp/WEB-INF/web.xml create mode 100644 ssm/ssm_demo/src/main/webapp/index.jsp diff --git a/javase/src/main/java/com/hongyi/proxy/ProxyFactory.java b/javase/src/main/java/com/hongyi/proxy/ProxyFactory.java new file mode 100644 index 0000000..d000d32 --- /dev/null +++ b/javase/src/main/java/com/hongyi/proxy/ProxyFactory.java @@ -0,0 +1,26 @@ +package com.hongyi.proxy; + +import java.lang.reflect.Proxy; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/21 11:45 + * @Version 1.0 + */ +// 代理类的工厂 +class ProxyFactory { + /** + * 通过被代理类对象 动态获取 代理类对象 + * @param obj 被代理类的对象 + * @return 代理类对象 + */ + public static Object getProxyInstance(Object obj) { + return Proxy.newProxyInstance( + obj.getClass().getClassLoader(), + obj.getClass().getInterfaces(), + (proxy, method, args) -> { + return method.invoke(obj, args); + } + ); + } +} diff --git a/ssm/ssm_demo/pom.xml b/ssm/ssm_demo/pom.xml new file mode 100644 index 0000000..c7606ed --- /dev/null +++ b/ssm/ssm_demo/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + com.hongyi + ssm_demo + 1.0-SNAPSHOT + war + + + UTF-8 + 1.7 + 1.7 + + + + + org.springframework + spring-webmvc + 5.2.10.RELEASE + + + + org.springframework + spring-jdbc + 5.2.10.RELEASE + + + + org.springframework + spring-test + 5.2.10.RELEASE + + + + org.mybatis + mybatis + 3.5.6 + + + + org.mybatis + mybatis-spring + 1.3.0 + + + + mysql + mysql-connector-java + 5.1.47 + + + + com.alibaba + druid + 1.1.16 + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + + com.fasterxml.jackson.core + jackson-databind + 2.9.10 + + + + junit + junit + 4.11 + test + + + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.1 + + 80 + / + + + + + diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/config/JdbcConfig.java b/ssm/ssm_demo/src/main/java/com/hongyi/config/JdbcConfig.java new file mode 100644 index 0000000..a96baf5 --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/config/JdbcConfig.java @@ -0,0 +1,37 @@ +package com.hongyi.config; + +import com.alibaba.druid.pool.DruidDataSource; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; + +import javax.sql.DataSource; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 13:56 + * @Version 1.0 + */ + +public class JdbcConfig { + @Value("${jdbc.driver}") + private String driver; + + @Value("${jdbc.url}") + private String url; + + @Value("${jdbc.username}") + private String username; + + @Value("${jdbc.password}") + private String password; + + @Bean + public DataSource dataSource() { + DruidDataSource dataSource = new DruidDataSource(); + dataSource.setDriverClassName(driver); + dataSource.setUrl(url); + dataSource.setUsername(username); + dataSource.setPassword(password); + return dataSource; + } +} diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/config/MybatisConfig.java b/ssm/ssm_demo/src/main/java/com/hongyi/config/MybatisConfig.java new file mode 100644 index 0000000..009cb4e --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/config/MybatisConfig.java @@ -0,0 +1,31 @@ +package com.hongyi.config; + +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.mapper.MapperScannerConfigurer; +import org.springframework.context.annotation.Bean; + +import javax.sql.DataSource; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 13:56 + * @Version 1.0 + */ +public class MybatisConfig { + + @Bean + public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) { + SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); + // 设置数据源 + factoryBean.setDataSource(dataSource); + factoryBean.setTypeAliasesPackage("com.hongyi.domain"); + return factoryBean; + } + + @Bean + public MapperScannerConfigurer mapperScannerConfigurer() { + MapperScannerConfigurer msc = new MapperScannerConfigurer(); + msc.setBasePackage("com.hongyi.dao"); + return msc; + } +} diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/config/ServletConfig.java b/ssm/ssm_demo/src/main/java/com/hongyi/config/ServletConfig.java new file mode 100644 index 0000000..97b425b --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/config/ServletConfig.java @@ -0,0 +1,25 @@ +package com.hongyi.config; + +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 14:13 + * @Version 1.0 + */ +public class ServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer { + @Override + protected Class[] getRootConfigClasses() { + return new Class[]{SpringConfig.class}; + } + + @Override + protected Class[] getServletConfigClasses() { + return new Class[]{SpringMvcConfig.class}; + } + + @Override + protected String[] getServletMappings() { + return new String[]{"/"}; + } +} diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/config/SpringConfig.java b/ssm/ssm_demo/src/main/java/com/hongyi/config/SpringConfig.java new file mode 100644 index 0000000..242d873 --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/config/SpringConfig.java @@ -0,0 +1,19 @@ +package com.hongyi.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.PropertySource; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 13:55 + * @Version 1.0 + */ +@Configuration +@ComponentScan({"com.hongyi.service"}) +@PropertySource("jdbc.properties") +@Import({JdbcConfig.class, MybatisConfig.class}) +public class SpringConfig { + +} diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/config/SpringMvcConfig.java b/ssm/ssm_demo/src/main/java/com/hongyi/config/SpringMvcConfig.java new file mode 100644 index 0000000..8221b93 --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/config/SpringMvcConfig.java @@ -0,0 +1,17 @@ +package com.hongyi.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 14:14 + * @Version 1.0 + */ +@Configuration +@ComponentScan("com.hongyi.controller") +@EnableWebMvc +public class SpringMvcConfig { + +} diff --git a/ssm/ssm_demo/src/main/resources/jdbc.properties b/ssm/ssm_demo/src/main/resources/jdbc.properties new file mode 100644 index 0000000..a9d4261 --- /dev/null +++ b/ssm/ssm_demo/src/main/resources/jdbc.properties @@ -0,0 +1,4 @@ +jdbc.driver=com.mysql.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/ssm_db +jdbc.username=root +jdbc.password=root \ No newline at end of file diff --git a/ssm/ssm_demo/src/main/webapp/WEB-INF/web.xml b/ssm/ssm_demo/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9f88c1f --- /dev/null +++ b/ssm/ssm_demo/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + + Archetype Created Web Application + diff --git a/ssm/ssm_demo/src/main/webapp/index.jsp b/ssm/ssm_demo/src/main/webapp/index.jsp new file mode 100644 index 0000000..c38169b --- /dev/null +++ b/ssm/ssm_demo/src/main/webapp/index.jsp @@ -0,0 +1,5 @@ + + +

Hello World!

+ + -- Gitee From bedd0ad2620f8e49957c70fead7d95578ca6dfef Mon Sep 17 00:00:00 2001 From: Yiming Zeng Date: Sat, 24 Jun 2023 15:48:37 +0800 Subject: [PATCH 4/4] =?UTF-8?q?java=20ssm=E6=95=B4=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ssm/ssm_demo/pom.xml | 5 ++ .../com/hongyi/controller/BookController.java | 45 ++++++++++++++++++ .../src/main/java/com/hongyi/dao/BookDao.java | 33 +++++++++++++ .../src/main/java/com/hongyi/domain/Book.java | 18 +++++++ .../java/com/hongyi/service/BookService.java | 28 +++++++++++ .../hongyi/service/impl/BookServiceImpl.java | 47 +++++++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/controller/BookController.java create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/dao/BookDao.java create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/domain/Book.java create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/service/BookService.java create mode 100644 ssm/ssm_demo/src/main/java/com/hongyi/service/impl/BookServiceImpl.java diff --git a/ssm/ssm_demo/pom.xml b/ssm/ssm_demo/pom.xml index c7606ed..d224e4d 100644 --- a/ssm/ssm_demo/pom.xml +++ b/ssm/ssm_demo/pom.xml @@ -16,6 +16,11 @@ + + org.projectlombok + lombok + 1.18.22 + org.springframework spring-webmvc diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/controller/BookController.java b/ssm/ssm_demo/src/main/java/com/hongyi/controller/BookController.java new file mode 100644 index 0000000..7f3489b --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/controller/BookController.java @@ -0,0 +1,45 @@ +package com.hongyi.controller; + +import com.hongyi.domain.Book; +import com.hongyi.service.BookService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 15:05 + * @Version 1.0 + */ +@RestController +@RequestMapping("/books") +public class BookController { + @Autowired + private BookService bookService; + + @PostMapping + public boolean save(@RequestBody Book book) { + return bookService.save(book); + } + + @PutMapping + public boolean update(@RequestBody Book book) { + return bookService.update(book); + } + + @DeleteMapping("/{id}") + public boolean delete(@PathVariable Integer id) { + return bookService.delete(id); + } + + @GetMapping("/{id}") + public Book getById(@PathVariable Integer id) { + return bookService.getById(id); + } + + @GetMapping + public List getAll() { + return bookService.getAll(); + } +} diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/dao/BookDao.java b/ssm/ssm_demo/src/main/java/com/hongyi/dao/BookDao.java new file mode 100644 index 0000000..a0906ad --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/dao/BookDao.java @@ -0,0 +1,33 @@ +package com.hongyi.dao; + +import com.hongyi.domain.Book; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 15:04 + * @Version 1.0 + */ +@Repository +public interface BookDao { + @Insert("INSERT INTO tbl_book VALUES (null, #{type}, #{name}, #{description})") + public void save(Book book); + + @Update("UPDATE tbl_book SET type=#{type}, name=#{name}, description=#{description} WHERE id=#{id}") + public void update(Book book); + + @Delete("DELETE FROM tbl_book WHERE id=#{id}") + public void delete(Integer id); + + @Select("SELECT * FROM tbl_book WHERE id=#{id}") + public Book getById(Integer id); + + @Select("SELECT * FROM tbl_book") + public List getAll(); +} diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/domain/Book.java b/ssm/ssm_demo/src/main/java/com/hongyi/domain/Book.java new file mode 100644 index 0000000..8cd4ece --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/domain/Book.java @@ -0,0 +1,18 @@ +package com.hongyi.domain; + +import lombok.Data; +import lombok.ToString; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 15:02 + * @Version 1.0 + */ +@Data +@ToString +public class Book { + private Integer id; + private String type; + private String name; + private String description; +} diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/service/BookService.java b/ssm/ssm_demo/src/main/java/com/hongyi/service/BookService.java new file mode 100644 index 0000000..733be1e --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/service/BookService.java @@ -0,0 +1,28 @@ +package com.hongyi.service; + +import com.hongyi.domain.Book; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 15:04 + * @Version 1.0 + */ +@Service +public interface BookService { + public boolean save(Book book); + + public boolean update(Book book); + + public boolean delete(Integer id); + + public Book getById(Integer id); + + public List getAll(); +} diff --git a/ssm/ssm_demo/src/main/java/com/hongyi/service/impl/BookServiceImpl.java b/ssm/ssm_demo/src/main/java/com/hongyi/service/impl/BookServiceImpl.java new file mode 100644 index 0000000..6d6883a --- /dev/null +++ b/ssm/ssm_demo/src/main/java/com/hongyi/service/impl/BookServiceImpl.java @@ -0,0 +1,47 @@ +package com.hongyi.service.impl; + +import com.hongyi.dao.BookDao; +import com.hongyi.domain.Book; +import com.hongyi.service.BookService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +/** + * @Author Kisugi Takumi + * @Date 2023/6/24 15:04 + * @Version 1.0 + */ +public class BookServiceImpl implements BookService { + + @Autowired + private BookDao bookDao; + + @Override + public boolean save(Book book) { + bookDao.save(book); + return true; + } + + @Override + public boolean update(Book book) { + bookDao.update(book); + return true; + } + + @Override + public boolean delete(Integer id) { + bookDao.delete(id); + return true; + } + + @Override + public Book getById(Integer id) { + return bookDao.getById(id); + } + + @Override + public List getAll() { + return bookDao.getAll(); + } +} -- Gitee