基于javaweb+mysql的ssm+maven物流后台管理系统(java+mysql+ssm+jsp)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSM+Maven物流后台管理系统(java+mysql+ssm+jsp)
emp1 123456
emp2 123456
emp3 123456
PageInfo<Employee> pageInfo=new PageInfo<>(list);
//把分页对象存入域中
model.addAttribute("pageInfo",pageInfo);
return "admin-list";
}
//执行登录操作
@RequestMapping("/login")
@ResponseBody
public String login(String username, String password, String code, String online, HttpSession session, HttpServletResponse response){
//验证码判断
String sysCode = (String) session.getAttribute("CODE_SESSION");
if(!sysCode.equalsIgnoreCase(code)){
return "error";
}
Employee employee = employeeService.getByUserName(username);
if(employee!=null){//通过用户名查到对象
//判断密码是否正确
if(employee.getPassword().equals(password)){//密码正确
//把用户信息存到域中
session.setAttribute("USER_SESSION",employee);
if("on".equals(online)){//用户勾了记住登录
addCookie(response,employee.getUsername());
}
return "true";
}
}
return "false";
}
//添加Cookie
private void addCookie(HttpServletResponse response,String username){
Cookie cookie=new Cookie("username",username);
cookie.setPath("/");
cookie.setMaxAge(60*60*24*7);
response.addCookie(cookie);
}
//跳转到登录页面
@RequestMapping("/tologin")
public String tologin(){
return "login";
}
@Controller
@RequestMapping("/carorder")
public class CarOrderController {
@Autowired
private CarOrderService carOrderService;
@RequestMapping("/list")
public String list(Model model, HttpSession session){
List<CarOrder> list = carOrderService.list(session);
model.addAttribute("list",list);
return "store-in";
}
}
public class Uploader {
private HttpServletRequest request = null;
private Map<String, Object> conf = null;
public Uploader(HttpServletRequest request, Map<String, Object> conf) {
this.request = request;
this.conf = conf;
}
public final State doExec() {
String filedName = (String) this.conf.get("fieldName");
State state = null;
if ("true".equals(this.conf.get("isBase64"))) {
state = Base64Uploader.save(this.request.getParameter(filedName),
this.conf);
} else {
state = BinaryUploader.save(this.request, this.conf);
}
return state;
}
}
return "false";
}
//添加Cookie
private void addCookie(HttpServletResponse response,String username){
Cookie cookie=new Cookie("username",username);
cookie.setPath("/");
cookie.setMaxAge(60*60*24*7);
response.addCookie(cookie);
}
//跳转到登录页面
@RequestMapping("/tologin")
public String tologin(){
return "login";
}
//切换帐号
@RequestMapping("/change")
public String change(HttpSession session){
//把刚才登录的信息从session中的移除
session.removeAttribute("USER_SESSION");
//跳转到登录页面
return "login";
}
@RequestMapping("/logout")
public String logout(HttpSession session,HttpServletResponse response){
//把刚才登录的信息从session中的移除
session.removeAttribute("USER_SESSION");
//清除Cookie
Cookie cookie=new Cookie("username",null);
cookie.setPath("/");
cookie.setMaxAge(0);//存活时间为0秒,相当于删除
response.addCookie(cookie);
//跳转到登录页面
return "login";
}
@RequestMapping("/tosave")
public String tosave(){
return "admin-add";
}
@RequestMapping("/save")
@Controller
@RequestMapping("/store")
public class StoreController {
@Autowired
private StoreService storeService;
@Autowired
private AreaService areaService;
@RequestMapping("/listJSON")
@ResponseBody
public String listJSON(){
List<Store> list = storeService.list();
//把集合转成JSON格式的字符返回给前台
return JSON.toJSONString(list);
}
@RequestMapping("/list")
public String list(Model model){
List<Store> list = storeService.list();
model.addAttribute("list",list);
return "store-list";
}
@RequestMapping("/tosave")
public String tosave(Model model){
//查询添加页面中所需要的区域列表
List<Area> list = areaService.list();
model.addAttribute("list",list);
return "store-add";
}
@RequestMapping("/save")
@ResponseBody
public String save(Store store){
try {
storeService.save(store);
return "true";
} catch (Exception e) {
e.printStackTrace();
return "false";
}
}
@RequestMapping("outStore")
@ResponseBody
// 将认证码显示到图象中
g.setColor(new Color(50 + random.nextInt(110), 20 + random.nextInt(110), 30 + random.nextInt(110)));
//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成
g.drawString(str, 18 * i +13, 27); //文字间距*i+距离左边距,上边距
}
HttpSession session=request.getSession();
// 将认证码存入SESSION
session.setAttribute("CODE_SESSION", code);
// 图象生效
g.dispose();
// 输出图象到页面
try {
ImageIO.write(image, "JPEG", response.getOutputStream());
//加上下面代码,运行时才不会出现java.lang.IllegalStateException: getOutputStream() has already been called ..........等异常
response.getOutputStream().flush();
response.getOutputStream().close();
response.flushBuffer();
} catch (IOException e) {
e.printStackTrace();
}
}
//获取随机颜色
private static Color getRandColor(int fc,int bc){
Random random = new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r,g,b);
}
}
public class ActionEnter {
private HttpServletRequest request = null;
private String rootPath = null;
private String contextPath = null;
model.addAttribute("list",list);
return "car-travel";
}
@RequestMapping("/updateTravel")
@ResponseBody
public String updateTravel(int cid){
try {
carService.updateByCidTravel(cid);
return "true";
} catch (Exception e) {
e.printStackTrace();
return "false";
}
}
@RequestMapping("/tosave")
public String tosave(Model model){
//查询所有门店
List<Store> list = storeService.list();
model.addAttribute("list",list);
return "car-add";
}
@RequestMapping("/save")
@ResponseBody
public String save(Car car){
try {
carService.save(car);
return "true";
} catch (Exception e) {
e.printStackTrace();
return "false";
}
}
}
public class LoginInterceptor implements HandlerInterceptor {
@Autowired
private EmployeeService employeeService;
return orderInfoMapper.listByStats(stats);
}
@Override
public int updateReceivere(String onum, HttpSession session) {
//获取当前登录者
Employee employee=(Employee)session.getAttribute("USER_SESSION");
//先查要修改的订单对象
OrderInfo orderInfo = orderInfoMapper.getByOnum(onum);
//把状态改为1
orderInfo.setState(1);
//更新到数据库中
orderInfoMapper.update(orderInfo);
//添加一个揽件记录
ReceivereCode receivereCode=new ReceivereCode(0,0,new Date(),orderInfo.getOnum(),employee.getEid());
receivereCodeMapper.save(receivereCode);
//添加线路记录
OrderRoute orderRoute=new OrderRoute(0,0,new Date(),orderInfo.getOnum(),employee.getStore().getSid());
orderRouteMapper.save(orderRoute);
return 1;
}
@Override
public int updateSend(String onum, HttpSession session) {
//获取当前登录者
Employee employee=(Employee)session.getAttribute("USER_SESSION");
//先查要修改的订单对象
OrderInfo orderInfo = orderInfoMapper.getByOnum(onum);
//把状态改为1
orderInfo.setState(2);
//更新到数据库中
orderInfoMapper.update(orderInfo);
//添加线路记录
OrderRoute orderRoute=new OrderRoute(0,0,new Date(),orderInfo.getOnum(),employee.getStore().getSid());
orderRouteMapper.save(orderRoute);
//派件记录表添加
SendRecode sendRecode=new SendRecode(0,employee.getEid(),0,new Date(),orderInfo.getOnum());
sendRecodeMapper.save(sendRecode);
return 1;
}
//跳转到登录页面
return "login";
}
@RequestMapping("/logout")
public String logout(HttpSession session,HttpServletResponse response){
//把刚才登录的信息从session中的移除
session.removeAttribute("USER_SESSION");
//清除Cookie
Cookie cookie=new Cookie("username",null);
cookie.setPath("/");
cookie.setMaxAge(0);//存活时间为0秒,相当于删除
response.addCookie(cookie);
//跳转到登录页面
return "login";
}
@RequestMapping("/tosave")
public String tosave(){
return "admin-add";
}
@RequestMapping("/save")
@ResponseBody
public String save(Employee employee){
try {
employeeService.save(employee);
return "true";
} catch (Exception e) {
e.printStackTrace();
return "false";
}
}
}
Map<String, Object> conf = null;
switch ( actionCode ) {
case ActionMap.CONFIG:
return this.configManager.getAllConfig().toString();
case ActionMap.UPLOAD_IMAGE:
case ActionMap.UPLOAD_SCRAWL:
case ActionMap.UPLOAD_VIDEO:
case ActionMap.UPLOAD_FILE:
conf = this.configManager.getConfig( actionCode );
state = new Uploader( request, conf ).doExec();
break;
case ActionMap.CATCH_IMAGE:
conf = configManager.getConfig( actionCode );
String[] list = this.request.getParameterValues( (String)conf.get( "fieldName" ) );
state = new ImageHunter( conf ).capture( list );
break;
case ActionMap.LIST_IMAGE:
case ActionMap.LIST_FILE:
conf = configManager.getConfig( actionCode );
int start = this.getStartIndex();
state = new FileManager( conf ).listFile( start );
break;
}
return state.toJSONString();
}
public int getStartIndex () {
String start = this.request.getParameter( "start" );
try {
return Integer.parseInt( start );
} catch ( Exception e ) {
return 0;
}
}
/**
* callback参数验证
*/
public boolean validCallbackName ( String name ) {
if ( name.matches( "^[a-zA-Z_]+[\\w0-9_]*$" ) ) {
return true;
}
if (!fileStream.isFormField())
break;
fileStream = null;
}
if (fileStream == null) {
return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA);
}
String savePath = (String) conf.get("savePath");
String originFileName = fileStream.getName();
String suffix = FileType.getSuffixByFilename(originFileName);
originFileName = originFileName.substring(0,
originFileName.length() - suffix.length());
savePath = savePath + suffix;
long maxSize = ((Long) conf.get("maxSize")).longValue();
if (!validType(suffix, (String[]) conf.get("allowFiles"))) {
return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
}
savePath = PathFormat.parse(savePath, originFileName);
String physicalPath = (String) conf.get("rootPath") + savePath;
InputStream is = fileStream.openStream();
State storageState = StorageManager.saveFileByInputStream(is,
physicalPath, maxSize);
is.close();
if (storageState.isSuccess()) {
storageState.putInfo("url", PathFormat.format(savePath));
storageState.putInfo("type", suffix);
storageState.putInfo("original", originFileName + suffix);
}
return storageState;
} catch (FileUploadException e) {
return new BaseState(false, AppInfo.PARSE_REQUEST_ERROR);
} catch (IOException e) {
}
return new BaseState(false, AppInfo.IO_ERROR);
}
private static boolean validType(String type, String[] allowTypes) {
public int getStartIndex () {
String start = this.request.getParameter( "start" );
try {
return Integer.parseInt( start );
} catch ( Exception e ) {
return 0;
}
}
/**
* callback参数验证
*/
public boolean validCallbackName ( String name ) {
if ( name.matches( "^[a-zA-Z_]+[\\w0-9_]*$" ) ) {
return true;
}
return false;
}
}
if (fileStream == null) {
return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA);
}
String savePath = (String) conf.get("savePath");
String originFileName = fileStream.getName();
String suffix = FileType.getSuffixByFilename(originFileName);
originFileName = originFileName.substring(0,
originFileName.length() - suffix.length());
savePath = savePath + suffix;
long maxSize = ((Long) conf.get("maxSize")).longValue();
if (!validType(suffix, (String[]) conf.get("allowFiles"))) {
return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
}
savePath = PathFormat.parse(savePath, originFileName);
String physicalPath = (String) conf.get("rootPath") + savePath;
InputStream is = fileStream.openStream();
State storageState = StorageManager.saveFileByInputStream(is,
physicalPath, maxSize);
is.close();
if (storageState.isSuccess()) {
storageState.putInfo("url", PathFormat.format(savePath));
storageState.putInfo("type", suffix);
storageState.putInfo("original", originFileName + suffix);
}
return storageState;
} catch (FileUploadException e) {
return new BaseState(false, AppInfo.PARSE_REQUEST_ERROR);
} catch (IOException e) {
}
return new BaseState(false, AppInfo.IO_ERROR);
}
private static boolean validType(String type, String[] allowTypes) {
List<String> list = Arrays.asList(allowTypes);
@RequestMapping("/orderinfo")
@Controller
public class OrderInfoController {
@Autowired
private OrderInfoService orderInfoService;
@RequestMapping("/save")
@ResponseBody
public String save(OrderInfo orderInfo, HttpSession session){
try {
orderInfoService.save(orderInfo,session);
return "true";
} catch (Exception e) {
e.printStackTrace();
return "false";
}
}
@RequestMapping("/tosave")
public String tosave(){
return "order-add";
}
@RequestMapping("/list")
public String listReceivere(Model model){
List<OrderInfo> list = orderInfoService.listByStats(0);
model.addAttribute("list",list);
return "order-list";
}
@RequestMapping("/sendlist")
public String sendlist(Model model){
List<OrderInfo> list = orderInfoService.listByStats(1);
model.addAttribute("list",list);
return "order-send";
}
@RequestMapping("/updateReceivere")
@ResponseBody
public String updateReceivere(String onum, HttpSession session){
try {
private ReceivereCodeMapper receivereCodeMapper;
@Autowired
private OrderRouteMapper orderRouteMapper;
@Autowired
private SendRecodeMapper sendRecodeMapper;
@Override
public int save(OrderInfo orderInfo, HttpSession session) {
//获取当前登录者
Employee employee=(Employee)session.getAttribute("USER_SESSION");
orderInfo.setEid(employee.getEid());
orderInfo.setState(0);//代表未揽件
orderInfo.setOnum(UUIDUtils.getUUID());
orderInfo.setCreatetime(new Date());
return orderInfoMapper.save(orderInfo);
}
@Override
public List<OrderInfo> listByStats(int stats) {
return orderInfoMapper.listByStats(stats);
}
@Override
public int updateReceivere(String onum, HttpSession session) {
//获取当前登录者
Employee employee=(Employee)session.getAttribute("USER_SESSION");
//先查要修改的订单对象
OrderInfo orderInfo = orderInfoMapper.getByOnum(onum);
//把状态改为1
orderInfo.setState(1);
//更新到数据库中
orderInfoMapper.update(orderInfo);
//添加一个揽件记录
ReceivereCode receivereCode=new ReceivereCode(0,0,new Date(),orderInfo.getOnum(),employee.getEid());
receivereCodeMapper.save(receivereCode);
//添加线路记录
OrderRoute orderRoute=new OrderRoute(0,0,new Date(),orderInfo.getOnum(),employee.getStore().getSid());
orderRouteMapper.save(orderRoute);
return 1;
}
@Override
public int updateSend(String onum, HttpSession session) {
//获取当前登录者
Employee employee=(Employee)session.getAttribute("USER_SESSION");
//先查要修改的订单对象
OrderInfo orderInfo = orderInfoMapper.getByOnum(onum);
//把状态改为1
orderInfo.setState(2);
//更新到数据库中
orderInfoMapper.update(orderInfo);
//添加线路记录
String callbackName = this.request.getParameter("callback");
if ( callbackName != null ) {
if ( !validCallbackName( callbackName ) ) {
return new BaseState( false, AppInfo.ILLEGAL ).toJSONString();
}
return callbackName+"("+this.invoke()+");";
} else {
return this.invoke();
}
}
public String invoke() {
if ( actionType == null || !ActionMap.mapping.containsKey( actionType ) ) {
return new BaseState( false, AppInfo.INVALID_ACTION ).toJSONString();
}
if ( this.configManager == null || !this.configManager.valid() ) {
return new BaseState( false, AppInfo.CONFIG_ERROR ).toJSONString();
}
State state = null;
int actionCode = ActionMap.getType( this.actionType );
Map<String, Object> conf = null;
switch ( actionCode ) {
case ActionMap.CONFIG:
return this.configManager.getAllConfig().toString();
case ActionMap.UPLOAD_IMAGE:
case ActionMap.UPLOAD_SCRAWL:
case ActionMap.UPLOAD_VIDEO:
case ActionMap.UPLOAD_FILE:
conf = this.configManager.getConfig( actionCode );
state = new Uploader( request, conf ).doExec();
break;
case ActionMap.CATCH_IMAGE:
conf = configManager.getConfig( actionCode );
String[] list = this.request.getParameterValues( (String)conf.get( "fieldName" ) );
state = new ImageHunter( conf ).capture( list );
return "false";
}
//添加Cookie
private void addCookie(HttpServletResponse response,String username){
Cookie cookie=new Cookie("username",username);
cookie.setPath("/");
cookie.setMaxAge(60*60*24*7);
response.addCookie(cookie);
}
//跳转到登录页面
@RequestMapping("/tologin")
public String tologin(){
return "login";
}
//切换帐号
@RequestMapping("/change")
public String change(HttpSession session){
//把刚才登录的信息从session中的移除
session.removeAttribute("USER_SESSION");
//跳转到登录页面
return "login";
}
@RequestMapping("/logout")
public String logout(HttpSession session,HttpServletResponse response){
//把刚才登录的信息从session中的移除
session.removeAttribute("USER_SESSION");
//清除Cookie
Cookie cookie=new Cookie("username",null);
cookie.setPath("/");
cookie.setMaxAge(0);//存活时间为0秒,相当于删除
response.addCookie(cookie);
//跳转到登录页面
return "login";
}
@RequestMapping("/tosave")
}
}
@Controller
@RequestMapping("/store")
public class StoreController {
@Autowired
private StoreService storeService;
@Autowired
private AreaService areaService;
@RequestMapping("/listJSON")
@ResponseBody
public String listJSON(){
List<Store> list = storeService.list();
//把集合转成JSON格式的字符返回给前台
return JSON.toJSONString(list);
}
@RequestMapping("/list")
public String list(Model model){
List<Store> list = storeService.list();
model.addAttribute("list",list);
return "store-list";
}
@RequestMapping("/tosave")
public String tosave(Model model){
//查询添加页面中所需要的区域列表
List<Area> list = areaService.list();
model.addAttribute("list",list);
return "store-add";
}