diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/.gitignore" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..35410cacdc5e87f985c93a96520f5e11a5c822e4 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/.gitignore" @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/compiler.xml" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/compiler.xml" new file mode 100644 index 0000000000000000000000000000000000000000..279a5e62b912c15e3fb6a9b39ca64455b4539cd6 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/compiler.xml" @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/dataSources.xml" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/dataSources.xml" new file mode 100644 index 0000000000000000000000000000000000000000..83108488c3741775f9f5fc416261c9c629fcde6a --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/dataSources.xml" @@ -0,0 +1,12 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 + $ProjectFileDir$ + + + \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/encodings.xml" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/encodings.xml" new file mode 100644 index 0000000000000000000000000000000000000000..aa00ffab7828f4818589659c804ec2cfd99baed3 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/encodings.xml" @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/jarRepositories.xml" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/jarRepositories.xml" new file mode 100644 index 0000000000000000000000000000000000000000..abb532ab355ddfa5ec01bd4393fcda38f88224b0 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/jarRepositories.xml" @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/misc.xml" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/misc.xml" new file mode 100644 index 0000000000000000000000000000000000000000..132404bc29da2535f7f7dde84180d85abc60d5a4 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/misc.xml" @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/sqldialects.xml" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/sqldialects.xml" new file mode 100644 index 0000000000000000000000000000000000000000..539d872a336fddf37cb3f9acf17d8a5d801d1cd9 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/sqldialects.xml" @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/uiDesigner.xml" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/uiDesigner.xml" new file mode 100644 index 0000000000000000000000000000000000000000..2b63946d5b31084bbb7dda418ceb3d75eb686373 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/.idea/uiDesigner.xml" @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/pom.xml" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/pom.xml" new file mode 100644 index 0000000000000000000000000000000000000000..3ecc1296e180b78cb8edd8210b57e78e177ad364 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/pom.xml" @@ -0,0 +1,69 @@ + + + 4.0.0 + + org.example + spring + 1.0-SNAPSHOT + + + + org.projectlombok + lombok + 1.18.36 + compile + + + + org.mybatis + mybatis + 3.5.16 + + + + com.mysql + mysql-connector-j + 8.3.0 + + + + junit + junit + 4.13.2 + test + + + + org.springframework + spring-context + 5.3.39 + + + + org.springframework + spring-jdbc + 5.3.39 + + + + com.alibaba + druid + 1.1.21 + + + + org.mybatis + mybatis-spring + 2.0.6 + + + + org.springframework + spring-test + 5.3.39 + + + + \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/config/JdbcConfig.java" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/config/JdbcConfig.java" new file mode 100644 index 0000000000000000000000000000000000000000..c41efbbbc558624bf33f76e932734de33ccdef81 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/config/JdbcConfig.java" @@ -0,0 +1,32 @@ +package com.aldd.config; + +import com.alibaba.druid.pool.DruidDataSource; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Component; + +import javax.sql.DataSource; + +@Component +@PropertySource("classpath:jdbc.properties") +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 DruidDataSource() { + DruidDataSource dataSource = new DruidDataSource(); + dataSource.setDriverClassName(driver); + dataSource.setUrl(url); + dataSource.setUsername(username); + dataSource.setPassword(password); + return dataSource; + } +} diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/config/MybatisConfig.java" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/config/MybatisConfig.java" new file mode 100644 index 0000000000000000000000000000000000000000..3d52bf7ff6b064a4248987a35061f09ee24402bf --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/config/MybatisConfig.java" @@ -0,0 +1,19 @@ +package com.aldd.config; + +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +import javax.sql.DataSource; + +@Component +@MapperScan("com.aldd.mapper") +public class MybatisConfig { + @Bean + public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) { + SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); + sqlSessionFactoryBean.setDataSource(dataSource); + return sqlSessionFactoryBean; + } +} diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/config/SpringConfig.java" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/config/SpringConfig.java" new file mode 100644 index 0000000000000000000000000000000000000000..6d534a68c326ce957ca594b70ac574ba90b5cf6a --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/config/SpringConfig.java" @@ -0,0 +1,12 @@ +package com.aldd.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration +@ComponentScan({"com.aldd.controller", "com.aldd.service","com.aldd.entity"}) +@Import({JdbcConfig.class, MybatisConfig.class}) +public class SpringConfig { + +} diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/controller/BookController.java" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/controller/BookController.java" new file mode 100644 index 0000000000000000000000000000000000000000..68e2950d051b985128d0ac5325e83ebd458370bf --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/controller/BookController.java" @@ -0,0 +1,38 @@ +package com.aldd.controller; + +import com.aldd.entity.Book; +import com.aldd.mapper.BookMapper; +import com.aldd.service.BookService; +import lombok.Data; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Data +@Controller +public class BookController { + @Autowired + private BookService bookService; + + public List selectAllBook() { + return bookService.selectAllBook(); + } + + public Book selectBookById(int id) { + return bookService.selectBookById(id); + } + + public String deleteBook(int id) { + return bookService.deleteBook(id) ? "删除成功" : "删除失败"; + } + + public String insertBook(Book book) { + return bookService.insertBook(book) ? "添加成功" : "添加失败"; + } + + public String updateBook(Book book) { + return bookService.updateBook(book) ? "修改成功" : "修改失败"; + } +} diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/entity/Book.java" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/entity/Book.java" new file mode 100644 index 0000000000000000000000000000000000000000..4461722713ceb7e1f985a76576137ee64132545b --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/entity/Book.java" @@ -0,0 +1,15 @@ +package com.aldd.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.stereotype.Component; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Component +public class Book { + private int bookId; + private String bookName; +} diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/mapper/BookMapper.java" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/mapper/BookMapper.java" new file mode 100644 index 0000000000000000000000000000000000000000..ecca1518888b44a704e72ab3b7ba4bf8e9661141 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/mapper/BookMapper.java" @@ -0,0 +1,23 @@ +package com.aldd.mapper; + +import com.aldd.entity.Book; +import org.apache.ibatis.annotations.*; + +import java.util.List; +@Mapper +public interface BookMapper { + @Select("select book_id bookId,book_name bookName from book") + List selectAllBook(); + + @Select("select book_id bookId,book_name bookName from book where book_id=#{id}") + Book selectBookById(int id); + + @Delete("delete from book where book_id=#{id}") + int deleteBook(int id); + + @Insert("insert into book(book_name)values (#{bookName})") + int insertBook(Book book); + + @Update("update book set book_name=#{bookName} where book_id=#{bookId}") + int updateBook(Book book); +} diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/service/BookService.java" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/service/BookService.java" new file mode 100644 index 0000000000000000000000000000000000000000..e503217613474aca5ac56ac5138f91211b7a21a3 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/service/BookService.java" @@ -0,0 +1,16 @@ +package com.aldd.service; + +import com.aldd.entity.Book; +import java.util.List; + +public interface BookService { + List selectAllBook(); + + Book selectBookById(int id); + + Boolean deleteBook(int id); + + Boolean insertBook(Book book); + + Boolean updateBook(Book book); +} diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/service/impl/BookServiceImpl.java" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/service/impl/BookServiceImpl.java" new file mode 100644 index 0000000000000000000000000000000000000000..061ba03b22cd68395b6e18aedfdc7d3515621456 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/java/com/aldd/service/impl/BookServiceImpl.java" @@ -0,0 +1,42 @@ +package com.aldd.service.impl; + +import com.aldd.entity.Book; +import com.aldd.mapper.BookMapper; +import com.aldd.service.BookService; +import lombok.Data; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Data +@Service +public class BookServiceImpl implements BookService { + @Autowired + private BookMapper mapper; + + @Override + public List selectAllBook() { + return mapper.selectAllBook(); + } + + @Override + public Book selectBookById(int id) { + return mapper.selectBookById(id); + } + + @Override + public Boolean deleteBook(int id) { + return mapper.deleteBook(id) > 0; + } + + @Override + public Boolean insertBook(Book book) { + return mapper.insertBook(book) > 0; + } + + @Override + public Boolean updateBook(Book book) { + return mapper.updateBook(book) > 0; + } +} diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/resources/jdbc.properties" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/resources/jdbc.properties" new file mode 100644 index 0000000000000000000000000000000000000000..7109942280246ebbf3dd006ae26056df5c553649 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/main/resources/jdbc.properties" @@ -0,0 +1,4 @@ +jdbc.driver=com.mysql.cj.jdbc.Driver +jdbc.url=jdbc:mysql:///aldd +jdbc.username=root +jdbc.password=123456 \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/test/java/com/aldd/test/TestBook.java" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/test/java/com/aldd/test/TestBook.java" new file mode 100644 index 0000000000000000000000000000000000000000..85f0604774fe05734108de0e0aa77ce6ecff51d5 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/src/test/java/com/aldd/test/TestBook.java" @@ -0,0 +1,48 @@ +package com.aldd.test; + +import com.aldd.config.SpringConfig; +import com.aldd.controller.BookController; +import com.aldd.entity.Book; +import com.aldd.mapper.BookMapper; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.lang.annotation.AnnotationTypeMismatchException; +import java.util.List; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = SpringConfig.class) +public class TestBook { + @Autowired + private BookController bookController; + @Autowired + private Book book; + + @Test + public void t1() { + ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class); + BookMapper bookMapper = context.getBean(BookMapper.class); + List bookList = bookMapper.selectAllBook(); + System.out.println(bookList); + } + + @Test + public void T2() { + Book book = bookController.selectBookById(1); + System.out.println(book); + } + + @Test + public void T3() { + book.setBookId(1); + book.setBookName("比伦挖穿地球的一百天"); + String s = bookController.updateBook(book); + System.out.println(s); + } +} diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/config/JdbcConfig.class" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/config/JdbcConfig.class" new file mode 100644 index 0000000000000000000000000000000000000000..52d7d64a301fe694b2c53b65b6b8897dbb4f0e84 Binary files /dev/null and "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/config/JdbcConfig.class" differ diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/config/MybatisConfig.class" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/config/MybatisConfig.class" new file mode 100644 index 0000000000000000000000000000000000000000..7327a9783abb16825324ece6c366a5d577987874 Binary files /dev/null and "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/config/MybatisConfig.class" differ diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/config/SpringConfig.class" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/config/SpringConfig.class" new file mode 100644 index 0000000000000000000000000000000000000000..7e1895f1c9922d1d3ada1569cfa9662525277290 Binary files /dev/null and "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/config/SpringConfig.class" differ diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/controller/BookController.class" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/controller/BookController.class" new file mode 100644 index 0000000000000000000000000000000000000000..9ef5eee2c01c4a89acd65a5b4929c2e8cbf978a4 Binary files /dev/null and "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/controller/BookController.class" differ diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/entity/Book.class" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/entity/Book.class" new file mode 100644 index 0000000000000000000000000000000000000000..a311c32ea59ec925c76cddc702aae3b714d6160e Binary files /dev/null and "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/entity/Book.class" differ diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/mapper/BookMapper.class" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/mapper/BookMapper.class" new file mode 100644 index 0000000000000000000000000000000000000000..823dbdb2b7ec0a109f1f787521ce7747118d396c Binary files /dev/null and "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/mapper/BookMapper.class" differ diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/service/BookService.class" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/service/BookService.class" new file mode 100644 index 0000000000000000000000000000000000000000..262bc356e8b9b0224f6bd2728cf8495844ebd10a Binary files /dev/null and "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/service/BookService.class" differ diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/service/impl/BookServiceImpl.class" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/service/impl/BookServiceImpl.class" new file mode 100644 index 0000000000000000000000000000000000000000..a797ee7792a08bfce225287cd29aae1cc3271194 Binary files /dev/null and "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/com/aldd/service/impl/BookServiceImpl.class" differ diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/jdbc.properties" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/jdbc.properties" new file mode 100644 index 0000000000000000000000000000000000000000..7109942280246ebbf3dd006ae26056df5c553649 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/classes/jdbc.properties" @@ -0,0 +1,4 @@ +jdbc.driver=com.mysql.cj.jdbc.Driver +jdbc.url=jdbc:mysql:///aldd +jdbc.username=root +jdbc.password=123456 \ No newline at end of file diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/test-classes/com/aldd/test/TestBook.class" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/test-classes/com/aldd/test/TestBook.class" new file mode 100644 index 0000000000000000000000000000000000000000..3fd3485419f0d3dc84b22bb641128838b38a5ac3 Binary files /dev/null and "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/spring/target/test-classes/com/aldd/test/TestBook.class" differ diff --git "a/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/\347\272\257\346\263\250\350\247\243\345\274\200\345\217\221\357\274\214spring+Mybatis \346\255\245\351\252\244\345\210\206\350\247\243.md" "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/\347\272\257\346\263\250\350\247\243\345\274\200\345\217\221\357\274\214spring+Mybatis \346\255\245\351\252\244\345\210\206\350\247\243.md" new file mode 100644 index 0000000000000000000000000000000000000000..bc73ef645e48cd89cdc755257af9d06eae863931 --- /dev/null +++ "b/\351\231\210\346\231\223\344\270\234/20241224 \346\263\250\350\247\243\345\274\200\345\217\221spring\345\222\214mybatis\346\225\264\345\220\2102/\347\272\257\346\263\250\350\247\243\345\274\200\345\217\221\357\274\214spring+Mybatis \346\255\245\351\252\244\345\210\206\350\247\243.md" @@ -0,0 +1,425 @@ +# 纯注解开发,spring+Mybatis 步骤分解 + +1. 建库建表 + +2. 建Java项目 + +3. 将项目的所有包,先建好 + + 1. entity 实体类包 + 2. mapper Dao层的代理接口包 + 3. service 业务层包 + 4. controller 表示层包 + 5. config 配置类包 + +4. 在entity包下,创建实体类Video + + 1. 根据表的字段,创建对应的属性 + + 2. set,get,toString,构造器 + + 3. ```java + @Data //提供getter,getter,toString方法 + @AllArgsConstructor //全参 + @NoArgsConstructor //无参构造器 + public class Video { + private int videoId; + private String videoTitle; + + // 做成标准类,javaBean类,1.属性私有,封装。2,提供getter,getter,toString方法 3,全参和无参构造器 + + } + + ``` + +5. 在mapper包里,创建一个VideoMapper接口 + + ```java + package com.demo.mapper; + + import com.demo.entity.Video; + 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 java.util.List; + + public interface VideoMapper { + // Dao层,为的是操作数据库,通过SQL语句,其实就是做CRUD + // CRUD是指在做计算处理时的增加(Create)、读取(Read)、更新(Update)和删除(Delete)几个单词的首字母简写 + // 1.要实现CRUD,这里要写5个方法 + // 2.在每个方法上方,写一个对应SQL语句类型的注解 + + // 1. 查询所有,返回一堆视频数据,所用集合来装List