public interface IAccountDao {
//保存用户
public Boolean save(Account account);
//修改用户信息
public Boolean update(Account account);
//删除用户
public Boolean delete(Account account);
//查询单个
public Account get(Long id);
//查询用户列表
public List list(int start, int num);
}
public class AccountDaoImpl implements IAccountDao {
public Boolean save(Account account) {
String sql = "INSERT INTO account (nickName, password,email,phoneNumber,iconUrl,intro,registerTime) VALUES (?,?,?,?,?,?,?);";
return JdbcTemplate.update(sql, account.getNickName(), account.getPassword(), account.getEmail(),
account.getPhoneNumber(), account.getIconUrl(), account.getIntro(),
account.getRegisterTime()) != 0;
}
public Boolean update(Account account) {
String sql = "UPDATE account " +
"SET nickName = ?," +
" password = ?," +
" email= ?," +
" phoneNumber= ?," +
" iconUrl= ?," +
" intro= ?," +
" registerTime= ? " +
"WHERE " +
"id = ?;";
Object[] params = {
account.getNickName(),
account.getPassword(),
account.getEmail(),
account.getPhoneNumber(),
account.getIconUrl(),
account.getIntro(),
account.getRegisterTime(),
account.getId()
};
return JdbcTemplate.update(sql, params) != 0;
}
public Account get(Long id) {
String sql = "SELECT * FROM account WHERE id = ?; ";
Account accounta = (Account) JdbcTemplate.query(sql, new BeanHandler(Account.class), id);
return accounta;
}
public List list(int start, int num) {
String sql = "SELECT * FROM account LIMIT ?,?";
Object[] params = {start, num};
List accounts = (List) JdbcTemplate.query(sql, new BeanListHandler(Account.class), params);
return accounts;
}
public Boolean delete(Account account) {
String sql = "DELETE FROM account WHERE id = ?";
return JdbcTemplate.update(sql, account.getId()) != 0;
}
}
public class BookDaoImpl implements IBookDao{
public long save(Book book) {
String sql="INSERT INTO book (title,author,isbn,publish,pagecount,price,imgurl,contentabstract,authorabstract,menuabstract,sharerid) " +
"VALUES(?,?,?,?,?,?,?,?,?,?,?)";
Object[] params={book.getTitle(),book.getAuthor(),book.getIsbn(),
book.getPublish(),book.getPagecount(),book.getPrice(),book.getImgurl(),
book.getContentabstract(),book.getAuthorabstract(),book.getMenuabstract(),
book.getSharerid()};
JdbcTemplate.update(sql,params);
return 0;
}
public void update(Book book) {
String sql="UPDATE book SET title= ?,author=?,isbn=?,publish=?,pagecount=?,price=?,imgurl=?,contentabstract=?,authorabstract=?,menuabstract=?,sharerid=? WHERE id=?;";
Object[] params={book.getTitle(),book.getAuthor(),book.getIsbn(),
book.getPublish(),book.getPagecount(),book.getPrice(),book.getImgurl(),
book.getContentabstract(),book.getAuthorabstract(),book.getMenuabstract(),
book.getSharerid(),book.getId()};
JdbcTemplate.update(sql,params);
}
public void delete(Book book) {
String sql="DELETE FROM book WHERE id = ?;";
JdbcTemplate.update(sql,book.getId());
}
public List list(int start,int num) {
String sql="SELECT * FROM book LIMIT ?, ?";
return (List) JdbcTemplate.query(sql, new BeanListHandler(Book.class),start,num);
}
public Book get(long id) {
String sql="SELECT * FROM book WHERE id = ?";
return (Book) JdbcTemplate.query(sql, new BeanHandler(Book.class),id);
}
public List query(ObjectQuery qo) {
String sql="SELECT * FROM book"+qo.getQuery();
Object[] params=qo.getParameters().toArray();
return (List) JdbcTemplate.query(sql, new BeanListHandler(Book.class),params);
}
}
11.图书的高级查询
QueryObject: 主要目的是提供给DAO的查询条件: SELECT * FROM xxx +qo.getQuery();
public class QueryObject {
//查询条件
private List conditions = new ArrayList();
//查询条件的占位符
private List
private int currentPage=1;
private int pageSize=5;
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public class DaoFactory {
public static Object createDao(String name) {
if (name.equals("bookDao")) {
return new BookDaoImpl();
} else if (name.equals("accountDao")) {
return new AccountDaoImpl();
}
return null;
}
}
public class FactoryTest {
@Test
public void test1() {
IBookDao bookDao = (BookDaoImpl) DaoFactory.createDao("bookDao");
IAccountDao accountDao = (AccountDaoImpl) DaoFactory.createDao("accountDao");
}
}
改造升级之后:
public class BeanFactory {
private static Properties p=new Properties();
static {
try {
p.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("dao.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
public static T getBean(String beanName,Class beanType) throws Exception {
String className=p.getProperty(beanName);
if(className==null){
throw new RuntimeException("该名称["+beanName+"]没有对应对象");
}
T obj= (T) Class.forName(className).newInstance();
if(!beanType.isInstance(obj)){
throw new RuntimeException("类型不合");
}
return obj;
}
}
http://www.namhuy.net/475/how-to-install-gui-to-centos-minimal.html
I have centos 6.3 minimal running as web server. I’m looking to install gui to my server to vnc to my server. You can insta
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option,changed_ids ) values('0ac91f167f754c8cbac00e9e3dc372
实例1:
package com.bijian.thread;
public class MyThread extends Thread {
private static ThreadLocal tl = new ThreadLocal() {
protected synchronized Object initialValue() {
return new Inte
var v = 'C9CFBAA3CAD0';
console.log(v);
var arr = v.split('');
for (var i = 0; i < arr.length; i ++) {
if (i % 2 == 0) arr[i] = '%' + arr[i];
}
console.log(arr.join(''));
console.log(v.r