扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
成都创新互联公司专业为企业提供钟楼网站建设、钟楼做网站、钟楼网站设计、钟楼网站制作等企业网站建设、网页设计与制作、钟楼企业网站模板建站服务,10年钟楼做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
1.0.0 shequ springdemo13 0.0.1-SNAPSHOT 1.7 UTF-8 UTF-8 codelds https://code.lds.org/nexus/content/groups/main-repo junit junit 4.10 org.springframework spring-core 4.1.4.RELEASE org.springframework spring-context 4.1.4.RELEASE org.springframework spring-jdbc 4.1.4.RELEASE MySQL mysql-connector-java 5.1.34
package com.mycompany.shequ.bean; public class Forum { private int fid; private String name; public int getFid() { return fid; } public void setFid(int fid) { this.fid = fid; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
package com.mycompany.shequ.dao; import java.util.List; import com.mycompany.shequ.bean.Forum; public interface ForumDao { public Listquery() throws Exception ; }
package com.mycompany.shequ.dao.impl; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import javax.sql.DataSource; import com.mycompany.shequ.bean.Forum; import com.mycompany.shequ.dao.ForumDao; public class ForumDaoImpl implements ForumDao{ private DataSource dataSource; public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } public Listquery() throws Exception { Connection conn = dataSource.getConnection(); String sql = "select * from hnsq_forum"; Statement smt = conn.createStatement(); ResultSet rs = smt.executeQuery(sql); List forumList = new ArrayList (); while(rs.next()){ Forum forum = new Forum(); forum.setFid(rs.getInt("fid")); forum.setName(rs.getString("name")); forumList.add(forum); } return forumList; } }
package com.mycompany.shequ.dao.impl; import java.util.List; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.mycompany.shequ.bean.Forum; import com.mycompany.shequ.dao.ForumDao; public class ForumDaoImplTest { @Test public void queryTest(){ ApplicationContext context = new ClassPathXmlApplicationContext("spring-module.xml"); ForumDao forumDao = (ForumDao) context.getBean("forumDao"); try { ListforumList = forumDao.queryDepartment(); for (Forum forum : forumList) { System.out.println(forum.getFid()); System.out.println(forum.getName()); } } catch (Exception e) { e.printStackTrace(); } } }
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流