提交 0598f71d authored 作者: 杨雪's avatar 杨雪

修改修改后的版本â

上级 3d0a6192
- 项目简介
本项目实现了一个简单的图书借阅系统。
- 环境依赖
IDE:IntelliJ IDEA2019.1.3
JDK:1.8
MySql:8.0
- 目录结构描述
entity:模型层,存放实体类
dao:持久化层
service:业务逻辑层
controller:控制层,处理用户输入请求
...@@ -40,6 +40,13 @@ ...@@ -40,6 +40,13 @@
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
......
package com.example.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
* 格式化时间转换器
*/
@Configuration
public class DateConvert {
@Bean
public Converter<String, Date> DateConvert() {
return new Converter<String, Date>() {
@Override
public Date convert(String source) {
if (StringUtils.isEmpty(source)) {
return null;
} else {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date = null;
try {
date = df.parse(source);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
}
};
}
@Bean
public Converter<String, LocalDate> LocalDateConvert() {
return new Converter<String, LocalDate>() {
@Override
public LocalDate convert(String source) {
if (StringUtils.isEmpty(source)) {
return null;
} else {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = null;
try {
date = LocalDate.parse(source, df);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
}
};
}
@Bean
public Converter<String, LocalDateTime> LocalDateTimeConvert() {
return new Converter<String, LocalDateTime>() {
@Override
public LocalDateTime convert(String source) {
if (StringUtils.isEmpty(source)) {
return null;
} else {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime date = null;
try {
date = LocalDateTime.parse(source, df);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
}
};
}
}
//package com.example.config;
//
//import com.mysql.cj.jdbc.AbandonedConnectionCleanupThread;
//import com.zaxxer.hikari.HikariConfig;
//import com.zaxxer.hikari.HikariDataSource;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.core.io.support.ResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.annotation.PreDestroy;
//import javax.sql.DataSource;
//import java.io.IOException;
//
///**
// * 数据持久层配置
// *
// * @author smartye
// */
//@Configuration
//@MapperScan(basePackages = "com.example.dao")
//@EnableTransactionManagement
//public class MybatisConfig {
//
// Log log = LogFactory.getLog(getClass());
//
// HikariDataSource ds;
//
// @Bean
// public DataSource dataSource(@Value("com.mysql.cj.jdbc.Driver") String driverClassName,
// @Value("jdbc:mysql://localhost:3306/book?useSSL=false&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=Asia/Shanghai") String jdbcUrl,
// @Value("root") String username,
// @Value("root") String password
// ) {
// HikariConfig config = new HikariConfig();
// config.setDriverClassName(driverClassName);
// config.setJdbcUrl(jdbcUrl);
// config.setUsername(username);
// config.setPassword(password);
// config.addDataSourceProperty("cachePrepStmts", true);
// config.addDataSourceProperty("useServerPrepStmts", true);
// config.addDataSourceProperty("maintainTimeStats", false);
// config.setIdleTimeout(60000);
// config.setConnectionTimeout(60000);
// config.setValidationTimeout(3000);
// config.setMaximumPoolSize(20);
// config.setMaxLifetime(60000);
// config.setMinimumIdle(10);
// config.setConnectionTestQuery("select 1");
// ds = new HikariDataSource(config);
// return ds;
// }
//
// @Bean
// public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) throws IOException {
// SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
// bean.setDataSource(dataSource);
// ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// bean.setMapperLocations(resolver.getResources("classpath*:mapper/*.xml"));
// return bean;
// }
//
// /**
// * 开启Spring的事务处理
// */
// @Bean
// public DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource) {
// DataSourceTransactionManager manager = new DataSourceTransactionManager();
// manager.setDataSource(dataSource);
// return manager;
// }
//
// @PreDestroy
// public void destroy() {
// ds.close();
// log.debug("关闭数据库连接池");
// AbandonedConnectionCleanupThread.checkedShutdown();
// }
//}
\ No newline at end of file
...@@ -3,60 +3,48 @@ package com.example.controller; ...@@ -3,60 +3,48 @@ package com.example.controller;
import com.example.entity.Book; import com.example.entity.Book;
import com.example.service.BookService; import com.example.service.BookService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping(value = "/book")
public class BookController { public class BookController {
@Autowired @Autowired
private BookService bookService; private BookService bookService;
@RequestMapping(value = "/insert") @RequestMapping(value = "/insert")
public String book(){ public List<Book> book( Book book){
Book book = new Book(); bookService.insert(book);
book.setName("西游记"); return bookService.selectAll();
book.setAuthor("吴承恩");
book.setPrice(52.3);
book.setNum(10);
int i = bookService.insert(book);
return "成功加入"+i+"条记录";
} }
@RequestMapping(value = "/selectAll") @RequestMapping(value = "/selectAll")
public String findAll(){ public List<Book> findAll(){
List<Book> bookList = bookService.selectAll(); List<Book> bookList = bookService.selectAll();
bookList.stream().forEach(System.out::println); return bookList;
return bookList.toString();
} }
@RequestMapping(value = "/selectById") @RequestMapping(value = "/selectById")
public Book selectById(){ public Book selectById(int id){
Book book = bookService.selectById(1); Assert.notNull(id,"id不能为空");
Book book = bookService.selectById(id);
return book; return book;
} }
@RequestMapping(value = "/update") @RequestMapping(value = "/update")
public String update(){ public List<Book> update( Book book){
Book book = new Book(); bookService.update(book.getId(),book);
book.setName("红楼梦"); return bookService.selectAll();
book.setAuthor("曹雪芹");
book.setPrice(52.2);
book.setNum(13);
int i = bookService.update(2,book);
return "成功更新"+i+"条记录";
} }
@RequestMapping(value = "/delete") @RequestMapping(value = "/delete")
public String delete(){ public List<Book> delete(int id){
int i = bookService.delete(3); bookService.delete(id);
return "成功删除"+i+"条记录"; return bookService.selectAll();
} }
} }
package com.example.controller;
import com.example.entity.Book;
import com.example.entity.Record;
import com.example.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping(value = "/record")
public class RecordController {
@Autowired
private RecordService recordService;
@RequestMapping(value = "/insert")
public List<Record> insert(Record record){
recordService.insert(record);
return recordService.selectAll();
}
@RequestMapping("/returnBook")
public Record returnBook(int recordId){
return recordService.returnBook(recordId);
}
@RequestMapping("/selectById")
public Record selectById(int recordId){
return recordService.selectById(recordId);
}
@RequestMapping("/selectAll")
public List<Record> selectAll(){
return recordService.selectAll();
}
}
package com.example.controller;
import com.example.entity.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping(value = "/user")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(value = "/selectById")
public User select(int userId){
return userService.selectById(userId);
}
@RequestMapping(value = "/selectAll")
public List<User> selectAll(){
return userService.selectAll();
}
@RequestMapping(value = "/insert")
public List<User> insert(User user){
userService.insert(user);
return userService.selectAll();
}
@RequestMapping(value = "/delete")
public List<User> delete(int userID){
userService.delete(userID);
return userService.selectAll();
}
@RequestMapping(value = "/update")
public List<User> update(User user){
userService.update(user.getUserId(),user);
return userService.selectAll();
}
}
...@@ -2,28 +2,50 @@ package com.example.dao; ...@@ -2,28 +2,50 @@ package com.example.dao;
import com.example.entity.Book; import com.example.entity.Book;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
/**
* 描述:书籍相关操作服务层
*
* @author Yangxue
* @version V1.0
* @class DaoMapper
* @packageName com.example.dao
* @description 提供书籍的增删改查接口
* @data 2020/4/13
**/
@Repository
@Mapper @Mapper
public interface DaoMapper { public interface DaoMapper {
// 新增一个book /**
*
* @param book
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:37
*/
@Insert("insert into book(name,author,price,num)values(#{name},#{author},#{price},#{num})") @Insert("insert into book(name,author,price,num)values(#{name},#{author},#{price},#{num})")
int insert(Book book); int insert(Book book);
// 删除一个book
@Delete("delete from book where id = #{id}") @Delete("delete from book where id = #{id}")
int delete(Integer id); int delete(Integer id);
// 更改一个book
@Update("update book set name=#{book.name},author=#{book.author},price=#{book.price},num=#{book.num} where id =#{id}") @Update("update book set name=#{book.name},author=#{book.author},price=#{book.price},num=#{book.num} where id =#{id}")
int update(Integer id,Book book); int update(Integer id,Book book);
// 查询一个book
@Select("select id,name,author,price,num from book where id=#{id}") @Select("select id,name,author,price,num from book where id=#{id}")
Book selectById(Integer id); Book selectById(Integer id);
// 查询全部book
@Select("select id,name,author,price,num from book") @Select("select id,name,author,price,num from book")
List<Book> selectAll(); List<Book> selectAll();
......
package com.example.dao;
import com.example.entity.Record;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* 描述:书籍相关操作服务层
*
* @author Yangxue
* @version V1.0
* @class DaoMapper
* @packageName com.example.dao
* @description 提供记录的增删改查接口
* @data 2020/4/13
*
**/
@Repository
@Mapper
public interface RecordMapper {
@Insert("insert into record(bookId,userId)values(#{bookId},#{userId})")
int insert(Record record);
@Delete("delete from record where recordId=#{recordId}")
int delete(int recordId);
@Update("update record set returnDate=#{record.returnDate},hasReturn=#{record.hasReturn} where recordId =#{recordId}")
int update(int recordId,Record record);
@Select("select * from record where recordId =#{recordId} ")
Record selectById(int recordId);
@Select("select * from record")
List<Record> selectAll();
}
package com.example.dao;
import com.example.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 描述:书籍相关操作服务层
* @author Yangxue
* @version V1.0
* @class DaoMapper
* @packageName com.example.dao
* @description 提供用户的增删改查接口
* @data 2020/4/13
**/
@Repository
@Mapper
public interface UserMapper {
@Insert("insert into user(name,age)values(#{name},#{age})")
int insert(User user);
@Update("update user set name=#{user.name},age=#{user.age} where userId =#{userId}")
int update(int userId,User user);
@Delete("delete from user where userId =#{userId}")
int delete(int userId);
@Select("select * from user where userId =#{userId} ")
User selectById(int userId);
@Select("select userId,name, age from user")
List<User> selectAll();
}
...@@ -3,23 +3,31 @@ package com.example.entity; ...@@ -3,23 +3,31 @@ package com.example.entity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
//import javax.persistence.*; * @author: yangxue
* @createDate: 2020/4/13
* @description: this is the Book class.
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class Book { public class Book {
/**
*书籍编号
*/
private int id; private int id;
// @Column(name = "bookName") /*
* 书籍名称
* */
private String name; private String name;
// @Column(name = "author")
private String author; private String author;
// @Column(name = "price") // 书籍的价格
private Double price; private Double price;
// @Column(name = "num") // 书籍的数量
private long num; private long num;
......
package com.example.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* @author: yangxue
* @createDate: 2020/4/13
* @description: this is the Record class.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Record {
/*
* 记录编号
* */
private Integer recordId;
/*
* 书籍编号
* */
private Integer bookId;
/*
* 用户编号
* */
private Integer userId;
/*
* 借书日期
* */
private Date lendDate;
/*
* 还书日期
* */
private Date returnDate;
/*
* 是否归还
* */
private boolean hasReturn;
}
package com.example.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author: yangxue
* @createDate: 2020/4/13
* @description: this is the User class.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
/*
* 用户编号
* */
private int userId;
/*
* 用户姓名
* */
private String name;
/*
* 用户年龄
* */
private int age;
}
...@@ -5,21 +5,18 @@ import org.apache.ibatis.annotations.Delete; ...@@ -5,21 +5,18 @@ import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import java.util.List; import java.util.List;
public interface BookService { public interface BookService {
int insert(Book book); int insert(Book book);
// 删除一个book
int delete(Integer id); int delete(Integer id);
// 更改一个book int update(Integer id,Book book);
int update(Integer id,Book book);
// 查询一个book
Book selectById(Integer id); Book selectById(Integer id);
// 查询全部book
List<Book> selectAll(); List<Book> selectAll();
} }
...@@ -12,26 +12,64 @@ public class BookServiceImpl implements BookService { ...@@ -12,26 +12,64 @@ public class BookServiceImpl implements BookService {
@Autowired @Autowired
private DaoMapper daoMapper; private DaoMapper daoMapper;
/**
*
* @param book
* @Return : 成功添加的记录数
* @Author : YangXue
* @Date : 2020/4/14 10:41
* @describe:添加
*/
@Override @Override
public int insert(Book book) { public int insert(Book book) {
return daoMapper.insert(book); return daoMapper.insert(book);
} }
/**
*
* @param id
* @Return : 成功删除的记录数
* @Author : YangXue
* @Date : 2020/4/14 10:41
* @describe: 删除书籍
*/
@Override @Override
public int delete(Integer id) { public int delete(Integer id) {
return daoMapper.delete(id); return daoMapper.delete(id);
} }
/**
*
* @param id,book
* @Return : 成功更新的记录数
* @Author : YangXue
* @Date : 2020/4/14 10:43
* @describe: 更新书籍
*/
@Override @Override
public int update(Integer id, Book book) { public int update(Integer id, Book book) {
return daoMapper.update(id,book); return daoMapper.update(id,book);
} }
/**
* @param id
* @Return : com.example.entity.Book
* @Author : YangXue
* @Date : 2020/4/14 10:45
* @describe: 根据书籍编号查找书籍
*/
@Override @Override
public Book selectById(Integer id) { public Book selectById(Integer id) {
return daoMapper.selectById(id); return daoMapper.selectById(id);
} }
/**
* @Return : java.util.List<com.example.entity.Book>
* @Author : YangXue
* @Date : 2020/4/14 10:47
* * * @describe: 查找全部书籍
*/
@Override @Override
public List<Book> selectAll() { public List<Book> selectAll() {
return daoMapper.selectAll(); return daoMapper.selectAll();
......
package com.example.service;
import com.example.entity.Book;
import com.example.entity.Record;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
public interface RecordService {
int insert(Record record);
int delete(int recordId);
int update(int recordId,Record record);
Record selectById(int recordId);
List<Record> selectAll();
Record returnBook(int RecordId);
}
package com.example.service;
import com.example.dao.RecordMapper;
import com.example.entity.Book;
import com.example.entity.Record;
import com.example.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.Date;
import java.util.List;
@Service
public class RecordServiceImpl implements RecordService {
@Autowired
private RecordMapper recordMapper;
@Autowired
private BookService bookService;
@Autowired
private UserService userService;
/**
*
* @param record
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:49
* @describe: 借书时生成新订单
*/
@Override
public int insert(Record record) {
Assert.notNull(record.getUserId(),"用户ID不能为空");
Assert.notNull(record.getBookId(),"书籍ID不能为空");
User user = userService.selectById(record.getUserId());
Book book = bookService.selectById(record.getBookId());
Assert.notNull(user,"用户不存在");
Assert.notNull(book,"书籍不存在");
if (book.getNum()<=0){
throw new IllegalArgumentException("库存不足");
}
book.setNum(book.getNum()-1);
bookService.update(book.getId(),book);
return recordMapper.insert(record);
}
/**
*
* @param recordId
* @Return : com.example.entity.Record
* @Author : YangXue
* @Date : 2020/4/14 10:49
* @describe: 根据订单号还书
*/
@Override
public Record returnBook(int recordId) {
Record record = recordMapper.selectById(recordId);
if (record.isHasReturn()== false){
record.setReturnDate(new Date());
record.setHasReturn(true);
Book book = bookService.selectById(record.getBookId());
book.setNum(book.getNum()+1);
bookService.update(book.getId(),book);
recordMapper.update(recordId,record);
}
return recordMapper.selectById(record.getRecordId());
}
/**
*
* @param recordId
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:50
* @describe: 根据记录编号查找借书记录
*/
@Override
public int delete(int recordId) {
return 0;
}
/**
* @param recordId
* @param record
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:51
* @describe: 更新记录的信息
*/
@Override
public int update(int recordId,Record record) {
return recordMapper.update(recordId,record);
}
/**
*
* @param recordId
* @Return : com.example.entity.Record
* @Author : YangXue
* @Date : 2020/4/14 10:52
* @describe: 根据编号查找记录
*/
@Override
public Record selectById(int recordId) {
return recordMapper.selectById(recordId);
}
/**
*
* @Return : java.util.List<com.example.entity.Record>
* @Author : YangXue
* @Date : 2020/4/14 10:53
* * @describe: 根据全部记录
*/
@Override
public List<Record> selectAll() {
return recordMapper.selectAll();
}
}
package com.example.service;
import com.example.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public interface UserService {
int insert(User user);
int update(int userId,User user);
int delete(int userId);
User selectById(int userId);
List<User> selectAll();
}
package com.example.service;
import com.example.dao.UserMapper;
import com.example.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
/**
*
* @param user
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:55
* @describe: 添加用户
*/
@Override
public int insert(User user) {
return userMapper.insert(user);
}
/**
* @param userId
* @param user
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:56
* @describe: 更新用户信息
*/
@Override
public int update(int userId,User user) {
return userMapper.update(userId,user);
}
/**
*
* @param userId
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:56
* @describe: 根据用户编号删除用户信息
*/
@Override
public int delete(int userId) {
return userMapper.delete(userId);
}
/**
*
* @param userId
* @Return : com.example.entity.User
* @Author : YangXue
* @Date : 2020/4/14 10:57
* @describe: 根据用户编号查找用户
*/
@Override
public User selectById(int userId) {
User user = userMapper.selectById(userId);
return user;
}
/**
*
* @Return : java.util.List<com.example.entity.User>
* @Author : YangXue
* @Date : 2020/4/14 10:57
* @describe: 查找全部用户信息
*/
@Override
public List<User> selectAll() {
return userMapper.selectAll();
}
}
...@@ -6,7 +6,10 @@ spring: ...@@ -6,7 +6,10 @@ spring:
username: root username: root
password: root password: root
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
jackson:
date-format: yyyy年MM月dd日HH点mm分ss
time-zone: GMT+8
# mybatis # mybatis����
mybatis: mybatis:
type-aliases-package: com.fdd.mybatis.dao type-aliases-package: com.fdd.mybatis.dao
<?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.example.dao.BookDAO">
<resultMap id="BaseResultMap" type="com.example.entity.Book1">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="author" jdbcType="VARCHAR" property="author" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="num" jdbcType="BIGINT" property="num" />
<result column="price" jdbcType="DOUBLE" property="price" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, author, `name`, num, price
</sql>
<select id="selectByExample" parameterType="com.example.entity.Book1Example" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from book
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limit != null">
<if test="offset != null">
limit ${offset}, ${limit}
</if>
<if test="offset == null">
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from book
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from book
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.example.entity.Book1Example">
delete from book
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.example.entity.Book1">
insert into book (id, author, `name`,
num, price)
values (#{id,jdbcType=INTEGER}, #{author,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{num,jdbcType=BIGINT}, #{price,jdbcType=DOUBLE})
</insert>
<insert id="insertSelective" parameterType="com.example.entity.Book1">
insert into book
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="author != null">
author,
</if>
<if test="name != null">
`name`,
</if>
<if test="num != null">
num,
</if>
<if test="price != null">
price,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="author != null">
#{author,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="num != null">
#{num,jdbcType=BIGINT},
</if>
<if test="price != null">
#{price,jdbcType=DOUBLE},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.example.entity.Book1Example" resultType="java.lang.Long">
select count(*) from book
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update book
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.author != null">
author = #{record.author,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.num != null">
num = #{record.num,jdbcType=BIGINT},
</if>
<if test="record.price != null">
price = #{record.price,jdbcType=DOUBLE},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update book
set id = #{record.id,jdbcType=INTEGER},
author = #{record.author,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
num = #{record.num,jdbcType=BIGINT},
price = #{record.price,jdbcType=DOUBLE}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.example.entity.Book1">
update book
<set>
<if test="author != null">
author = #{author,jdbcType=VARCHAR},
</if>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="num != null">
num = #{num,jdbcType=BIGINT},
</if>
<if test="price != null">
price = #{price,jdbcType=DOUBLE},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.example.entity.Book1">
update book
set author = #{author,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
num = #{num,jdbcType=BIGINT},
price = #{price,jdbcType=DOUBLE}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论