forked from liyifeng1994/ssm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3f90d7
commit 5501bd5
Showing
12 changed files
with
200 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.soecode.lyf.dao; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.apache.ibatis.annotations.Param; | ||
|
||
import com.soecode.lyf.entity.Book; | ||
|
||
public interface FamilyDao { | ||
|
||
/** | ||
* 通过ID查询单本图书 | ||
* | ||
* @param id | ||
* @return | ||
*/ | ||
Book queryById(long id); | ||
|
||
/** | ||
* 查询所有图书 | ||
* | ||
* @param offset 查询起始位置 | ||
* @param limit 查询条数 | ||
* @return | ||
*/ | ||
List<Book> queryAll(@Param("offset") int offset, @Param("limit") int limit); | ||
|
||
/** | ||
* 减少馆藏数量 | ||
* | ||
* @param bookId | ||
* @return 如果影响行数等于>1,表示更新的记录行数 | ||
*/ | ||
int reduceNumber(long familyId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.soecode.lyf.entity; | ||
|
||
import java.util.Date; | ||
|
||
public class BaseEntity { | ||
private long id; | ||
private Date createDateTime; | ||
private Date updateDateTime; | ||
private String creator; | ||
private String updator; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.soecode.lyf.entity; | ||
|
||
public class Family { | ||
private long id; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.soecode.lyf.enums; | ||
|
||
public enum ResultType { | ||
SUCCESS,ERROR | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/soecode/lyf/listener/CloseDataSourceListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.soecode.lyf.listener; | ||
|
||
|
||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
import java.util.Enumeration; | ||
import java.sql.Driver; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
import com.soecode.lyf.utils.JdbcUtils; | ||
|
||
|
||
/** | ||
* 关闭ComboPooledDataSource连接池监听器 | ||
* @author huangyong | ||
* @date 2018年4月23日 下午8:54:34 | ||
*/ | ||
public class CloseDataSourceListener implements ServletContextListener { | ||
|
||
@Override | ||
public void contextInitialized(ServletContextEvent arg0) { | ||
|
||
} | ||
|
||
@Override | ||
public void contextDestroyed(ServletContextEvent arg0) { | ||
JdbcUtils.closeDataSource(); | ||
//注销驱动 | ||
//得到所有注册了的驱动 | ||
Enumeration<Driver> drivers = DriverManager.getDrivers(); | ||
//遍历注销 | ||
while(drivers.hasMoreElements()){ | ||
try { | ||
DriverManager.deregisterDriver(drivers.nextElement()); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.soecode.lyf.utils; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import com.mchange.v2.c3p0.ComboPooledDataSource; | ||
|
||
|
||
/** | ||
* 用Jdbc操作数据库的工具,本类依赖c3p0-config.xml文件 | ||
* @author huangyong | ||
* @date 2018年4月8日 下午9:58:31 | ||
* | ||
*/ | ||
public class JdbcUtils { | ||
private static final ComboPooledDataSource ds = new ComboPooledDataSource(); | ||
|
||
/** | ||
* 获得数据源 | ||
* @return DataSource 返回类型 | ||
*/ | ||
public static DataSource getDataSource(){ | ||
return ds; | ||
} | ||
|
||
/** | ||
* 关闭数据源 | ||
* @return void 返回类型 | ||
*/ | ||
public static void closeDataSource(){ | ||
ds.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
jdbc.driver=com.mysql.jdbc.Driver | ||
jdbc.url=jdbc:mysql:https://localhost:3307/ssm?useUnicode=true&characterEncoding=utf8 | ||
jdbc.url=jdbc:mysql:https://localhost:3306/chong_ni_test?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC | ||
jdbc.username=root | ||
jdbc.password= | ||
jdbc.password=lyy@1551881752 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE mapper | ||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
"http:https://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
<mapper namespace="com.soecode.lyf.dao.FamilyDao"> | ||
<!-- 目的:为dao接口方法提供sql语句配置 --> | ||
<select id="queryById" resultType="Family" parameterType="long"> | ||
<!-- 具体的sql --> | ||
SELECT | ||
book_id, | ||
name, | ||
number | ||
FROM | ||
book | ||
WHERE | ||
book_id = #{bookId} | ||
</select> | ||
|
||
<select id="queryAll" resultType="Family"> | ||
SELECT | ||
book_id, | ||
name, | ||
number | ||
FROM | ||
book | ||
ORDER BY | ||
book_id | ||
LIMIT #{offset}, #{limit} | ||
</select> | ||
|
||
<update id="reduceNumber"> | ||
UPDATE book | ||
SET number = number - 1 | ||
WHERE | ||
book_id = #{bookId} | ||
AND number > 0 | ||
</update> | ||
</mapper> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters