初步提交
This commit is contained in:
commit
dd6fd583ff
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
13
.idea/compiler.xml
generated
Normal file
13
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="springLearn202503" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/springLearn202503/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/springLearn202503/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/springLearn202503/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/spring20250421.iml" filepath="$PROJECT_DIR$/.idea/spring20250421.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
9
.idea/spring20250421.iml
generated
Normal file
9
.idea/spring20250421.iml
generated
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
45
springLearn202503/pom.xml
Normal file
45
springLearn202503/pom.xml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.sec</groupId>
|
||||||
|
<artifactId>springLearn202503</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<version>5.3.21</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.2</version>
|
||||||
|
<!-- <scope>test</scope>-->
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.23</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid</artifactId>
|
||||||
|
<version>1.1.22</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mchange</groupId>
|
||||||
|
<artifactId>c3p0</artifactId>
|
||||||
|
<version>0.9.5.4</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
65
springLearn202503/src/main/java/com/sec/Main.java
Normal file
65
springLearn202503/src/main/java/com/sec/Main.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package com.sec;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||||
|
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||||
|
import com.sec.dao.UserDao;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
|
import java.beans.PropertyVetoException;
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||||
|
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// ApplicationContext application=new ClassPathXmlApplicationContext("application.xml");
|
||||||
|
ClassPathXmlApplicationContext application=new ClassPathXmlApplicationContext("application.xml");
|
||||||
|
UserDao userDao1 = (UserDao)application.getBean("UserDao");
|
||||||
|
// UserDao userDao2 = (UserDao)application.getBean("UserDao");
|
||||||
|
System.out.println(userDao1);
|
||||||
|
application.close();
|
||||||
|
// System.out.println(userDao2);
|
||||||
|
|
||||||
|
// userDao.getData();
|
||||||
|
DruidDataSource druidDataSource=new DruidDataSource();
|
||||||
|
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
|
druidDataSource.setUrl("jdbc:mysql://47.103.155.22:3306/learn_spring");
|
||||||
|
druidDataSource.setUsername("root");
|
||||||
|
druidDataSource.setPassword("mysql_wafeYX");
|
||||||
|
|
||||||
|
try {
|
||||||
|
DruidPooledConnection connection = druidDataSource.getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(" select * from user_info ");
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
System.out.println(resultSet.getString("user_name")+" "+resultSet.getString("account_name"));
|
||||||
|
// System.out.println(resultSet.getString("account_name"));
|
||||||
|
}
|
||||||
|
resultSet.close();
|
||||||
|
preparedStatement.close();
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
ComboPooledDataSource comboPooledDataSource=new ComboPooledDataSource();
|
||||||
|
try {
|
||||||
|
comboPooledDataSource.setDriverClass("com.mysql.jdbc.Driver");
|
||||||
|
comboPooledDataSource.setJdbcUrl("jdbc:mysql://47.103.155.22:3306/learn_spring");
|
||||||
|
comboPooledDataSource.setUser("root");
|
||||||
|
comboPooledDataSource.setPassword("mysql_wafeYX");
|
||||||
|
|
||||||
|
Connection connection = comboPooledDataSource.getConnection();
|
||||||
|
Statement statement = connection.createStatement();
|
||||||
|
ResultSet resultSet = statement.executeQuery("select * from user_info ");
|
||||||
|
while (resultSet.next()) {
|
||||||
|
System.out.println(resultSet.getString("user_name"));
|
||||||
|
}
|
||||||
|
statement.close();
|
||||||
|
connection.close();
|
||||||
|
} catch (PropertyVetoException | SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
5
springLearn202503/src/main/java/com/sec/dao/UserDao.java
Normal file
5
springLearn202503/src/main/java/com/sec/dao/UserDao.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package com.sec.dao;
|
||||||
|
|
||||||
|
public interface UserDao {
|
||||||
|
public void getData();
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.sec.dao.impl;
|
||||||
|
|
||||||
|
import com.sec.dao.UserDao;
|
||||||
|
|
||||||
|
public class UserDaoImpl implements UserDao {
|
||||||
|
|
||||||
|
public UserDaoImpl(){
|
||||||
|
System.out.println("无参构造");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(){
|
||||||
|
System.out.println("初始化方法");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroy(){
|
||||||
|
System.out.println("销毁方法");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getData() {
|
||||||
|
System.out.println("hello user!!!");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.sec.factroy;
|
||||||
|
|
||||||
|
import com.sec.dao.UserDao;
|
||||||
|
import com.sec.dao.impl.UserDaoImpl;
|
||||||
|
|
||||||
|
public class DemoFactroy
|
||||||
|
{
|
||||||
|
public UserDao getDao(){
|
||||||
|
return new UserDaoImpl();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.sec.factroy;
|
||||||
|
|
||||||
|
import com.sec.dao.UserDao;
|
||||||
|
import com.sec.dao.impl.UserDaoImpl;
|
||||||
|
|
||||||
|
public class StaticFactroy {
|
||||||
|
public static UserDao getUserDao() {
|
||||||
|
return new UserDaoImpl();
|
||||||
|
}
|
||||||
|
}
|
9
springLearn202503/src/main/resources/application.xml
Normal file
9
springLearn202503/src/main/resources/application.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
<!-- <bean id="UserDao" class="com.impl.dao.com.sec.UserDaoImpl" scope="singleton" init-method="init" destroy-method="destroy"></bean>-->
|
||||||
|
<!-- <bean id="UserDao" class="com.factroy.com.sec.StaticFactroy" factory-method="getUserDao"></bean>-->
|
||||||
|
<bean id="DemoFactroy" class="com.sec.factroy.DemoFactroy"></bean>
|
||||||
|
<bean id="UserDao" factory-bean="DemoFactroy" factory-method="getDao"></bean>
|
||||||
|
</beans>
|
9
springLearn202503/target/classes/application.xml
Normal file
9
springLearn202503/target/classes/application.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
<!-- <bean id="UserDao" class="com.impl.dao.com.sec.UserDaoImpl" scope="singleton" init-method="init" destroy-method="destroy"></bean>-->
|
||||||
|
<!-- <bean id="UserDao" class="com.factroy.com.sec.StaticFactroy" factory-method="getUserDao"></bean>-->
|
||||||
|
<bean id="DemoFactroy" class="com.sec.factroy.DemoFactroy"></bean>
|
||||||
|
<bean id="UserDao" factory-bean="DemoFactroy" factory-method="getDao"></bean>
|
||||||
|
</beans>
|
BIN
springLearn202503/target/classes/com/sec/Main.class
Normal file
BIN
springLearn202503/target/classes/com/sec/Main.class
Normal file
Binary file not shown.
BIN
springLearn202503/target/classes/com/sec/dao/UserDao.class
Normal file
BIN
springLearn202503/target/classes/com/sec/dao/UserDao.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user