设为首页 收藏本站
查看: 868|回复: 0

[经验分享] hibernat use many-to-many---oracle

[复制链接]

尚未签到

发表于 2016-7-31 12:18:24 | 显示全部楼层 |阅读模式
package serviceimp;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import po.Power;
import po.Role;
import service.PowerService;
@SuppressWarnings("unchecked")
public class PowerServiceImp extends BaseServiceImp implements PowerService {
/**
* add update,delete role
*
* @param id
* @param name
* @param oper
* @return
*/
public String edit_role(String id, String name, String oper) {
// add
if ("add".equals(oper)) {
if (!this.isNull(name)) {
Role r = new Role();
r.setName(name.trim());
this.saveOrUpdate(r);
} else {
return "请输入角色名称!";
}
}
// edit
if ("update".equals(oper)) {
if (!this.isNull(name)) {
Role r = (Role) this.get(Role.class, id);
r.setName(name.trim());
this.saveOrUpdate(r);
} else {
return "请输入角色名称!";
}
}
// delete
if ("delete".equals(oper)) {
this.bulkUpdate("delete from Role as r where r.id='" + id + "'");
}
return "1";
}
/**
* add update,delete role
*
* @param id
* @param name
* @param url
* @param oper
* @return
*/
public String edit_power(String id, String name, String url, String oper) {
// add
if ("add".equals(oper)) {
if (this.isNull(name))
return "请输入权限名称!";
if (this.isNull(url))
return "请输入角色url!";
Power p = new Power(name.trim(), url.trim());
this.saveOrUpdate(p);
}
// edit
if ("update".equals(oper)) {
if (this.isNull(name))
return "请输入权限名称!";
if (this.isNull(url))
return "请输入角色url!";
Power p = (Power) this.get(Power.class, id);
p.setName(name.trim());
p.setUrl(url.trim());
this.saveOrUpdate(p);
}
// delete
if ("delete".equals(oper)) {
this.bulkUpdate("delete from Power as p where p.id='" + id + "'");
}
return "1";
}
/**
* 为角色分配权限
*
* @param role_id
* @param power_id
* @return
*/
public String set_power_to_role(String role_id, String power_id[],
String unpower_id[]) {
try {
@SuppressWarnings("unused")
Role r = (Role) this.findAll(
"from Role as r left join fetch r.powers where r.id='"
+ role_id + "'").get(0);
Set<Power> pset = r.getPowers();
for (Iterator<Power> it = pset.iterator(); it.hasNext();) {
Power p = it.next();
// if (ArrayUtils.contains(unpower_id, p.getId())) {
// p.getRoles().remove(r);
// it.remove();
// }
for (int i = 0; i < unpower_id.length; i++) {
if (p.getId().equals(unpower_id)) {
// 删除权限
p.getRoles().remove(r);
it.remove();
}
}
}
for (int i = 0; i < power_id.length; i++) {
if (power_id != null && !power_id.trim().equals("")) {
Power p = (Power) this.get(Power.class, power_id);
p.getRoles().add(r);
pset.add(p);
}
}
this.saveOrUpdate(r);
} catch (Exception ex) {
ex.printStackTrace();
return "-1";
}
return "1";
}
/**
* 取角色权限
*
* @param role_id
* @return
*/
public List list_powers_by_role_id(String role_id) {
List t = new ArrayList();
Role r = (Role) this.findAll(
"from Role as r left join fetch r.powers  where r.id='" + role_id + "'").get(0);
Set<Power> pset = r.getPowers();
Iterator<Power> it = pset.iterator();
while (it.hasNext()) {
t.add(it.next().getName());
}
return t;
}
public List list_powers(int cur_page, int page_size) {
// TODO Auto-generated method stub
String hql = "select new Power(p.id,p.name,p.url) from Power as p";
return this.findAllByPage01(hql, page_size, cur_page);
}
public List list_roles(int cur_page, int page_size) {
// TODO Auto-generated method stub
String hql = "select new Role(r.id,r.name) from Role as r";
return this.findAllByPage01(hql, page_size, cur_page);
}
}


启动oracle数据库时,提示没有监听器
如果,你在控制面板/管理工具/服务中双击打开OracleOraHome92TNSListener的服务看到其“可执行文件的路径”一栏为空时的处理方法:

首先运行regedit.exe启动注册表编辑器,在HKEY_LOCAL_MACHINE/SYSTEM/ControlSet002/下的Services和CurrentControlSet/Services下找到OracleOraHome92TNSListener项,在右边窗口按右键,新建/字符串,取名ImagePath。

双击新见的建,在“数值数据”项输入D:\oracle\ora92\bin\TNSLSNR.EXE(根据你自己的实际情况进行修改),确定完成。   

再次在服务中双击打开OracleOraHome92TNSListener的服务看到其“可执行文件的路径”一栏已经显示了其正确的值。这时你可以启动监听了。



package action;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import service.AdminService;
import service.ManagerService;
import service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class BaseAction extends ActionSupport {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
protected ManagerService managerService;
protected AdminService adminService;
protected UserService userService;
public void setManagerService(ManagerService managerService) {
this.managerService = managerService;
}
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
public boolean isNull(String str) {
if (str == null || "".equals(str.trim())) {
return true;
}
return false;
}
// 自己封装的一个把源文件对象复制成目标文件对象
public boolean copy(File src, File dst) {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(src), 1024);
out = new BufferedOutputStream(new FileOutputStream(dst), 1024);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != out) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 图像的等比缩略
*
* @param fi大图文件
* @param fo将要转换出的小图文件
*/
public boolean resize_image(File fi, File fo) {
try {
// File fi = new File("E:/3.jpg"); // 大图文件
// File fo = new File("E:/333.jpg"); // 将要转换出的小图文件
// AffineTransform transform = new AffineTransform();
BufferedImage bis = ImageIO.read(fi);
int w = bis.getWidth();
// System.out.println(w);
int h = bis.getHeight();
// System.out.println(h);
// double scale = (double) w / h;
int nw = w;
int nh = h;
if (w > 320) {
nw = 320;
nh = nw * h / w;
if (nh > 320) {
nh = 320;
nw = nh * w / h;
}
} else if (h > 320) {
nh = 320;
nw = nh * w / h;
if (nw > 320) {
nw = 320;
nh = nw * h / w;
}
}
BufferedImage tag = new BufferedImage(nw, nh,
BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(bis, 0, 0, nw, nh, null); // 绘制缩小后的图
// 转换为32*32 jpg格式
FileOutputStream newimage = new FileOutputStream(fo); // 输出到文件流
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag);
newimage.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 图像的等比缩略
*
*
* width 输出图片大小 height
*
* @param fi大图文件
* @param fo将要转换出的小图文件
*/
public boolean resize_image(File fi, File fo, int width, int height) {
try {
// File fi = new File("E:/3.jpg"); // 大图文件
// File fo = new File("E:/333.jpg"); // 将要转换出的小图文件
// AffineTransform transform = new AffineTransform();
BufferedImage bis = ImageIO.read(fi);
int w = bis.getWidth();
// System.out.println(w);
int h = bis.getHeight();
// System.out.println(h);
// double scale = (double) w / h;
int nw = w;
int nh = h;
if (w > width) {
nw = width;
nh = nw * h / w;
if (nh > height) {
nh = height;
nw = nh * w / h;
}
} else if (h > height) {
nh = height;
nw = nh * w / h;
if (nw > width) {
nw = width;
nh = nw * h / w;
}
}
BufferedImage tag = new BufferedImage(nw, nh,
BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(bis, 0, 0, nw, nh, null); // 绘制缩小后的图
// 转换为32*32 jpg格式
FileOutputStream newimage = new FileOutputStream(fo); // 输出到文件流
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag);
newimage.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-251489-1-1.html 上篇帖子: oracle时间函数(包括截取时间) 下篇帖子: oracle数据字符集和排序
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表