nutz demo

阅读更多

 

package com.curiousby.nut;

import org.nutz.mvc.annotation.By;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.SetupBy;
import org.nutz.mvc.annotation.Views;
import org.nutz.mvc.ioc.provider.ComboIocProvider;
import org.nutz.mvc.view.JPEGViewMaker;

import com.curiousby.common.filter.CheckLoginFilter;
import com.curiousby.common.setup.SetupByMain;
 
/**
 * @author baoyou E-mail:[email protected]
 * @version 2016年1月20日 下午4:42:49
 *
 * desc: ...
 */
@Modules(scanPackage = true)
@Views(JPEGViewMaker.class)
@IocBy(type = ComboIocProvider.class, args = {
		"*org.nutz.ioc.loader.annotation.AnnotationIocLoader", "com.curiousby.nut",
		"*org.nutz.ioc.loader.xml.XmlIocLoader", "dao.xml" })
@Filters(@By(type = CheckLoginFilter.class, args = { "currentUser", "/index.jsp" }))
@SetupBy(SetupByMain.class)
public class MainModule {
	
}

 

package com.curiousby.nut.bean;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Table;

/**
 * @author baoyou E-mail:[email protected]
 * @version 2016年1月20日 下午5:33:57
 *
 * desc: ...
 */
@Table("t_user")
public class User {

	//userId,userName,password,tel,sex,description
	@Id
	private int userId;
	@Column
	private String userName;
	private String password;
	private String tel;
	private String sex;
	private String description;
	
	
	public int getUserId() {
		return userId;
	}
	public void setUserId(int userId) {
		this.userId = userId;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	
	
}

 

package com.curiousby.nut.dao;

import org.nutz.dao.impl.NutDao;
import org.nutz.ioc.loader.annotation.IocBean;
/**
 * @author baoyou E-mail:[email protected]
 * @version 2016年1月20日 下午5:36:51
 *
 * desc: ...
 */
@IocBean(name="userDao",fields={ "dataSource" })
public class UserDao extends NutDao { 

}

 

package com.curiousby.nut.service;

import java.util.HashMap;
import java.util.Map;

import org.nutz.dao.Cnd;
import org.nutz.dao.Condition;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.entity.Entity;
import org.nutz.dao.pager.Pager;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.json.Json;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.service.IdEntityService; 

import com.curiousby.common.Consts;
import com.curiousby.nut.bean.User;
import com.curiousby.nut.search.UserSearch;
 

/**
 * @author baoyou E-mail:[email protected]
 * @version 2016年1月20日 下午5:36:59
 *
 * desc: ...
 */
@IocBean(name="userService")
public class UserService extends IdEntityService{
	public static final Log log = Logs.getLog(UserService.class);
	
	@Inject("refer:userDao")
	public void setActivityDao(Dao dao){
		setDao(dao);
	}

	public String getPersonList(UserSearch us, int pageNumber) {
		Sql sql = Sqls.create(
				"select u.userId,u.userName,u.password,u.tel,u.sex,u.description from t_user u  $condition");
		Entity entity = this.dao().getEntity(User.class);
		sql.setEntity(entity).setCondition(bulidQureyCndforPersonManage(us));
		Pager pager = this.dao().createPager(pageNumber, Consts.newPageSize);
		pager.setRecordCount((int) Daos.queryCount(this.dao(), sql.getSourceSql()));
		sql.setPager(pager);
		sql.setCallback(Sqls.callback.records());
		this.dao().execute(sql);
		Map map = new HashMap();
		map.put("pageCount", (pager.getRecordCount() + Consts.newPageSize - 1) / Consts.newPageSize);
		map.put("list", sql.getList(User.class));
		System.out.println("person manage: " + map.toString());
		return Json.toJson(map);
	}
	
	private Condition bulidQureyCndforPersonManage(UserSearch us) {

		Cnd cnd = null;
		if (null != us) {
			cnd=Cnd.where("1", "=", 1);
			if (null !=us.getUserName() && !"".equals(us.getUserName())) {
				cnd.and("u.userName", "LIKE", "%" + us.getUserName() + "%");
			}
		}
		cnd.orderBy("u.userId", "desc");
		return cnd;
	}
	
}

 

package com.curiousby.nut.search;
/**
 * @author baoyou E-mail:[email protected]
 * @version 2016年1月20日 下午6:31:35
 *
 * desc: ...
 */
public class UserSearch {

	private String userName;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

 
	
}

 

package com.curiousby.nut.controller;

import javax.servlet.http.HttpServletRequest;

import org.nutz.dao.pager.Pager;
import org.nutz.ioc.annotation.InjectName;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Attr;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import com.curiousby.nut.bean.User; 
import com.curiousby.nut.search.UserSearch;
import com.curiousby.nut.service.UserService;
 
/**
 * @author baoyou E-mail:[email protected]
 * @version 2016年1月20日 下午5:37:18
 *
 * desc: ...
 */
@IocBean
@InjectName
@At("/user")
public class UserController {

	public static final Log log = Logs.getLog(UserController.class);
	private UserService userService;
	
	@At("/userList")
	@Ok("raw")
	public String getPersonList( @Param("userName") String userName, @Param("..") Pager pager,HttpServletRequest request,@Attr("currentUser") User user) {
		UserSearch us = new UserSearch();
		us.setUserName(userName);

		return userService.getPersonList(us, pager.getPageNumber());
	}
	
	
	@At("/toUserList")
	@Ok("jsp:jsp.user.userList")
	public void toPersonList(HttpServletRequest request) {
		log.error("-------------------------------");
		log.info("come to userlist");
		log.error("-------------------------------");
	}
	
	
	public UserService getUserService() {
		return userService;
	}
	@Inject("refer:userService")
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}

 

 

 

package com.curiousby.common.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionFilter;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.View;
import org.nutz.mvc.view.ServerRedirectView;

/**
 * @author baoyou E-mail:[email protected]
 * @version 2016年1月20日 下午4:50:10
 *
 * desc: ...
 */
public class CheckLoginFilter implements ActionFilter{
	private String name;
	private String path;
	
	public CheckLoginFilter(String name, String path) {
		super();
		this.name = name;
		this.path = path;
	}


	@Override
	public View match(ActionContext context) {
		HttpServletRequest request = context.getRequest();
		String uri = request.getRequestURI();
		if (uri != null 
			&& uri.contains("/user/register")
			|| uri.contains("/user/toUserList")// 本实例 没有登陆加上该uri
			|| uri.contains("/user/userList")// 本实例 没有登陆加上该uri
			|| uri.contains("/user/login") 
			) {
			return null;  
		} else {
			HttpSession session = Mvcs.getHttpSession(false);
			if (session == null || null == session.getAttribute(name)) {
				return new ServerRedirectView(path);
			}
		}
		return null;
	}

}

 

package org.nutz.mvc.view;

import org.nutz.ioc.Ioc;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.View;
import org.nutz.mvc.ViewMaker;

/**
 * @author baoyou E-mail:[email protected]
 * @version 2016年1月20日 下午4:42:49
 *
 * desc: ...
 */
public class JPEGViewMaker implements ViewMaker {
	private static final Log log = Logs.getLog(JPEGViewMaker.class);

	@Override
	public View make(Ioc ioc, String type, String value) {
		//log.debugf("Type:%s,Value:%s", type, value);
		if ("jpg".equalsIgnoreCase(type)) {
			return new JPEGView("image/jpeg");
		}
		return null;
	}

}

 

 



	
		
			close
		
		
			com.mysql.jdbc.Driver
		
		
			 jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&useLocalSessionState=true  
		
		
			root
		
		
			root
		
		
		
			500
		
		
			30
		
		
			15000
		
		
			true
		
		
			true
		
		
			select 1 from dual
		
	

	
		
			dataSource
		
	

 

 



  NutDemo
  
    index.jsp
  
  
  
    nutz
    org.nutz.mvc.NutFilter
    
      modules
      com.curiousby.nut.MainModule
    
  
  
    nutz
    /*
  
  

 

 

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="../common/taglibs.jsp"%>




个人客户






	

用户管理

用户名:

序号 用户名 密码 电话 性别 描述 操作

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。


nutz demo_第1张图片nutz demo_第2张图片nutz demo_第3张图片
 
 
 谢谢您的赞助,我会做的更好!

 

 

 

你可能感兴趣的:(nutz,demo)