【web开发学习笔记】ibatis学习总结,学习笔记ibatis
【web开发学习笔记】ibatis学习总结,学习笔记ibatis
ibatis学习总结
ibatis数据库配置文件
<?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> <dataSource type="SIMPLE"> <property name="JDBC.Driver" value="org.hsqldb.jdbcDriver"/> <property name="JDBC.ConnectionURL" value="jdbc:hsqldb:."/> <property name="JDBC.Username" value="carp"/> <property name="JDBC.Password" value="123"/> </dataSource> </transactionManager> <sqlMap resource="com/mydomain/data/Account.xml"/> </sqlMapConfig>
数据库与model映射配置文件
<?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="Account"> <resultMap id="AccountResult" class="Account"> <result property="id" column="ACC_ID"/> <result property="firstName" column="ACC_FIRST_NAME"/> <result property="lastName" column="ACC_LAST_NAME"/> <result property="emailAddress" column="ACC_EMAIL"/> </resultMap> <!-- Select with no parameters using the result map for Account class. --> <select id="selectAllAccounts" resultMap="AccountResult"> select * from ACCOUNT </select> <!-- A simpler select example without the result map. Note the aliases to match the properties of the target result class. --> <select id="selectAccountById" parameterClass="int" resultClass="Account"> select ACC_ID as id, ACC_FIRST_NAME as firstName, ACC_LAST_NAME as lastName, ACC_EMAIL as emailAddress from ACCOUNT where ACC_ID = #id# </select> <!-- Insert example, using the Account parameter class --> <insert id="insertAccount" parameterClass="Account"> insert into ACCOUNT ( ACC_ID, ACC_FIRST_NAME, ACC_LAST_NAME, ACC_EMAIL values ( #id#, #firstName#, #lastName#, #emailAddress# ) </insert> <!-- Update example, using the Account parameter class --> <update id="updateAccount" parameterClass="Account"> update ACCOUNT set ACC_FIRST_NAME = #firstName#, ACC_LAST_NAME = #lastName#, ACC_EMAIL = #emailAddress# where ACC_ID = #id# </update> <!-- Delete example, using an integer as the parameter class --> <delete id="deleteAccountById" parameterClass="int"> delete from ACCOUNT where ACC_ID = #id# </delete> </sqlMap>
Model对象
package com.mydomain.domain; public class Account { private int id; private String firstName; private String lastName; private String emailAddress; /*Model层,主要进行数据访问部分*/ public int getId() { return id; } public void setId(int id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } }
DAO数据访问对象
package com.mydomain.data; import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.client.SqlMapClientBuilder; import com.ibatis.common.resources.Resources; import com.mydomain.domain.Account; import java.io.Reader; import java.io.IOException; import java.util.List; import java.sql.SQLException; public class SimpleExample { /** * SqlMapClient instances are thread safe, so you only need one.In this case, we'll use a static singleton. */ private static SqlMapClient sqlMapper; /** * It's not a good idea to put code that can fail in a class initializer, * but for sake of argument, here's how you configure an SQL Map. */ static { try { Reader reader = Resources.getResourceAsReader("com/mydomain/data/SqlMapConfig.xml"); sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); reader.close(); } catch (IOException e) { // Fail fast. throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e); } } public static List selectAllAccounts () throws SQLException { return sqlMapper.queryForList("selectAllAccounts"); } public static Account selectAccountById (int id) throws SQLException { return (Account) sqlMapper.queryForObject("selectAccountById", id); } public static void insertAccount (Account account) throws SQLException { sqlMapper.insert("insertAccount", account); } public static void updateAccount (Account account) throws SQLException { sqlMapper.update("updateAccount", account); } public static void deleteAccount (int id) throws SQLException { sqlMapper.delete("deleteAccount", id); } }
结论:
1、通过数据库和Model对象映射配置文件,将数据库中表与java对象进行关联;
2、通过数据库配置文件,里面包含数据库与model对象映射配置文件,保证数据库连接;
3、通过DAO进行数据库的增删改查操作;
我说说主要的《html》《java基础》《java服务器》《servlet》《jsp》《javabean》《javamail》《web层技术》(struts,jsf,等)《业务层技术》(spring)《持久化层技术》(jdbc hibernate 等)
还有一些 css js 等前台技术。连结池。等后台小技术 呵呵 只想到这么多拉
首先声明我不是高手,我是计算机专业的,但WEB开发完全是自学的。应该说WEB开发自学是程序设计中比较容易的,但是要学的东西很多。大体我总结为以下几个方面。
第一大步:掌握前台技术
1、学会HTML,再熟悉一下XHTML,了解他们之间的区别,学习的过程当中少用DreamWever这种所见即所得的软件进行代码编写,建议使用EditPLus或者ue等具有高亮代码提示功能的文本编辑器进行代码编写。
2、学会CSS,重在理解CSS的优点,区别使用和不使用CSS的利弊。代码测试编写同上。
3、学会JavaScript,主要学会利用DOM(文档模型)来操作HTML元素,还有BOM(浏览器模型)来操作窗口。
第二大步:掌握服务器脚本
1、选择一门自己认为顺眼的动态脚本语言,就象你说的PHP(不要去考量语言的优劣性),掌握语法结构,掌握常用函数,类。
2、熟悉SQL语句的使用(对于常用网站而言),熟悉一种数据库的使用。
3、能够配合Javascript和动态脚本语言来实现流行的Ajax模式。
打的好累,希望会对你有所帮助。以上里面出现的专业词汇如不懂请百度一下或者问我,我就不给你复制粘贴了。当然,现在网站制作这方面已经分的挺清楚了,如果你比较喜欢服务器脚本方面的东东,那就偏重一些第二步,否则··那就偏重一些第一步。
评论暂时关闭