博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring 第一篇(1-1):让java开发变得更简单(下)转
阅读量:7221 次
发布时间:2019-06-29

本文共 2132 字,大约阅读时间需要 7 分钟。

这个波主虽然只发了几篇,但是写的很好

上面一篇文章写的很好,其中提及到了,templet方式我之前已经有点了解了,但是Spring的还不知道,这次真的又学到了Spring的

 配置文件

 

[java]
  1. package xm.zjl.dao;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import org.springframework.beans.factory.annotation.Autowired;  
  7. import org.springframework.jdbc.core.JdbcTemplate;  
  8. import org.springframework.stereotype.Repository;  
  9.   
  10. /** 
  11.  * 测试标签dao 
  12.  *  
  13.  * @author zjl 
  14.  * 
  15.  */  
  16. @Repository  
  17. public class TagTestDao{  
  18.     @Autowired  
  19.     private JdbcTemplate jdbcTemplate;  
  20.       
  21.       
  22.     public List getList(){  
  23.         List list = new ArrayList();  
  24.         String sql = "select * from user";  
  25.         jdbcTemplate.execute(sql);  
  26.         return list;  
  27.     }  
  28.   
  29. }  

2.配置文件:

[html]
  1. <beans xmlns="http://www.springframework.org/schema/beans"    
  2.  xmlns:context="http://www.springframework.org/schema/context"    
  3.  xmlns:p="http://www.springframework.org/schema/p"    
  4.  xmlns:mvc="http://www.springframework.org/schema/mvc"    
  5.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  6.  xsi:schemaLocation="http://www.springframework.org/schema/beans    
  7.       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    
  8.       http://www.springframework.org/schema/context    
  9.       http://www.springframework.org/schema/context/spring-context.xsd    
  10.       http://www.springframework.org/schema/mvc    
  11.       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">    
  12.      <!-- 启动注解驱动的Spring MVC功能,注册请求url和注解POJO类方法的映射-->    
  13.      <mvc:annotation-driven />    
  14.      <!-- 启动包扫描功能,以便注册带有@Controller、@Service、@repository、@Component等注解的类成为spring的bean -->    
  15.      <context:component-scan base-package="xm.zjl.*" />    
  16.      <!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->    
  17.      <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/" p:suffix=".jsp" />  
  18.       
  19.      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">  
  20.          <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>  
  21.          <property name="url" value="jdbc:mysql://localhost:3306/mydata"></property>  
  22.          <property name="username" value="root"></property>  
  23.          <property name="password" value="root"></property>  
  24.      </bean>  
  25.        
  26.       
  27.      <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">  
  28.         <property name="dataSource" ref="dataSource"/>  
  29.      </bean>  
  30.           
  31.       
  32. </beans>    

2.继承JdbcDaoSupport类,但是dataSource没有设置成功(注解方式),若果有方法请留言,多谢

转载地址:http://xzhym.baihongyu.com/

你可能感兴趣的文章
Linux中用户和组中认证库和解析库的文件格式以及默认参数定义文件
查看>>
Windows中如何删除大量文件夹
查看>>
radio多次点击 选中与不选中
查看>>
21天让你成为Horizon View高手—Day19:Horizon View 5.2新功能—Html Ac
查看>>
netty初步认知
查看>>
redis
查看>>
用过的发送邮件的方法。
查看>>
VMWare
查看>>
【论文阅读】Image Super-Resolution Using Deep Convolutional Networks
查看>>
web.xml 中的listener、 filter、servlet 加载顺序及其详解
查看>>
try catch finally
查看>>
Windows编程之作业篇
查看>>
一文了解“Service Mesh(服务网格)”的历史与现在
查看>>
使用 rt_tables 巧妙配置 Linux centos7多网卡多路由实现策略路由
查看>>
Javascript中的RegExp类型
查看>>
Java 基础
查看>>
Spring的代理选择
查看>>
PHP搭建简易留言板
查看>>
websphere set jndi
查看>>
ORACLE同义词总结
查看>>