Skip to content

Commit a3efe41

Browse files
committed
Complete ssm Integration Project Architecture in ssmbuild
1 parent 65e0f8b commit a3efe41

8 files changed

Lines changed: 199 additions & 8 deletions

File tree

‎ssmbuild/src/main/java/top/clearlight/dao/BookMapper.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
where bookName = #{bookName};
2929
</select>
3030

31-
<select id="queryAllBook" resultType="top.clearlight.pojo.Books" parameterType="List">
31+
<select id="queryAllBook" resultType="top.clearlight.pojo.Books">
3232
select *
3333
from ssmbuild.books
3434
</select>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package top.clearlight.service;
2+
3+
import top.clearlight.pojo.Books;
4+
5+
import java.util.List;
6+
7+
/**
8+
* @author <a href="mail to: lxy12531@163.com" rel="nofollow">lxy</a>
9+
* @date 2020/4/5 16:32
10+
*/
11+
public interface BookService {
12+
// 增加一本书
13+
int addBook(Books books);
14+
15+
// 删除一本书
16+
int deleteBookById(int id);
17+
18+
// 更新一本书
19+
int updateBook(Books books);
20+
21+
// 查询一本书
22+
Books queryBookByName(String bookName);
23+
24+
// 查询全部的书
25+
List<Books> queryAllBook();
26+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package top.clearlight.service;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.stereotype.Service;
5+
import top.clearlight.dao.BookMapper;
6+
import top.clearlight.pojo.Books;
7+
8+
import java.util.List;
9+
10+
/**
11+
* @author <a href="mail to: lxy12531@163.com" rel="nofollow">lxy</a>
12+
* @date 2020/4/5 16:40
13+
*/
14+
public class BookServiceImpl implements BookService {
15+
16+
// service调用dao: 组合dao
17+
@Autowired
18+
private BookMapper bookMapper;
19+
20+
public void setBookMapper(BookMapper bookMapper) {
21+
this.bookMapper = bookMapper;
22+
}
23+
24+
public int addBook(Books books) {
25+
return bookMapper.addBook(books);
26+
}
27+
28+
public int deleteBookById(int id) {
29+
return bookMapper.deleteBookById(id);
30+
}
31+
32+
public int updateBook(Books books) {
33+
return bookMapper.updateBook(books);
34+
}
35+
36+
public Books queryBookByName(String bookName) {
37+
return bookMapper.queryBookByName(bookName);
38+
}
39+
40+
public List<Books> queryAllBook() {
41+
return bookMapper.queryAllBook() ;
42+
}
43+
}

‎ssmbuild/src/main/resources/applicationContext.xml‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://www.springframework.org/schema/beans
55
http://www.springframework.org/schema/beans/spring-beans.xsd">
6-
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
7-
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
8-
<property name="jdbcUrl" value="jdbc:mysql:///ee111"/>
9-
<property name="user" value="root"/>
10-
<property name="password" value="root"/>
11-
</bean>
126

13-
7+
<import resource="classpath:spring-dao.xml"/>
8+
<import resource="classpath:spring-service.xml"/>
9+
<import resource="classpath:spring-mvc.xml"/>
1410
</beans>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:context="http://www.springframework.org/schema/context"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans
6+
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
7+
8+
<!--1. 关联数据库配置文件-->
9+
<context:property-placeholder location="classpath:database.properties"/>
10+
11+
<!--2. 连接池-->
12+
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
13+
<property name="driverClass" value="${jdbc.driver}"/>
14+
<property name="jdbcUrl" value="${jdbc.url}"/>
15+
<property name="user" value="${jdbc.username"/>
16+
<property name="password" value="${jdbc.password}"/>
17+
18+
<!-- 如果池中数据连接不够时一次增长多少个 -->
19+
<property name="acquireIncrement" value="5"/>
20+
<!-- 初始化数据库连接池时连接的数量 -->
21+
<property name="initialPoolSize" value="20"/>
22+
<!-- 数据库连接池中的最大的数据库连接数 -->
23+
<property name="maxPoolSize" value="30"/>
24+
<!-- 数据库连接池中的最小的数据库连接数 -->
25+
<property name="minPoolSize" value="10"/>
26+
</bean>
27+
28+
<!--3. sqlSessionFactory-->
29+
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
30+
<property name="dataSource" ref="dataSource"/>
31+
32+
<!--绑定MyBatis的配置文件-->
33+
<property name="configLocation" value="classpath:mybatis-config.xml"/>
34+
</bean>
35+
36+
<!--配置dao接口扫描包, 动态的实现了Dao接口可以注入到Spring容器中!-->
37+
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
38+
<!--注入sqlSessionFactory-->
39+
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
40+
<!--要扫描的dao包-->
41+
<property name="basePackage" value="top.clearlight.dao"/>
42+
</bean>
43+
44+
</beans>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:mvc="http://www.springframework.org/schema/mvc"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans
7+
http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/mvc
9+
https://www.springframework.org/schema/mvc/spring-mvc.xsd
10+
http://www.springframework.org/schema/context
11+
https://www.springframework.org/schema/context/spring-context.xsd">
12+
13+
<!--1. 注解驱动-->
14+
<mvc:annotation-driven/>
15+
<!--2. 静态资源过滤-->
16+
<mvc:default-servlet-handler/>
17+
<!--3. 扫描包:controller-->
18+
<context:component-scan base-package="top.clearlight.controller"/>
19+
20+
<!--4. 视图解析器-->
21+
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
22+
<property name="prefix" value="/WEB-INF/jsp/"/>
23+
<property name="suffix" value=".jsp"/>
24+
</bean>
25+
26+
</beans>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:context="http://www.springframework.org/schema/context"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans
6+
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
7+
8+
<!--1. 扫描service下的包-->
9+
<context:component-scan base-package="top.clearlight.service"/>
10+
11+
<!--2. 将我们的所有业务类, 注入到spring, 可以通过配置或者注解实现-->
12+
<bean id="BookServiceImpl" class="top.clearlight.service.BookServiceImpl">
13+
<property name="bookMapper" ref="bookMapper"/>
14+
</bean>
15+
16+
<!--3. 声明式事务配置-->
17+
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
18+
<!--注入数据源-->
19+
<property name="dataSource" ref="dataSource"/>
20+
</bean>
21+
22+
</beans>

‎ssmbuild/web/WEB-INF/web.xml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
5+
version="4.0">
6+
<!--DispatchServlet-->
7+
<servlet>
8+
<servlet-name>springmvc</servlet-name>
9+
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
10+
<init-param>
11+
<param-name>contextConfigLocation</param-name>
12+
<param-value>classpath:spring-mvc.xml</param-value>
13+
</init-param>
14+
</servlet>
15+
<servlet-mapping>
16+
<servlet-name>springmvc</servlet-name>
17+
<url-pattern>/</url-pattern>
18+
</servlet-mapping>
19+
20+
<!--乱码过滤-->
21+
<filter>
22+
<filter-name>encodingFilter</filter-name>
23+
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
24+
</filter>
25+
<filter-mapping>
26+
<filter-name>encodingFilter</filter-name>
27+
<url-pattern>/*</url-pattern>
28+
</filter-mapping>
29+
30+
<!--Session-->
31+
<session-config>
32+
<session-timeout>15</session-timeout>
33+
</session-config>
34+
</web-app>

0 commit comments

Comments
 (0)