ibatis的SQL语句有问号!
selectidfrombaseinfowhereid=?andId=?这是执行时用debug打印出来的。知道里有一个同似的提问,但是看不懂。(http://zhidao...
select id from baseinfo where id=? and Id=?
这是执行时用debug打印出来的。
知道里有一个同似的提问,但是看不懂。(http://zhidao.baidu.com/question/123307249.html)。
以下为回答:
这么写
param**="int"(*代表省略)
delete from student where id = #value#
就可以执行了
我是用 parameterClass="java.util.Map" 传的值,和他这个有点区别,忘高手来看看啊。
但是我在另外一个工程都能查询的。。。新建的工程就不行了,代码这些都没动。感觉是没配置好一样。 展开
这是执行时用debug打印出来的。
知道里有一个同似的提问,但是看不懂。(http://zhidao.baidu.com/question/123307249.html)。
以下为回答:
这么写
param**="int"(*代表省略)
delete from student where id = #value#
就可以执行了
我是用 parameterClass="java.util.Map" 传的值,和他这个有点区别,忘高手来看看啊。
但是我在另外一个工程都能查询的。。。新建的工程就不行了,代码这些都没动。感觉是没配置好一样。 展开
展开全部
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Test">
<statement id="insert_student"
parameterClass="zh2208.dto.StudentDto">
insert into student(
id,name,age,sex,address) values(
#id#,#name#,#age#,#sex#,#address# )
</statement>
<statement id="delete_all_student">
delete from student
</statement>
<statement id="deleteByID_student"
parameterClass="zh2208.dto.StudentDto">
delete from student where
id = #id#
</statement>
<statement id="updataStudent_test"
parameterClass="zh2208.dto.StudentDto">
update student set
name=#name#,sex=#sex#,age=#age#,address=#address#
where id = #id#
</statement>
<statement id="select_all_student"
resultClass="zh2208.dto.StudentDto">
select * from student order by id
</statement>
<statement id="selectByID_student"
parameterClass="zh2208.dto.StudentDto"
resultClass="zh2208.dto.StudentDto">
select * from student
where id = #id#
order by id
</statement>
</sqlMap>
上面是ibatis2.0版本的xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="BlogMapper">
<select id="findById" parameterType="java.lang.Integer" resultType="Blog">
select * from Blog where blogid =#{blogid}#
</select>
<delete id="deleteById" parameterType="java.lang.Integer">
delete Blog where blogid =#{blogid}#
</delete>
<update id="updateBlog" parameterType="Blog">
update Blog set author=#{author}#,subject=#{subject}#,content=#{content}#
, publishTime=#{publishTime}# where blogid=#{blogid}
</update>
<insert id="addBlog" parameterType="Blog">
insert into Blog(blogid,author,subject,content, publishTime)
values(#{blogid},#{author},#{subject},#{content},#{publishTime})
</insert>
<select id="findAll" resultType="java.util.List">
select * from Blog
</select>
</mapper>
这个是ibatis3.0版本的
parameterClass="java.util.Map"用这个传值比较诡异
一般都是用类对象来传值
ibatis是思想就是对象和数据库建立关系
一个类对应一个数据库的表
对应起来后查询修改删除
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Test">
<statement id="insert_student"
parameterClass="zh2208.dto.StudentDto">
insert into student(
id,name,age,sex,address) values(
#id#,#name#,#age#,#sex#,#address# )
</statement>
<statement id="delete_all_student">
delete from student
</statement>
<statement id="deleteByID_student"
parameterClass="zh2208.dto.StudentDto">
delete from student where
id = #id#
</statement>
<statement id="updataStudent_test"
parameterClass="zh2208.dto.StudentDto">
update student set
name=#name#,sex=#sex#,age=#age#,address=#address#
where id = #id#
</statement>
<statement id="select_all_student"
resultClass="zh2208.dto.StudentDto">
select * from student order by id
</statement>
<statement id="selectByID_student"
parameterClass="zh2208.dto.StudentDto"
resultClass="zh2208.dto.StudentDto">
select * from student
where id = #id#
order by id
</statement>
</sqlMap>
上面是ibatis2.0版本的xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="BlogMapper">
<select id="findById" parameterType="java.lang.Integer" resultType="Blog">
select * from Blog where blogid =#{blogid}#
</select>
<delete id="deleteById" parameterType="java.lang.Integer">
delete Blog where blogid =#{blogid}#
</delete>
<update id="updateBlog" parameterType="Blog">
update Blog set author=#{author}#,subject=#{subject}#,content=#{content}#
, publishTime=#{publishTime}# where blogid=#{blogid}
</update>
<insert id="addBlog" parameterType="Blog">
insert into Blog(blogid,author,subject,content, publishTime)
values(#{blogid},#{author},#{subject},#{content},#{publishTime})
</insert>
<select id="findAll" resultType="java.util.List">
select * from Blog
</select>
</mapper>
这个是ibatis3.0版本的
parameterClass="java.util.Map"用这个传值比较诡异
一般都是用类对象来传值
ibatis是思想就是对象和数据库建立关系
一个类对应一个数据库的表
对应起来后查询修改删除
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询