userdao.java

来自「本demo为完整的」· Java 代码 · 共 48 行

JAVA
48
字号
package com.greysh.genix.dao;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;
import com.greysh.genix.model.User;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class UserDao {
	private static SqlMapClient sqlMapper;
	static {
		try {
			String source = "com\\greysh\\genix\\config\\SqlMapConfig.xml";
			Reader reader = Resources.getResourceAsReader(source);
			sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		} catch (IOException e) {
			throw new RuntimeException(
					"Something bad happened while building the SqlMapClient instance."
							+ e, e);
		}
	}

	public static List<?> selectAllUser() throws SQLException {
		return sqlMapper.queryForList("selectAllUser");
	}

	public static User selectUserById(int id) throws SQLException {
		return (User) sqlMapper.queryForObject("selectUserById", id);
	}

	public static void insertUser(User user) throws SQLException {
		sqlMapper.insert("insertUser", user);
	}

	public static void updateUser(User user) throws SQLException {
		sqlMapper.update("updateUser", user);
	}

	public static void deleteUser(int id) throws SQLException {
		sqlMapper.delete("deleteUserById", id);
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?