Spring+Hibernate 零散知识点
2016-08-30 09:29
489 查看
MySQL
创建database 时设定字符串create database test2 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
查询字符集show variables like 'character%';
修改字符集,修改配置文件my.ini
在[client]中加入。# Here follows entries for some specificprogramsdefault-character-set= utf8在[mysqld]中加入character-set-server = utf8
Hibernate
自动创建表的设置:(两个方法)方法1.在配置文件中加上
<property name="hibernate.hbm2ddl.auto">create</property>
方法2:
Configuration conf=new Configuration();
conf.configure("/hibernate.cfg.xml");
SchemaExport dbExport=new SchemaExport(conf);
dbExport.create(true, true);
Hibernate4和Mysql5.1以上版本创建表出错 type=InnDB
需要修改配置:
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
修改为:
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
tools
安装Eclipse 的hibernate Toolshelp --> Eclipse Marketplace
Find --> Hibernate Tools
Install
web
request.getInputStream()
获取form 里post 的参数spring
@RequestMapping(value = "/produces", produces = "application/json"):表示将功能处理方法将生产json格式的数据consumes="application/json"
方法仅处理request Content-Type为“application/json”类型的请求。
produces="application/json"
方法仅处理request请求中Accept头中包含了"application/json"的请求,同时暗示了返回的内容类型为application/json;
文件上传
<!-- 配置MultipartResolver 用于文件上传 使用spring的CommosMultipartResolver -->
<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="UTF-8"
p:maxUploadSize="5400000"
p:uploadTempDir="fileUpload/temp"
>
</beans:bean>
<body> <h2>文件上传实例</h2> <form action="fileUpload.html" method="post" enctype="multipart/form-data"> 选择文件:<input type="file" name="file"> <input type="submit" value="提交"> </form> </body>
//通过Spring的autowired注解获取spring默认配置的request @Autowired private HttpServletRequest request; /*** * 上传文件 用@RequestParam注解来指定表单上的file为MultipartFile * * @param file * @return */ @RequestMapping("fileUpload") public String fileUpload(@RequestParam("file") MultipartFile file) { // 判断文件是否为空 if (!file.isEmpty()) { try { // 文件保存路径 String filePath = request.getSession().getServletContext().getRealPath("/") + "upload/" + file.getOriginalFilename(); // 转存文件 file.transferTo(new File(filePath)); } catch (Exception e) { e.printStackTrace(); } } // 重定向 return "redirect:/list.html"; } /*** * 读取上传文件中得所有文件并返回 * * @return */ @RequestMapping("list") public ModelAndView list() { String filePath = request.getSession().getServletContext().getRealPath("/") + "upload/"; ModelAndView mav = new ModelAndView("list"); File uploadDest = new File(filePath); String[] fileNames = uploadDest.list(); for (int i = 0; i < fileNames.length; i++) { //打印出文件名 System.out.println(fileNames[i]); } return mav; }
Java
Method m = o.getClass().getDeclaredMethod(cmd, pe.getClass(),String.class);m.setAccessible(true);
pe = (PhoneEntity) m.invoke(o, pe,json);
MYSQL
Error Code: 1175. You are using safe update
where 中使用非主键解决方法 SET SQL_SAFE_UPDATES = 0;
前言
相关文章推荐
- Spring+Hibernate 零散知识点
- spring struts2,ibatis,hibernate知识点
- hibernate零散知识点
- Spring学习_01_Spring初窥(零散知识点总结)
- spring 零散知识点
- Webwork2结合Spring, Hibernate
- 集成测试Strtus+Spring+Hibernate
- Hibernate+Spring 对DAO的处理实列!
- spring+hibernate+struts例子wiring安装
- Tapestry+Spring+Hibernate(转)
- Spring+Hibernate+Struts技术的一个分页程序,共享给大家
- Spring让Hibernate使用者受益良多
- 使用struts+spring+hibernate 组装web应用
- 使用open source产品组装你的web应用架构(struts+spring+hibernate)
- 使用struts+spring+hibernate 组装web应用
- Struts+Spring+Hibernate 分析
- Hibernate和Spring对DAO处理的实例
- iBatis指南、Hibernate指南、Spring开发指南
- Struts+Hibernate+Spring 框架图我的翻译
- 使用struts+spring+hibernate 组装web应用