项目

JSP

`事件处理
function doSearch(){

        alert($('#start').val());
        $("#customerList").datagrid('load',{
            findName:$('#findName').val(),
            sex:$('#sex').val(),
            findPhone:$('#findPhone').val(),
            start:$("#start").val,
            end:$("#end").val
        })
    }
    function deleteid(){
        var ids = getSelectionsIds();
        if(ids.length == 0){
            $.messager.alert('提示','未选中用户!');
            return ;
        }
        $.messager.confirm('确认','确定删除ID为 '+ids+' 的用户吗?',function(r){
            if (r){
                var params = {"ids":ids};
                $.post("/banbiShop/manager/customer/delete",params, function(data){
                    if(data =='ok'){
                        $.messager.alert('提示','删除用户成功!',undefined,function(){
                            $("#customerList").datagrid("reload");
                        });
                    }
                });
            }
        });
    }
    function getSelectionsIds(){
        var customerList = $("#customerList");//表格显示的
        var sels = customerList.datagrid("getSelections");//选择的
        var ids = [];
        for(var i in sels){
            ids.push(sels[i].id);
        }
        ids = ids.join(",");
        return ids;
    } 

  **控制层**

``@Controller
@RequestMapping("/manager/customer")
public class CustomerController {
private Logger log=Logger.getLogger(this.getClass().getName());
@Autowired
private CustomerService custService;

@RequestMapping("getCust")
@ResponseBody
public TbCustomer geTbCustomerById(Long id){
TbCustomer customer = custService.getTbCustomerById(id);
return customer;
}

@RequestMapping("listCustomer")
@ResponseBody
public EasyUiDateGridResult listCustomer(int page,int rows,String findName,String sex,String findPhone,Date start,Date end){
custService.getAllCustomer(page, rows, findName, sex, findPhone, start, end);
return null;
}
@RequestMapping("delete")
@ResponseBody
public String delete(Long[]  ids){
System.out.println("-------------"+ids);
ArrayList<Long> list = new ArrayList<Long>();
for(int i=0;i<ids.length;i++){
list.add(ids[i]);
}
int i = custService.deleteByid(list);
if(i>0){
return "ok";
}
return "err";
}
}

@Service
public class CustomerServiceImpl implements CustomerService {

//Autowired自动装配,ioc容器中如果有类型匹配的对象,如果只有一个,则直接装配,就是按类型装配,
//如果有多个,则按名称装配,如果名称名与属性名不一致则使用@Qualifier("name")
@Autowired
private TbCustomerMapper  custMapper;
@Autowired
private TbChildrenMapper childMapper;

@Override
public TbCustomer getTbCustomerById(Long id) {
// TODO Auto-generated method stub
TbCustomer customer = custMapper.selectByPrimaryKey(id);
return customer;
}

@Override
public List<TbCustomer> findCustomerByName(String name) {
TbCustomerExample customerEx = new TbCustomerExample();
Criteria criteria = customerEx.createCriteria();
criteria.andRealnameLike(name);
List<TbCustomer> list = custMapper.selectByExample(customerEx);
return list;
}

@Override
public EasyUiDateGridResult getAllCustomer(int page, int rows) {
TbCustomerExample customerEx = new TbCustomerExample();
PageHelper helper = new PageHelper();
helper.startPage(page,rows);
List<TbCustomer> list = custMapper.selectByExample(customerEx);
PageInfo<TbCustomer> info = new PageInfo<TbCustomer>(list);
EasyUiDateGridResult result=new EasyUiDateGridResult();
result.setRows(list);
result.setTotal(info.getTotal());
return result;

}

@Override
public EasyUiDateGridResult getAllCustomer(int page, int rows, String findName) {
TbCustomerExample customerEx = new TbCustomerExample();
if(findName!=null){
Criteria crt1 = customerEx.createCriteria();
Criteria crt2 = customerEx.createCriteria();
crt1.andUsernameLike("%"+findName+"%");
crt2.andRealnameLike("%"+findName+"%");
customerEx.or(crt2);
}
PageHelper helper = new PageHelper();
helper.startPage(page,rows);
List<TbCustomer> list = custMapper.selectByExample(customerEx);
PageInfo<TbCustomer> info = new PageInfo<TbCustomer>(list);
EasyUiDateGridResult result=new EasyUiDateGridResult();
result.setRows(list);
result.setTotal(info.getTotal());
return result;
}

@Override
public EasyUiDateGridResult getAllCustomer(int page, int rows, String findName, String sex) {
TbCustomerExample customerEx = new TbCustomerExample();
if(findName!=null && !findName.equals("")){
Criteria crt1 = customerEx.createCriteria();
Criteria crt2 = customerEx.createCriteria();
crt1.andUsernameLike("%"+findName+"%");
crt2.andRealnameLike("%"+findName+"%");
customerEx.or(crt2);
}
if(sex!=null && !sex.equals("")){
Criteria crt1 = customerEx.createCriteria();
crt1.andSexEqualTo(sex);
}
if(sex!=null && !sex.equals("") && findName!=null && !findName.equals("")){
Criteria crt1 = customerEx.createCriteria();
Criteria crt2 = customerEx.createCriteria();
crt1.andUsernameLike("%"+findName+"%").andSexEqualTo(sex);
crt2.andRealnameLike("%"+findName+"%").andSexEqualTo(sex);
customerEx.or(crt2);
}
PageHelper helper = new PageHelper();
helper.startPage(page,rows);
List<TbCustomer> list = custMapper.selectByExample(customerEx);
PageInfo<TbCustomer> info = new PageInfo<TbCustomer>(list);
EasyUiDateGridResult result=new EasyUiDateGridResult();
result.setRows(list);
result.setTotal(info.getTotal());
return result;
}
@Override
public int deleteByid(List<Long> ids) {
//用户实例
TbCustomerExample customerEx = new TbCustomerExample();
//创建标准
Criteria criteria = customerEx.createCriteria();
//添加ids到标准
Criteria in=criteria.andIdIn(ids);
//TbCustomerMapper里面的deleteByExample类型为Example
int byExample = custMapper.deleteByExample(customerEx);
return byExample;
}

@Override
public EasyUiDateGridResult getAllCustomer(int page, int rows, String findName, String sex, String findPhone,
Date start, Date end) {
System.out.println("时间-------------"+findName+sex+findPhone+"时间"+start+"后"+end);
TbCustomerExample customerEx = new TbCustomerExample();
Criteria crt1 = customerEx.createCriteria();
Criteria crt2 = customerEx.createCriteria();
if(findName!=null && !findName.equals("")){
crt1.andUsernameLike("%"+findName+"%");
crt2.andRealnameLike("%"+findName+"%");
customerEx.or(crt2);
}
if(findPhone!=null && !findPhone.equals("")){
crt1.andPhoneEqualTo(findPhone);
crt2.andPhoneEqualTo(findPhone);
}
if(sex!=null && !sex.equals("")){
crt1.andSexEqualTo(sex);
crt2.andSexEqualTo(sex);
}
if(start!=null && !start.equals("") && end!=null && !end.equals("")){
crt1.andCreatedBetween(start, end);
crt2.andCreatedBetween(start, end);
}
if(start!=null &&  end==null ){
crt1.andCreatedGreaterThanOrEqualTo(start);
crt2.andCreatedGreaterThanOrEqualTo(start);
}
if(start==null &&  end!=null ){
crt1.andCreatedLessThanOrEqualTo(end);
crt2.andCreatedLessThanOrEqualTo(end);
}
return null;
}
``
**转换器---String-to -Date**
public class StringControllerDate implements Converter<String, Date> {

@Override
public Date convert(String org) {
Date date;
if(org==null && org.equals("")){
return null;
}
try {
date = new java.text.SimpleDateFormat("yyyy-MM-dd").parse(org);
return date;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}

}

SpringMVC—-xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

<context:component-scan base-package="com.issCollege.banbiShop.controller"></context:component-scan>
<!-- 注解驱动 -->
<mvc:annotation-driven conversion-service="formattingConversion">
</mvc:annotation-driven>
<!-- 视图解析 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>
<!-- 分段解析 -->
<bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="10485760"></property>
    <property name="defaultEncoding" value="UTF-8"></property>
</bean>
<!-- 转换器 -->
<bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean" id="formattingConversion">
<property name="converters">
<set>
<bean class="com.issCollege.banbiShop.converter.StringControllerDate"></bean>
</set>
</property>
</bean>
<!-- 静态资源 -->
<mvc:resources location="/WEB-INF/css/" mapping="/css/**"></mvc:resources>
<mvc:resources location="/WEB-INF/js/" mapping="/js/**"></mvc:resources>
<mvc:resources location="/WEB-INF/img/" mapping="/img/**"></mvc:resources>
<mvc:resources location="/WEB-INF/tools/" mapping="/tools/**"></mvc:resources>
</beans>

“`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值