liferay6.1的SSI整合2(SDK开发)

阅读更多
UserAction:
package com.action;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.service.IUserService;
import com.vo.User;
public class UserAction extends ActionSupport{
		
	private static final long serialVersionUID = 3836787603947654532L;
	
	private IUserService userService;
    private  List userList;
    private User user;
    
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List getUserList() {
		return userList;
	}

	public void setUserList(List userList) {
		this.userList = userList;
	}

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	public String findAllUsers() throws Exception {
		System.out.println("find--user");
        userList = userService.findAllUsers();
    	System.out.println("find over----------------");
		return "finduser";
	}
	
	public String ssi()throws Exception{
		System.out.println("index...action");
		return "view";
	}
	
	public String addUser()throws Exception{
		System.out.println("name---"+user.getName());
		System.out.println("name---"+user.getAge());
		userService.addUser(user);
		return "addUserSuccess";
	}
	
}



DAO层 IUserDao :
package com.dao;

import java.util.List;

import com.vo.User;

public interface IUserDao {

	public List findAllUsers();

        public User findUserByKey(int id);

        public void deleteUser(User user);

	public void addUser(User user);

	public void updateUser(User user);

}



DAO层 UserDao

package com.daoImpl;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.dao.IUserDao;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.vo.User;

public class UserDao extends SqlMapClientDaoSupport implements IUserDao {


	public void addUser(User user) {
		this.getSqlMapClientTemplate().insert("saveUser", user);
	}

	public void deleteUser(User user) {
		this.getSqlMapClientTemplate().delete("deleteUser", user);
	}

	public List findAllUsers() {
		List list = null;
		list = this.getSqlMapClientTemplate().queryForList("getAllUsers");
		return list;
	}

	public User findUserByKey(int id) {
		User user = null;
		user = (User) this.getSqlMapClientTemplate().queryForObject("findUserById", id);
		return user;
	}

	public void updateUser(User user) {
		this.getSqlMapClientTemplate().update("updateUser", user);
	}

}


Service 层 UserServiceImpl
package com.serviceImpl;
import java.util.List;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.dao.IUserDao;
import com.ibatis.sqlmap.client.SqlMapClient;

import com.service.IUserService;
import com.vo.User;


public class UserServiceImpl extends SqlMapClientTemplate implements
		IUserService {
	
	private IUserDao userDao;
	public IUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	public void addUser(User user) {
		userDao.addUser(user);
	}

	public void deleteUser(User user) {
		userDao.deleteUser(user);
	}

	public List findAllUsers() {
		return userDao.findAllUsers();
	}



	public void updateUser(User user) {
		userDao.updateUser(user);
	}

	@Override
	public User findUserByKey(int id) {

		return userDao.findUserByKey(id);
	}

}


Service层 IUserService
package com.service;

import java.util.List;
import com.vo.User;
public interface IUserService {

	public List findAllUsers();
	
public User findUserByKey(int id);
	
	public void deleteUser(User user);
	
	public void addUser(User user);
	
	public void updateUser(User user);
	
}



实体类:User
package com.vo;
import java.io.Serializable;
public class User implements Cloneable, Serializable {
	
	private static final long serialVersionUID = -9103289450003300385L;

	private int id;
	private String name;
	private String age;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	public String getAge() {
		return age;
	}
	public void setAge(String age) {
		this.age = age;
	}

}

你可能感兴趣的:(java,liferay)