MyBatis set标签
示例
要求:根据 id 修改网站名称或网址(本节示例基于《个MyBatis程序》一节的代码实现)。WebsiteMapper.xml 代码如下。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis网站站点" rel="nofollow" />
package net.biancheng.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import net.biancheng.po.Website;
public interface WebsiteMapper {
public List<Website> selectWebsite(Website site);
public int updateWebsite(Website site);
}
测试类代码如下。
package net.biancheng.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import net.biancheng.mapper.WebsiteMapper;
import net.biancheng.po.Website;
public class Test {
public static void main(String[] args) throws IOException {
InputStream config = Resources.getResourceAsStream("mybatis-config.xml");
SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(config);
SqlSession ss = ssf.openSession();
Website site = new Website();
site.setId(1);
site.setUrl("www.biancheng网站站点" rel="nofollow" />
DEBUG [main] - ==> Preparing: SELECT * FROM website WHERE id=?
DEBUG [main] - ==> Parameters: 1(Integer)
DEBUG [main] - <== Total: 1
Website[id=1,name=编程帮,url=http://www.biancheng网站站点" rel="nofollow" />