Java tutorial
package com.jeans.iservlet.controller.impl; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.fasterxml.jackson.annotation.JsonView; import com.jeans.iservlet.controller.BaseController; import com.jeans.iservlet.model.AssetConstants; import com.jeans.iservlet.model.asset.Asset; import com.jeans.iservlet.model.asset.AssetChangeLog; import com.jeans.iservlet.model.asset.Hardware; import com.jeans.iservlet.model.asset.Software; import com.jeans.iservlet.service.asset.AssetService; import com.jeans.iservlet.view.ViewFactory; import com.jeans.iservlet.view.ViewFilters; import com.jeans.iservlet.view.asset.AssetChangeLogView; import com.jeans.iservlet.view.asset.AssetView; import com.jeans.iservlet.view.easyui.PropertyGrid; @Controller @RequestMapping("/acl") public class AclController extends BaseController { @Autowired private AssetService astService; /** * ?? * * @param catalog * / * @param keyword * * @return */ @RequestMapping(method = RequestMethod.POST, value = "/search") @ResponseBody @JsonView(ViewFilters.AssetList.class) public List<AssetView> searchAssets(@RequestParam byte catalog, @RequestParam String keyword) { return ViewFactory.createViewList(Asset.class, AssetView.class, astService.search(catalog, keyword, getCurrentCompany())); } /** * ? * * @param id * id * @return */ @RequestMapping(method = RequestMethod.POST, value = "/props") @ResponseBody public PropertyGrid loadProperties(@RequestParam long id) { Asset asset = astService.load(id); PropertyGrid props = new PropertyGrid(); if (null != asset) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); DecimalFormat df = new DecimalFormat(",##0.00"); props.addItem("?", null == asset.getCompany() ? null : asset.getCompany().getAlias(), ""); props.addItem("", AssetConstants.getAssetTypeName(asset.getType()), ""); props.addItem("", AssetConstants.getAssetCatalogName(asset.getCatalog()), ""); props.addItem("??", asset.getName(), ""); props.addItem("?", asset.getVendor(), ""); props.addItem("?", asset.getModelOrVersion(), ""); props.addItem("?", asset.getAssetUsage(), ""); props.addItem("", null == asset.getPurchaseTime() ? null : sdf.format(asset.getPurchaseTime()), ""); props.addItem("?", Integer.toString(asset.getQuantity()), ""); props.addItem("", df.format(asset.getCost().doubleValue()), ""); props.addItem("?", AssetConstants.getAssetStateName(asset.getState()), ""); if (asset instanceof Hardware) { props.addItem("??", ((Hardware) asset).getSn(), ""); props.addItem("??", ((Hardware) asset).getConfiguration(), ""); props.addItem("??", AssetConstants.getHardwareWarrantyName(((Hardware) asset).getWarranty()), ""); props.addItem("??", ((Hardware) asset).getLocation(), ""); props.addItem("?", ((Hardware) asset).getIp(), ""); props.addItem("??", AssetConstants.getHardwareImportanceName(((Hardware) asset).getImportance()), ""); props.addItem("", null == ((Hardware) asset).getOwner() ? null : ((Hardware) asset).getOwner().getDepartment().getAlias() + ", " + ((Hardware) asset).getOwner().getName(), ""); props.addItem("?", ((Hardware) asset).getCode(), ""); props.addItem("?", ((Hardware) asset).getFinancialCode(), ""); } else if (asset instanceof Software) { props.addItem("", AssetConstants.getSoftwareTypeName(((Software) asset).getSoftwareType()), ""); props.addItem("??", ((Software) asset).getLicense(), ""); props.addItem("??", null == ((Software) asset).getExpiredTime() ? null : sdf.format(((Software) asset).getExpiredTime()), ""); } props.addItem("", asset.getComment(), ""); } return props; } /** * ?? * * @param id * id * @return */ @RequestMapping(method = RequestMethod.POST, value = "/acls") @ResponseBody @JsonView(ViewFilters.ACLSummary.class) public List<AssetChangeLogView> loadAcls(@RequestParam long id) { return ViewFactory.createViewList(AssetChangeLog.class, AssetChangeLogView.class, astService.loadChangeLogs(id)); } }