ibatisor配置文件|ibatis配置文件中update语句的写法

|

❶ ibatis配置文件中parameterClass指的是参数类型还是参数名

parameterClass和resultMap不是必须的,resultClass你有返回值的时候就配置一下

❷ ibatis的数据源有哪些配置方式

1、Transcation Manager Aliases分为三种JDBC、JTA、EXTERNAL2、Data Source Factory Aliases分成三种SIMPLE、DBCP、JNDI3、你可以直接在SqlMapConfig.xml中定义数据源,也可以通过在SqlMapConfig.xml中加载外部配置数据源文件如proterties属性文件或则xml文件。可以加载开源的数据源连接池的配置文件,推荐使用加载数据库连接池配置文件的方式。

❸ ss和ibatis框架,连接oracle的配置文件该怎么配

1.下载ibatis Jar包,我用的是ibatis-2.3.0.677.jar2.添加iBatis的config配置文件com.lubby.bean.SqlMapConfig.xml[html] view plain <?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> <!– 引用JDBC属性的配置文件 –> <!– <properties resource="com/lubby/bean/SqlMap.properties" /> –> <!– 使用JDBC的事务管理 –> <transactionManager type="JDBC"> <!– 数据源 –> <dataSource type="SIMPLE"> <property name="JDBC.Driver" value="org.postgresql.Driver" /> <property name="JDBC.ConnectionURL" value="jdbc:postgresql://127.0.0.1:5432/lubby" /> <property name="JDBC.Username" value="admin" /> <property name="JDBC.Password" value="admin" /> </dataSource> </transactionManager> <!– 这里可以写多个实体的映射文件 –> <sqlMap resource="com/lubby/bean/Student.xml" /> </sqlMapConfig> 3.添加实体类com.lubby.bean.Student.java[html] view plain public class Student { private String sid; private String name; private int age; public Student() { super(); } public Student(String sid, String name, int age) { super(); this.sid = sid; this.name = name; this.age = age; } public String getSid() { return sid; } public void setSid(String sid) { this.sid = sid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "Student [sid=" + sid + ", name=" + name + ", age=" + age + "]"; } } 4.添加实体类的Maping文件com.lubby.bean.Student.xml[html] view plain <?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> <!– 通过typeAlias使得我们在下面使用Student实体类的时候不需要写包名 –> <typeAlias alias="Student" type="com.lubby.bean.Student" /> <!– 这样以后改了sql,就不需要去改java代码了 –> <!– id表示select里的sql语句,resultClass表示返回结果的类型 –> <select id="getAllStudent" resultClass="Student"> select * from student </select> <!– parameterClass表示参数的内容 –> <!– #表示这是一个外部调用的需要传进的参数,可以理解为占位符 –> <select id="getStudentById" parameterClass="String" resultClass="Student"> select * from student where sid=#id# </select> </sqlMap> 5.DAO以及实现DAOcom.lubby..StudentDAO.java[java] view plain public interface StudentDAO { /** * 获取所有学生 * @return 所有学生信息列表 */ public List<Student> getAllStudent(); /** * 根据学生ID查询信息 * @return 所查学生信息 */ public Student getStudentById(String id); } com.lubby.impl.StudentDAOImpl.java[java] view plain package com.lubby.impl; import java.io.IOException; import java.io.Reader; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.ibatis.common.resources.Resources; import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.client.SqlMapClientBuilder; import com.lubby.bean.Student; import com.lubby..StudentDAO; public class StudentDAOImpl implements StudentDAO { private static SqlMapClient sqlMapClient = null; // 读取配置文件 static { try { Reader reader = Resources.getResourceAsReader("com/lubby/bean/SqlMapConfig.xml"); sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader); reader.close(); } catch (IOException e) { e.printStackTrace(); } } @Override public List<Student> getAllStudent() { List<Student> list = null; try { list = sqlMapClient.queryForList("getAllStudent"); } catch (SQLException e) { e.printStackTrace(); } return list; } @Override public Student getStudentById(String id) { Student student = null; try { student = (Student) sqlMapClient.queryForObject("getStudentById", id); } catch (SQLException e) { e.printStackTrace(); } return student; } } 6.调用DAO查询com.lubby.test.IbatisTest.java[java] view plain public class IbatisTest { public static void main(String[] args) { StudentDAO stuDaoImpl = new StudentDAOImpl(); List<Student> list = new ArrayList<>(); list = stuDaoImpl.getAllStudent(); for (Student stu : list) { System.out.println(stu); } Student student = stuDaoImpl.getStudentById("003"); System.out.println("ID为004的学生信息:" + student); } } 7.结果显示[plain] view plain Student [sid=001, name=Tom, age=22] Student [sid=002, name=Jack, age=23] Student [sid=003, name=Tom, age=20] Student [sid=004, name=Alice, age=18] ID为004的学生信息:Student [sid=003, name=Tom, age=20]

❹ ibatis配置文件:update标签

再仔细看一下你的语句,本来应该传给 CHAR 类型的数据,但你的参数是 TIMESTAMP 类型的,无法进行转换是类型写错了,还是传递的参数写错了

❺ ibatis配置文件中两个$中间夹字符串什么意思

在通常情况下ibatis的参数在sqlmap中使用#param#的形式,参数名以’#‘包着,但当使用sql的like语句时就发生了问题,在单引号中无法使用#param#这种形式。解决办法有: 1.当应用select * from table1 where col like ’%value%’时,如果要把‘value’以参数代替,可以把整个like后面的字符串全改为参数。即:select * from table1 where col like #param# ,此时参数param的值为字符串'%value%' 2.使用‘$’将参数名包起来。例如:name like ‘%#name#%’。我们的解决方法有2。(a)把name like ‘%#name#%’的#换成$,即:name like ‘%$name$%’。(b)用||连接字符串的方式,写成,name like ‘%’|| #name#‘%’。在iBatis中,对于in子句的标准做法是采用动态sql来解决的。具体方法大致是:Java代码传入一个List或者数组,然后在sqlMapConfig映射中使用iterate循环取这个变量,动态地生成sql语句。这个标准解法的缺点是,使用起来比较麻烦1. 需要在sqlMapConfig中使用动态语句2. 需要传入一个Iterable的变量对于这个问题,我使用了一个偷懒的办法,就是使用$标记。在iBatis中,普通的变量,比如:v,是使用#号,在这个例子中,就是:#v#。这样,iBatis会使用prepareStatement,并对变量进行变量绑定。而$符号是简单替代的用法,在数据库的执行效率上要比前一种差。但优点就是简单方便。比如:SELECT * FROM emp WHERE emp_no in ($empString$);而empString的值就是1, 2, 3. 在Log中,可以看到,Sql语句就是:SELECT * FROM emp WHERE emp_no in (1,2,3)

❻ ibatis 配置文件中 <select >中增加一个<iterate>,就报Element type "iterate" must be declared

这是因为没有定义property属性,需要在之后添加property属性,代码如下:

<iterateopen="("close=")"conjunction=","property="jobtableList">$jobtableList[].JOBORD$</iterate>

❼ Ibatis配置文件中 parameterClass,resultClass,resultMap 都具体是什么意思啊 是传入参数的类型么

parameterClass = 参数类型resultClass = 返回类型resultMap = 返回成员映射 resultMap:<resultMaps> <resultMap id="FullResultMap" class="Admin"> <result property="AdminId" column="adminId" dbType="Int"/> <result property="LoginName" column="loginName" dbType="NVarChar"/> <result property="Password" column="password" dbType="NVarChar"/> <result property="Keyword" column="keyword" dbType="NVarChar"/> </resultMap> </resultMaps>意思就是配置数据库返回的字段与实体类的对应关系。这个一般不需要。

❽ iBATIS配置文件中<resultMap>详解

resultMap = 返回成员映射 resultMap:<resultMaps> <resultMap id="FullResultMap" class="Admin"> <result property="AdminId" column="adminId" dbType="Int"/> <result property="LoginName" column="loginName" dbType="NVarChar"/> <result property="Password" column="password" dbType="NVarChar"/> <result property="Keyword" column="keyword" dbType="NVarChar"/> </resultMap> </resultMaps>意思就是配置数据库返回的字段与实体类的对应关系。这个一般不需要

❾ 详解iBatis主配置文件

主要是sqlMapConfig.xml:<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMapConfig (View Source for full doctype…)> – <sqlMapConfig>- <!– Configure a built-in transaction manager. If you're using an app server, you probably want to use its transaction manager and a managed datasource –> – <transactionManager type="JDBC" commitRequired="false">- <dataSource type="SIMPLE"> <property name="JDBC.Driver" value="org.hsqldb.jdbcDriver" /> <property name="JDBC.ConnectionURL" value="jdbc:hsqldb:." /> <property name="JDBC.Username" value="sa" /> <property name="JDBC.Password" value="sa" /> </dataSource> </transactionManager>- <!– List the SQL Map XML files. They can be loaded from the classpath, as they are here (com.domain.data…) –> <sqlMap resource="com/mydomain/data/Account.xml" /> – <!– List more here… <sqlMap resource="com/mydomain/data/Order.xml"/> <sqlMap resource="com/mydomain/data/Documents.xml"/> –> </sqlMapConfig>以及sql的映射问价,如Account.xml的文件内容:<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap (View Source for full doctype…)> – <sqlMap namespace="Account">- <!– Use type aliases to avoid typing the full classname every time. –> <typeAlias alias="Account" type="com.mydomain.domain.Account" /> – <!– Result maps describe the mapping between the columns returned from a query, and the class properties. A result map isn't necessary if the columns (or aliases) match to the properties exactly. –> – <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>

❿ ibatis配置文件中update语句的写法

ibatis标签提供生成sql的功能,没有标签满足你的需求。但是可以从sql的角度解决,像是你用select的时候的1=1的处理方式。我是这么搞的update user set id = id <…………> where id = #{id}


赞 (0)