ibatis中xml里sql如何使用常量呢
比如select * from stu where id = ‘5’我想直接写个5 --------------------编程问答-------------------- 还是每次传进去吧。
或者这样试试:
Account.java
public class Account {
private int id;
private String firstName;
private String lastName;
private String emailAddress;
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;
}
}
Account.xml
<?xml version="1.0" encoding="UTF-8" ?>--------------------编程问答-------------------- 那就直接写呗。 --------------------编程问答-------------------- ibatis本来就是非常灵活的,你想直接写就直接写呗。 --------------------编程问答-------------------- 可以直接写的啥 --------------------编程问答-------------------- 当然可以直接写了。just do it --------------------编程问答-------------------- 定义一下呗比如action里定义sum=5,然后配置文件里传入#{sum}就ok了
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Account">
<typeAlias alias="Account" type="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 id="getByLike" 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_EMAIL like '%$value$%'
</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>
</sqlMap>
补充:Java , Web 开发