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(); } } }
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。