Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca06b6b

Browse files
committed
更新为mysql数据源。
1 parent f1d4fc8 commit ca06b6b

29 files changed

+904
-266
lines changed

pom.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,16 @@
152152
</dependency>
153153

154154
<!--hsqldb-->
155-
<dependency>
156-
<groupId>org.hsqldb</groupId>
157-
<artifactId>hsqldb</artifactId>
158-
<version>2.2.9</version>
159-
</dependency>
160155
<dependency>
161156
<groupId>mysql</groupId>
162157
<artifactId>mysql-connector-java</artifactId>
163158
<version>${mysql.version}</version>
164159
</dependency>
160+
<dependency>
161+
<groupId>c3p0</groupId>
162+
<artifactId>c3p0</artifactId>
163+
<version>0.9.1.2</version>
164+
</dependency>
165165

166166
<!--Mybatis-->
167167
<dependency>

src/main/java/com/isea533/mybatis/controller/demo/DemoController.java

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
125
package com.isea533.mybatis.controller.demo;
226

327
import com.isea533.mybatis.model.Country;

src/main/java/com/isea533/mybatis/mapper/CountryMapper.java

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
125
package com.isea533.mybatis.mapper;
226

327
import com.github.abel533.mapper.Mapper;

src/main/java/com/isea533/mybatis/mapper/UserInfoMapper.java

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
125
package com.isea533.mybatis.mapper;
226

327
import com.github.abel533.mapper.Mapper;

src/main/java/com/isea533/mybatis/mapper/UserLoginInfoMapper.java

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
125
package com.isea533.mybatis.mapper;
226

327
import com.github.abel533.mapper.Mapper;

src/main/java/com/isea533/mybatis/model/Country.java

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
125
package com.isea533.mybatis.model;
226

3-
import javax.persistence.*;
27+
import javax.persistence.Column;
28+
import javax.persistence.GeneratedValue;
29+
import javax.persistence.GenerationType;
30+
import javax.persistence.Id;
431

532
public class Country {
633
/**

src/main/java/com/isea533/mybatis/model/UserInfo.java

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
125
package com.isea533.mybatis.model;
226

327
import javax.persistence.*;

src/main/java/com/isea533/mybatis/model/UserLoginInfo.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
125
package com.isea533.mybatis.model;
226

3-
import java.util.Date;
427
import javax.persistence.*;
28+
import java.util.Date;
529

630
@Table(name = "`user login info`")
731
public class UserLoginInfo {

src/main/java/com/isea533/mybatis/service/BaseService.java

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
125
package com.isea533.mybatis.service;
226

327
import com.github.abel533.mapper.Mapper;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014 [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
125
package com.isea533.mybatis.service;
226

327
import com.isea533.mybatis.model.Country;
@@ -9,17 +33,17 @@
933
@Service
1034
public class DemoService extends BaseService<Country>{
1135

12-
public int save(Country country2) {
13-
if (country2 == null) {
36+
public int save(Country country) {
37+
if (country == null) {
1438
throw new NullPointerException("保存的对象不能为空!");
1539
}
16-
if (country2.getCountrycode() == null || country2.getCountrycode().equals("")) {
40+
if (country.getCountrycode() == null || country.getCountrycode().equals("")) {
1741
throw new RuntimeException("国家代码不能为空!");
1842
}
19-
if (country2.getCountryname() == null || country2.getCountryname().equals("")) {
43+
if (country.getCountryname() == null || country.getCountryname().equals("")) {
2044
throw new RuntimeException("国家名称不能为空!");
2145
}
22-
return super.save(country2);
46+
return super.save(country);
2347
}
2448

2549
}

src/main/resources/applicationContext.xml

+37-10
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,57 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ The MIT License (MIT)
4+
~
5+
~ Copyright (c) 2014 [email protected]
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
8+
~ of this software and associated documentation files (the "Software"), to deal
9+
~ in the Software without restriction, including without limitation the rights
10+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
~ copies of the Software, and to permit persons to whom the Software is
12+
~ furnished to do so, subject to the following conditions:
13+
~
14+
~ The above copyright notice and this permission notice shall be included in
15+
~ all copies or substantial portions of the Software.
16+
~
17+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
~ THE SOFTWARE.
24+
-->
25+
226
<beans xmlns="http://www.springframework.org/schema/beans"
327
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
528
xmlns:tx="http://www.springframework.org/schema/tx"
629
xmlns:aop="http://www.springframework.org/schema/aop"
730
xmlns:context="http://www.springframework.org/schema/context"
8-
xmlns:util="http://www.springframework.org/schema/util"
931
xsi:schemaLocation="http://www.springframework.org/schema/beans
1032
http://www.springframework.org/schema/beans/spring-beans.xsd
11-
http://www.springframework.org/schema/jdbc
12-
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
1333
http://www.springframework.org/schema/tx
1434
http://www.springframework.org/schema/tx/spring-tx.xsd
1535
http://www.springframework.org/schema/aop
1636
http://www.springframework.org/schema/aop/spring-aop.xsd
1737
http://www.springframework.org/schema/context
18-
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
38+
http://www.springframework.org/schema/context/spring-context.xsd">
1939

2040
<context:component-scan base-package="com.isea533.mybatis.service"/>
2141

2242
<context:property-placeholder location="classpath:config.properties"/>
2343

24-
<!--hsqldb测试数据库-->
25-
<jdbc:embedded-database id="dataSource">
26-
<jdbc:script location="classpath:hsqldb.sql"/>
27-
</jdbc:embedded-database>
44+
<!-- c3p0 -->
45+
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
46+
<property name="driverClass" value="${jdbc.driverClass}"/>
47+
<property name="jdbcUrl" value="${jdbc.url}"/>
48+
<property name="user" value="${jdbc.user}"/>
49+
<property name="password" value="${jdbc.password}"/>
50+
<property name="maxPoolSize" value="${jdbc.maxPoolSize}"/>
51+
<property name="minPoolSize" value="${jdbc.minPoolSize}"/>
52+
<property name="maxStatements" value="${jdbc.maxStatements}"/>
53+
<property name="testConnectionOnCheckout" value="${jdbc.testConnection}"/>
54+
</bean>
2855

2956
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
3057
<property name="dataSource" ref="dataSource"/>
@@ -76,7 +103,7 @@
76103
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
77104
<property name="dataSource" ref="dataSource"/>
78105
</bean>
79-
106+
80107
<bean class="com.github.abel533.mapperhelper.MapperHelper"
81108
depends-on="sqlSession" init-method="initMapper" scope="singleton" lazy-init="false">
82109
<property name="mappers">

0 commit comments

Comments
 (0)