发表于: 2019-11-09 19:42:21
1 1135
Task1Day7
今天学了一个最简单的spring,帮助我进一步理解了spring框架的意义
HelloWorld.java:
package com.tutorialspoint;
public class HelloWorld {
private String message;
public void setMessage(String message){
this.message = message;
}
public void getMessage() {
System.out.println("Your Message : " + message);
}
}
MainApp.java:
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
//id of bean
obj.getMessage();
}
}
Beans.xml:
<?xml version="1.0" encoding="utf-8" ?>
<bean id="helloWorld" class="com.tutorialspoint.HelloWorld">
<property name="message" value="Hello !"/>
</bean>
</beans>
jdbctemplate提供的主要查询方法有:
The Spring JDBC template offers several ways to query the database. queryForList() returns a list of HashMaps. The name of the column is the key in the hashmap for the values in the table. More convenient is the usage of ResultSetExtractor or RowMapper which allows to translates the SQL result direct into an object (ResultSetExtractor) or a list of objects (RowMapper). Both these methods will be demonstrated in the coding.
配置jdbctemplate的两种方法:
How to configure JdbcTemplate
1. As a bean in the spring configuration XML
2. Programmatic Configuration
明天写完jdbctemplate部分的代码,今天搞懂之后已经很晚了,太困了TAT
评论