- 浏览: 164664 次
- 性别:
- 来自: 武汉
文章分类
最新评论
配置和BS差不多,附上程序
1、用来传输对象的DTO
package com.yihaodian.pis.dto; import java.io.Serializable; public class SiteCategoryDto implements Serializable { private static final long serialVersionUID = -8202969095017554696L; /** * 分类id */ private Integer id; /** * 网站id */ private Integer siteId; /** * 分类名称 */ private String categoryName; /** * 分类产品列表对应的url */ private String categoryUrl; /** * 父分类id */ private Integer parentCategoryId; /** * 分类级别 */ private Integer categoryLevel; /** * 商品抓取数量 */ private Integer fetchSize; /** * 网站名称 */ private String siteName; /** * 父亲分类名称 */ private String parentName; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getSiteId() { return siteId; } public void setSiteId(Integer siteId) { this.siteId = siteId; } public String getCategoryName() { return categoryName; } public void setCategoryName(String categoryName) { this.categoryName = categoryName; } public String getCategoryUrl() { return categoryUrl; } public void setCategoryUrl(String categoryUrl) { this.categoryUrl = categoryUrl; } public Integer getParentCategoryId() { return parentCategoryId; } public void setParentCategoryId(Integer parentCategoryId) { this.parentCategoryId = parentCategoryId; } public Integer getCategoryLevel() { return categoryLevel; } public void setCategoryLevel(Integer categoryLevel) { this.categoryLevel = categoryLevel; } public Integer getFetchSize() { return fetchSize; } public void setFetchSize(Integer fetchSize) { this.fetchSize = fetchSize; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("SiteCategory [id="); builder.append(id); builder.append(", siteId="); builder.append(siteId); builder.append(", categoryName="); builder.append(categoryName); builder.append(", categoryUrl="); builder.append(categoryUrl); builder.append(", fetchSize="); builder.append(fetchSize); builder.append(", categoryLevel="); builder.append(categoryLevel); builder.append(", parentCategoryId="); builder.append(parentCategoryId); builder.append("]"); return builder.toString(); } public String getSiteName() { return siteName; } public void setSiteName(String siteName) { this.siteName = siteName; } public String getParentName() { return parentName; } public void setParentName(String parentName) { this.parentName = parentName; } }
2、对数据库操作的DAO
package com.yihaodian.pricehisotry.dao; import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; import com.yihaodian.pis.dto.SiteCategoryDto; /** * 畅销商品数据库操作 */ public class SiteCategoryDao extends SqlMapClientDaoSupport{ public SiteCategoryDao() { } public int clearSiteCategories(int id) { return this.getSqlMapClientTemplate().delete("clearSiteCategories", id); } /* * 保存分类畅销商品记录 */ public void saveSiteCategory(SiteCategoryDto siteCategory) { this.getSqlMapClientTemplate().insert("addSiteCategory", siteCategory); } public Integer getMaxId(){ Object count = this.getSqlMapClientTemplate().queryForObject("getMaxId"); return Integer.parseInt(count.toString()); } /** * 添加分类畅销商品记录 */ public int addSiteCategory(SiteCategoryDto siteCategory) { return (int) ((Long) this.getSqlMapClientTemplate().insert( "addSiteCategory", siteCategory)).longValue(); } }
3、SQLmap对数据库操作的语句
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" > <sqlMap namespace="bestseller"> <typeAlias alias="SiteCategoryDto" type="com.yihaodian.pis.dto.SiteCategoryDto" /> <resultMap class="SiteCategoryDto" id="SiteCategoryResult"> <result property="id" column="id" javaType="java.lang.Integer" jdbcType="SERIAL" /> <result property="siteId" column="site_id" javaType="java.lang.Integer" jdbcType="INTEGER" /> <result property="categoryName" column="category_name" javaType="java.lang.String" jdbcType="VARCHAR" /> <result property="categoryUrl" column="category_url" javaType="java.lang.String" jdbcType="VARCHAR" /> <result property="parentCategoryId" column="parent_category_id" javaType="java.lang.Integer" jdbcType="INTEGER" /> <result property="categoryLevel" column="category_level" javaType="java.lang.Integer" jdbcType="INTEGER" /> <result property="fetchSize" column="fetch_size" javaType="java.lang.Integer" jdbcType="INTEGER" /> </resultMap> <insert id="addSiteCategory" parameterClass="SiteCategoryDto"> INSERT INTO pis.site_category(site_id,category_name,category_url,parent_category_id,category_level,fetch_size) VALUES (#siteId#,#categoryName#,#categoryUrl#,#parentCategoryId#,#categoryLevel#,#fetchSize#) <selectKey> SELECT lastval(); </selectKey> </insert> <select id="countGetAllSiteCategory" resultClass="java.lang.Integer"> select count(*) FROM pis.site_category </select> <delete id="deleteSiteCategory" parameterClass="java.lang.Integer"> DELETE FROM pis.site_category where id=#id# </delete> <delete id="clearSiteCategories" parameterClass="java.lang.Integer"> DELETE FROM pis.site_category where site_id = #site_id# </delete> <select id="countGetCategoryBySite" resultClass="java.lang.Integer"> select count(*) FROM pis.site_category where site_id=#siteId# </select> <select id="countGetCategoryBySiteLevel" resultClass="java.lang.Integer"> select count(*) FROM pis.site_category where site_id=#siteId# and category_level=#categoryLevel# </select> <select id="getCategoryByName" parameterClass="SiteCategoryDto" resultMap="SiteCategoryResult"> SELECT id,site_id,category_name,category_url,parent_category_id,category_level,fetch_size FROM pis.site_category where site_id=#siteId# and category_level=#categoryLevel# and category_name=#categoryName# </select> <select id="getCategoryByParentId" parameterClass="java.lang.Integer" resultMap="SiteCategoryResult"> SELECT id,site_id,category_name,category_url,parent_category_id,category_level,fetch_size FROM pis.site_category where parent_category_id=#parentCategoryId# </select> <select id="queryCategoryById" parameterClass="java.lang.Integer" resultMap="SiteCategoryResult"> SELECT id,site_id,category_name,category_url,parent_category_id,category_level,fetch_size FROM pis.site_category where id=#id# </select> <select id="getMaxId" resultClass="java.lang.Integer"> select max(id) from pis.site_category; </select> </sqlMap>
4、DAO的申明配置
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!----> <bean id="siteCategoryDao" class="com.yihaodian.pricehisotry.dao.SiteCategoryDao"> <property name="dataSource" ref="dataSource" /> <property name="sqlMapClient" ref="sqlMapClient" /> </bean> </beans>
5、连接数据库的配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- org.springframework.beans.factory.config.PropertyPlaceholderConfigurer com.yihaodian.common.util.DecryptPropertyPlaceholderConfigurer --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:jdbc.properties</value> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="maxActive" value="100" /> <property name="maxIdle" value="30" /> <property name="maxWait" value="1000" /> <property name="defaultAutoCommit" value="true" /> <property name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout" value="60" /> </bean> <!-- SqlMap setup for iBATIS Database Layer --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"> <value>classpath:sqlmap-config.xml</value> </property> <property name="dataSource" ref="dataSource" /> </bean> <!-- Transaction manager for a single JDBC DataSource --> <!-- <tx:annotation-driven /> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> --> </beans>
6、将数据库操作XML引入
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <settings enhancementEnabled="true" maxTransactions="10" maxRequests="32" maxSessions="20" /> <!-- --> <sqlMap resource="sqlmap/sqlmap_Bestseller.xml"/> </sqlMapConfig>
- src.rar (38.3 KB)
- 下载次数: 0
- config.rar (10.5 KB)
- 下载次数: 0
相关推荐
一个java 多线程操作数据库应用程序!!!
02 掌握通过Java应用程序操作MySQL数据库的方法和步骤,包括查询(顺序查询、游动查询)、添加、修改和删除数据记录等基本数据操作过程。 03 了解通过预编译SQL语句对MySQL数据库进行数据操作的过程。 04 理解预...
任务1 将P171页程序片段补充完整 任务2 Modify the program labstaff.java 任务3 Modify the program labupdate.java 任务4 将labupdate.java修改为GUI的形式,用户输入和修改结果的输出均通过调用JOptionPane类的...
和JBuilder工程文件,以及实例中应用的数据库,并有在实例中涉及的相关Java类文件(数据库 驱动程序)。配书光盘中全部内容包括: 1. 各章实例源程序 实例源程序以及实例中应用的数据库在光盘的各章实例目录中,...
JAVA JDK 11软件新增Epsilon 垃圾收集器和lambda 参数的局部变量语法,可以有效的提高开发者的生产效率和Java应用程序的管理。 新的Java编译器API允许从Java应用程序内部对Java源程序进行编译。在编译期间,应用...
利用Java开发数据库应用时,经常需要在用户界面上显示查询结果。我们可以利用Vector、JTable、AbstractTableModel等三个类较好地解决这一问题。 类Vector: 定义如下: public class Vector extends ...
dbtrace 是基于Java语言开发的数据库访问性能诊断工具,设计目标是使应用程序零代码修改、无缝集成到应用中,轻松完成Java应用中JDBC访问的性能诊断、耗时跟踪、调用栈跟踪及日志记录。
实践周子任务二(JDBC程序设计):了解JDBC工作的基本原理和掌握JDBC编程的基本步骤,按要求编写一个带有图形用户界面的数据库应用程序,具备增加、删除、查询、修改功能。 实践周高级子任务:结合子任务一和二,构建一...
HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.2 -------------------------------------------------------------------------------- 目录 前言 1. 翻译说明 2. 版权声明 1. Hibernate...
3. 对Java-swing的知识有一定的了解,需要学习总结应用相关知识或者想找项目练手 实现的功能: 实现功能包括学生信息的新增、编辑、查看、删除;班级信息管理、包括班级信息的新增、编辑、查看、删除。其中学生、...
" " " " " " " " " " " " " " " " " " " " " " " " " " "为了不暴露表结构和只显示用户需要的信息,建立了一个视图record " " " " " " " "下面是用java连接数据库的过程: " "首先下载java连接sql数据库的驱动程序,...
简单的图形界面实现数据库的增删查改,使用java图形界面对数据库进行增删查改的相关操作,代码简单能够进行简单的修改
3.3.1 创建、取消、更改数据库和表 3.3.2 创建、更改和取消视图 3.4 数据处理语言 3.4.1 INSERT语句 3.4.2 UPDATE语句 3.4.3 DELETE语句 3.5 数据查询语言 3.5.1 SELECT语句 3.5.2 WHERE子句 3.5.3 SQL...
195 第6章 Java C/S结构编程 197 实例67 实现C/S多线程 198 实例68 客户端程序 200 实例69 服务器端程序 201 实例70 C/S结构聊天室 203 实例71 基于C/S的小游戏 209 实例72 应用C/S数据库 237...
该光盘中有《Java数据库编程实例》一书中的所有实例源程序代码,编译通过的实例类代码 和JBuilder工程文件,以及实例中应用的数据库,并有在实例中涉及的相关Java类文件(数据库 驱动程 序)。配书光盘中全部内容包括...
IronEye SQL 这个轻量级的 Java 工具提供所有流动在数据库与应用程序之间的 SQL 统计信息并用多张图表展现,可以快速优化程序的性能。 IronGrid 相对于 Continuous Integration 提出了 Continuous Performance 的...
booleanisClosed()throwsSQLException 查询此ResultSet对象是否已经被关闭 StatementgctStatcmcnt()throwsSQLException 获取生成此ResultSet对象的Statement对象 (4)数据库的查询和更新操作 Java数据库应用程序中...
通过应用awt等包,合理的添加了按钮、菜单、文本框、文本区、表格等组件类,还包含窗口、面板等容器类,经过设计者合理的布局,完成了窗体的设计,并通过建立JDBC-ODBC桥接器连接到mysql数据库后,向数据库发送SQL...