java物流项目有哪些模块_物流项目(四)

1. 模块管理

即权限管理

1.1 查询

作业

1.2 新增

1.2.1 pojo

修改TreeNode:新增权限时需要使用ztree显示上级

//ztree的bean对象

public class TreeNode {

private String id;

private String pId;

private String name;

private Boolean open=true;

private Boolean checked;

private Integer layerNum;

... ...

}

1.2.2 mapper

修改ModuleMapper.xml

select m.module_id id,m.parent_id pId,m.name,'false' open,layer_num+1 layerNum from module_p m

修改ModuleMapper

//查询所有的权限

List listModuleOfTreeBean();

1.2.3 service

@Override

public List listModuleOfTreeBean() throws Exception {

return modulePMapper.listModuleOfTreeBean();

}

1.2.4 controller

@RequestMapping("/tocreate")

public String tocreate(Model model) throws Exception {

return "sysadmin/module/jModuleCreate";

}

//查询zTree的数据

@RequestMapping("/listModuleOfTreeBean")

@ResponseBody

public List listModuleOfTreeBean(Model model) throws Exception {

List treeNodes = moduleService.listModuleOfTreeBean();

return treeNodes;

}

1.2.5 jsp

修改jModuleCreate.jsp

var zTreeObj;

var setting = {

check: {

enable: true, //显示checkbox/radio

chkStyle: "radio",

radioType: "all"

},

data: {

simpleData: {

enable: true//使用简单的数据模式

}

},

callback: {

onClick: onClick,

onCheck: onCheck

}

};

//树的节点数据

/* var zNodes = [

{"id":1, "pId":0, "name":"系统管理",open:true},

{"id":11, "pId":1, "name":"用户管理",open:true},

{"id":12, "pId":1, "name":"角色管理",open:true},

{"id":111, "pId":11, "name":"新增",open:true,checked:true }

];*/

$(function(){

$.ajax({

url:'${ctx}/module/listModuleOfTreeBean',

type:'post',

success:initzTree

});

});

function onClick(e, treeId, treeNode) {

zTreeObj.checkNode(treeNode, !treeNode.checked, null, true);

return false;

}

function onCheck(e, treeId, treeNode) {

//选中的节点的名字显示到父级框

$("#moduleSel").val(treeNode.name);

//选中的节点的id赋值到隐藏框

$("#parentId").val(treeNode.id);

//选中的节点的layerNum赋值到层级

$("#layerNum").val(treeNode.layerNum);

}

function showMenu() {

var moduleObj = $("#moduleSel");

var moduleOffset = $("#moduleSel").offset();

//设置zTree显示的位置

$("#menuContent").css({left:moduleOffset.left + "px", top:moduleOffset.top + moduleObj.outerHeight() +

"px"}).slideDown("fast");

$("body").bind("mousedown", onBodyDown);

}

function onBodyDown(event) {

if (!(event.target.id == "menuBtn" || event.target.id == "moduleSel" || event.target.id == "menuContent" ||

$(event.target).parents("#menuContent").length>0)) {

hideMenu();

}

}

function hideMenu() {

$("#menuContent").fadeOut("fast");

$("body").unbind("mousedown", onBodyDown);

}

function initzTree(zNodes){

/**

obj:显示数的heml元素

setting:树的配置信息

zNodes:树的节点数据

*/

zTreeObj = $.fn.zTree.init($("#jTree"), setting, zNodes);

}

... ...

父级:

 选择父级菜单

... ...

1.3 修改

1.3.1 mapper

修改ModuleMapper.xml:修改权限时回显上级权限

select m.module_id id,m.parent_id pId,m.name,'false' checked,layer_num+1 layerNum from module_p m where m.MODULE_ID!=#{parentId}

union

select m.module_id id,m.parent_id pId,m.name,'true' checked,layer_num+1 layerNum from module_p m where m.MODULE_ID=#{parentId}

修改ModuleMapper

//通过parentId查询所有的权限,并把查询结果装到TreeBean里,并支持回显

List listModuleOfTreeBeanByParentId(String parentId);

1.3.2 service

1.3.3 controller

1.4 明细

作业

1.5 删除

作业

2. 清空缓存

2.1 修改realm

修改自定义realm

//清除缓存

public void clearCached() {

PrincipalCollection principals = SecurityUtils.getSubject().getPrincipals();

super.clearCache(principals);

}

2.2 修改controller

修改ModuleController

@RequestMapping("/module")

public String module(String[] moduleIds,String roleId)throws Exception{

roleModuleService.addRoleModule(moduleIds,roleId);

customRealm.clearCached();

return "redirect:/role/list";

}

修改RoleController

@RequestMapping("/role")

public String role(String[] roleIds,String userId)throws Exception{

roleUserService.addRoleUser(roleIds,userId);

customRealm.clearCached();

return "redirect:/user/list";

}

3. 退出

修改applicationContext-shiro.xml

/user/logout = logout

修改/home/title.jsp

function logout(){

return formSubmit("${ctx}/user/logout", "_top");

}

1. 什么是JavaMail

JavaMail是提供给开发人员在应用程序中实现邮件发送和接收功能而提供的一套标准开发类库,支持常用的邮件协议,如SMTP、POP3、IMAP,开发人员使用JavaMail编写邮件程序时,无需考虑底层的通信细节(Socket),JavaMail也提供了能够创建出各种复杂MIME格式的邮件内容的API。使用JavaMail,我们可以实现类似OutLook、FoxMail的软件。

2. JavaMail的基本概述

2.1 邮件开发的相关协议

Ø SMTP 的全称是“Simple Mail Transfer Protocol”,即简单邮件传输协议(25号端口)。

Ø POP3是Post Office Protocol 3的简称,即邮局协议的第3个版本,是TCP/IP协议族中的一员(默认端口是110)。

Ø IMAP全称是Internet Mail Access Protocol,即交互式邮件存取协议,它是跟POP3类似邮件访问标准协议之一

2.2 IMAP和POP3有什么区别?

2.3 POP3/IMAP、SMTP之间的区别和联系

简单地说,SMTP管“发”,POP3/IMAP管“收”。

举个例子,你坐在电脑边用mail client写完邮件,点击‘发送’。这时你的mail client会发消息给邮件服务器上的SMTP service。这时有两种情况:

1. 如果邮件的收信人也是处于同一个domain,比如从给163的邮箱,SMTP service只需要转给local的POP3 Service即可

2. 如果邮件收信人是另外的domain,比如

其实一般每个提供电子邮件服务的网站都有自己的SMTP和POP服务器地址,在你登录你的电子邮件网站时仔细找找肯定能发现它们,如果找不到还可以查看一下网站的“帮助”。

2.4 邮件发送的过程

3. JavaMail的准备工作

3.1 申请邮箱

3.2 引入JavaMail 依赖

freight_web

javax.mail

mail

1.4.4

3.3 测试

package com.sxt.test;

import org.junit.Test;

import javax.mail.Address;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

import java.util.Properties;

public class JavaMailTest {

@Test

public void test() throws Exception {

//设置发送者的配置信息

Properties properties = new Properties();

//发送者的协议

properties.put("mail.smtp.host","smtp.126.com");

properties.put("mail.smtp.auth","true");

Session session = Session.getInstance(properties);

//设置调试信息在控制台打印出来

session.setDebug(true);

//信息体

MimeMessage message = new MimeMessage(session);

//发信者

Address address = new InternetAddress("guangweima@126.com");

message.setFrom(address);

//收信者

Address toAddress = new InternetAddress("361499689@qq.com");

/**

* 设置收件人地址(可以增加多个收件人、抄送、密送)

* MimeMessage.RecipientType.TO:发送

* MimeMessage.RecipientType.CC:抄送

* MimeMessage.RecipientType.BCC:密送

*/

message.setRecipient(MimeMessage.RecipientType.TO,toAddress);

//主题

message.setSubject("米西米西");

//正文

message.setText("哈喽啊,饭已ok啦,下来米西吧!!!");

message.saveChanges();

//发送邮件

Transport transport = session.getTransport("smtp");

//登录

transport.connect("guangweima@126.com", "361499beyond");

transport.sendMessage(message, message.getAllRecipients());

transport.close();

}

}

3.4 JavaMail的三个核心类

3.5 测试二

package com.sxt.test;

import org.junit.Test;

import javax.mail.Address;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

import java.util.Properties;

public class JavaMailTest {

//发件人地址

public static String senderAddress = "guangweima@126.com";

//收件人地址

public static String recipientAddress = "361499689@qq.com";

//发件人账户名

public static String senderAccount = "guangweima@126.com";

//发件人账户密码

public static String senderPassword = "xxxxxxxxx";

@Test

public void test2() throws Exception {

/**********session对象**********/

Properties properties = new Properties();

properties.put("mail.smtp.host","smtp.126.com");

properties.put("mail.smtp.auth","true");

Session session = Session.getInstance(properties);

session.setDebug(true);

/**************message对象*************/

MimeMessage message = getMessage(session);

/**************transport对象*************/

Transport transport = session.getTransport("smtp");

transport.connect(senderAccount, senderPassword);

transport.sendMessage(message, message.getAllRecipients());

transport.close();

}

/**

* 获得message对象

* @param session

* @return

* @throws Exception

*/

public MimeMessage getMessage(Session session) throws Exception {

MimeMessage message = new MimeMessage(session);

InternetAddress address = new InternetAddress(senderAddress);

message.setFrom(address);

InternetAddress toAddress = new InternetAddress(recipientAddress);

message.setRecipient(MimeMessage.RecipientType.TO,toAddress);

message.setSubject("哈哈");

message.setText("下了课我们去威尼斯水世界洗脚吧","UTF-8");

message.saveChanges();

return message;

}

}

4. Spring整合javaMail

Spring邮件抽象层的主要包为org.springframework.mail。它包括了发送电子邮件的主要接口

mailSender:发送邮件

mailMessage:普通信件

mimeMessage:多媒体信件

MimeMessageHelper:往多媒体信件中添加附件、图片、html

这里简单的介绍了如何使用spring发送各种形式的邮件以及配置:

4.1 mail.properties

freight_web

mail.username=你的邮箱账户

mail.password=你的邮箱密码

mail.from=你的邮箱

4.2 applicationContext-mail.xml

freight_web

xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="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.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

${mail.from}

true

true

0

4.3 发送简单邮件

package com.sxt.test;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.mail.MailSender;

import org.springframework.mail.SimpleMailMessage;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration("classpath:applicationContext-mail.xml")

public class MailSendTest {

@Autowired

private MailSender mailSender;

@Autowired

private SimpleMailMessage simpleMailMessage;

@Test

public void SingleMailSend (){

simpleMailMessage.setSubject("你好");

simpleMailMessage.setText("这个是一个通过Spring框架来发送邮件的小程序");

simpleMailMessage.setTo("361499689@qq.com");

mailSender.send(simpleMailMessage);

}

}

4.4 发送带有图片的邮件

@Test

public void ImageMailSend () throws MessagingException {

JavaMailSenderImpl sender = (JavaMailSenderImpl)mailSender;

MimeMessage mailMessage = sender.createMimeMessage();

MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,true);

messageHelper.setFrom("guangweima@126.com");

messageHelper.setTo("361499689@qq.com");

messageHelper.setSubject("测试邮件中嵌套图片!!");

// true 表示启动HTML格式的邮件

messageHelper.setText(

"

hello!!spring image html mail

"

+"", true);

FileSystemResource img = new FileSystemResource(new File("d://1.png"));

messageHelper.addInline("image", img);//跟cid一致

sender.send(mailMessage);

System.out.println("邮件发送成功...");

}

4.5 发送带附件的邮件

@Test

public void AttachedMailSend() throws MessagingException {

JavaMailSenderImpl sender = (JavaMailSenderImpl)mailSender;

MimeMessage mailMessage = sender.createMimeMessage();

MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,true);

messageHelper.setFrom("guangweima@126.com");

messageHelper.setTo("361499689@qq.com");

messageHelper.setSubject("测试邮件中嵌套附件!!");

// true 表示启动HTML格式的邮件

messageHelper.setText(

"

工资已发放,详细信息请查看附件

", true);

FileSystemResource file = new FileSystemResource(new File("D://1.xlsx"));

messageHelper.addAttachment("工资.xlsx", file);//添加到附件

sender.send(mailMessage);

System.out.println("邮件发送成功...");

}

5. 实现发送新员工登录信息

5.1 数据库

5.2 applicationContext-dao.xml

注意:删除applicationContext-mail.xml中的

为什么dao能加载web工程的配置文件?

项目运行时要把pojo、dao、service、web打成一个war包,一个war包和一个工程没有任何区别

5.3 controller

修改UserController

@Autowired

private MailSender mailSender;

... ...

@RequestMapping("/create")

public String createUser(UserP userP, UserInfoP userInfoP, Model model) throws Exception {

String password = userP.getPassword();

//保存用户信息 保存用户扩展信息

userService.createUser(userP,userInfoP);

//给新用户发送登录信息的邮件

Subject subject = SecurityUtils.getSubject();

CurrentUser currentUser = (CurrentUser) subject.getPrincipal();

JavaMailSenderImpl sender = (JavaMailSenderImpl)mailSender;

MimeMessage mailMessage = sender.createMimeMessage();

MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,true);

messageHelper.setFrom(currentUser.getUserInfoP().getEmail());

messageHelper.setTo(userInfoP.getEmail());

messageHelper.setSubject("欢迎新员工");

// true 表示启动HTML格式的邮件

String html = "" +

"

" +

"

欢迎新员工

" +

"

您的账号是:"+userP.getUserName()+"

" +

"

您的密码是:"+password+"

" +

" " +

"";

messageHelper.setText(html, true);

//因为发送邮件会有延迟,所以开启多线程

new Thread(new Runnable() {

@Override

public void run() {

sender.send(mailMessage);

}

}).start();

return "redirect:/user/list";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值