nutz demo

简介:   package com.curiousby.nut; import org.nutz.mvc.annotation.By; import org.nutz.mvc.annotation.

 

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:curiousby@163.com
 * @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:curiousby@163.com
 * @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:curiousby@163.com
 * @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:curiousby@163.com
 * @version 2016年1月20日 下午5:36:59
 *
 * desc: ...
 */
@IocBean(name="userService")
public class UserService extends IdEntityService<User>{
	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<User> 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<String, Object> map = new HashMap<String, Object>();
		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:curiousby@163.com
 * @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:curiousby@163.com
 * @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:curiousby@163.com
 * @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:curiousby@163.com
 * @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;
	}

}

 

 

<ioc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="nutz-ioc-0.1.xsd">

	<obj name="dataSource" type="org.apache.tomcat.jdbc.pool.DataSource">
		<events>
			<depose>close</depose>
		</events>
		<field name="driverClassName">
			<str>com.mysql.jdbc.Driver</str>
		</field>
		<field name="url">
			 <str>jdbc:mysql://localhost:3306/database?useUnicode=true&amp;characterEncoding=UTF-8&amp;rewriteBatchedStatements=true&amp;useLocalSessionState=true</str>  
		</field>
		<field name="username">
			<str>root</str>
		</field>
		<field name="password">
			<str>root</str>
		</field>
		<!-- *****************************TestDataBase***************************** -->
		<field name="maxActive">
			<int>500</int>
		</field>
		<field name="initialSize">
			<int>30</int>
		</field>
		<field name="maxWait">
			<int>15000</int>
		</field>
		<field name="defaultAutoCommit">
			<bool>true</bool>
		</field>
		<field name="testOnBorrow">
			<bool>true</bool>
		</field>
		<field name="validationQuery">
			<str>select 1 from dual</str>
		</field>
	</obj>

	<obj name="dao" type="org.nutz.dao.impl.NutDao">
		<args>
			<refer>dataSource</refer>
		</args>
	</obj>
</ioc>

 

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>NutDemo</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
    <filter-name>nutz</filter-name>
    <filter-class>org.nutz.mvc.NutFilter</filter-class>
    <init-param>
      <param-name>modules</param-name>
      <param-value>com.curiousby.nut.MainModule</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>nutz</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  
</web-app>

 

 

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="../common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>个人客户</title>
<link href="../css/base.css" rel="stylesheet" type="text/css">
<link href="../css/main.css" rel="stylesheet" type="text/css">
<link href="../css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="../css/daterangepicker-bs3.css" rel="stylesheet" type="text/css">
</head>
<body>
	<div class="cnt_box">
		<h2 class="cnt_title mg_b10">用户管理</h2>
		
		<p class="searchwrap2 clearfix">
			<span class="txtblock">用户名:</span> 
			<input class="input_chs" type="text" id="userName" /> 
			
		</p>
		<table class="atdc_list mg_b10" width="100%">
			<thead>
				<tr>
					<th width="10%">序号</th>
					<th width="11%">用户名</th>
					<th width="13%">密码</th>
					<th width="18%">电话</th>
					<th width="9%">性别</th>
					<th width="19%">描述</th>
					<th width="11%">操作</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
		<div class="pd_5 fnt_14 clearfix" id="colseDiv">

        <p class="fr page pagination" id="Pagination">
        </p>
		</div>

	</div>
	<script type="text/javascript" src="../js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../js/moment.js"></script>
	<script type="text/javascript" src="../js/daterangepicker.js"></script>
	<script type="text/javascript" src="../js/common.js"></script>
	<script type="text/javascript">
	    var pageCount,tbodyHtml;
		$(function() {
			initPage(1);
		});
		function pageselectCallback(page_index, jq) {
			alert("pageselectCallback");
			view(page_index + 1);
			$(".atdc_list tbody").html(tbodyHtml);
			tbodyHtml = "";
			return false;
		}
		function initPage(pageNumber) {
			view(pageNumber);
			$("#Pagination").pagination(pageCount, {
				num_edge_entries : 1, //边缘页数
				num_display_entries : 4, //主体页数
				callback : pageselectCallback,
				items_per_page : 1
			//每页显示1项
			});
		}
		function view(pageNumber) { 
			var userName = "";
			userName = $("#userName").val();
			
			var state = "";
			state = $("input[name='state1']:checked,input[name='state2']:checked").map(function(index, elem) {
						return $(elem).val();
			}).get().join(",");

			tbodyHtml = "";
			$.ajax({
				type : "POST",
				url : "${ctx}/user/personList",
				async : false,
				data : "pageNumber=" + pageNumber + "&startTime=" + times + "&endTime=" + timee + "&phone=" + phone + "&state=" + state,
				dataType : "json",
				success : function(data) {
					pageCount = data.pageCount;
					if (("") != data.list) {
						$.each(data.list,function(i, item) {
							//alert(item.phone);
							//alert(item.createtime);
							//alert(item.password);
							//alert(item.userstate);
													
							var phone = item.phone;
							var username;
							if(null != item.username || undefined != item.username){
								username = item.username;
							}else{
								username ='';
							}
							var password = item.password;
							var userstate = item.userstate;
							var email = item.email;
							if(null != item.email || undefined != item.email){
								email = item.email;
							}else{
								email ='';
							}

							var reg = new RegExp("-","gi");
							var create;
							if (null != item.createtime || undefined != item.createtime) {
								create = item.createtime.substring(0,10).replace(reg,".");
							} else {
								create = '';
							}
					
							tbodyHtml+='<tr>'
								+'<td>'+(i+1)+'</td>'
								+'<td>'+phone+'</td>'
								+'<td>'+create+'</td>'
								+'<td>'+email+'</td>'
								+'<td>'+username+'</td>'
								+'<td>'+password+'</td>'
							if(userstate == 0){
								tbodyHtml+='<td>开通</td>'
							}
							if(userstate == 1){
								tbodyHtml+='<td>停用</td>'
							}
							tbodyHtml+='<td class="alignleft"><a href="${ctx}/user/toPersonView?phone='+item.phone+'">查看</a><a href="${ctx}/user/toPersonEdit?phone='+item.phone+'">编辑</a></td>'
							tbodyHtml+="</tr>"
							//alert(tbodyHtml);
						
						});
					} else {
							tbodyHtml += "<tr><td colspan='9'>未查询到符合条件的个人客户</td></tr>";
							$("#colseDiv").hide();
					}
					$(".atdc_list tbody").html(tbodyHtml);
			   }

	      });
	}
		
	</script>
</body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

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



 
 
 谢谢您的赞助,我会做的更好!

 

 

 

目录
相关文章
|
3月前
|
SQL JSON 前端开发
SpringBootWeb案例-1(二)
SpringBootWeb案例-1(二)
29 0
|
3月前
|
JSON Java 对象存储
SpringBootWeb案例-2(二)
SpringBootWeb案例-2(二)
20 0
|
3月前
|
JSON 前端开发 Java
SpringBootWeb案例-1(一)
SpringBootWeb案例-1(一)
36 0
|
3月前
|
存储 JSON 前端开发
SpringBootWeb案例-2(一)
SpringBootWeb案例-2(一)
47 0
|
6月前
|
Java 对象存储 Spring
Javaweb之SpringBootWeb案例之 @ConfigurationProperties的详细解析
Javaweb之SpringBootWeb案例之 @ConfigurationProperties的详细解析
143 0
Javaweb之SpringBootWeb案例之 @ConfigurationProperties的详细解析
|
6月前
|
前端开发 Java 数据库连接
Javaweb之SpringBootWeb案例的详细解析
Javaweb之SpringBootWeb案例的详细解析
66 0
|
Java Spring 容器
Springboot中的@Import注解~
Springboot中的@Import注解~
|
前端开发 Java Maven
SpringBoot项目中WEB与Controller的联系--【JSB系列之009】
SpringBoot项目中WEB与Controller的联系--【JSB系列之009】
|
Java Maven
springboot使用freemarker的入门Demo
1.创建一个maven web项目 2.添加所需要的依赖
|
Java 应用服务中间件 Apache
webservice开发不得不知的细节,Error creating bean with name ‘org.apache.cxf.jaxws.EndpointImpl---1987203924‘
webservice开发不得不知的细节,Error creating bean with name ‘org.apache.cxf.jaxws.EndpointImpl---1987203924‘
161 0