MySQL存图片路径,在JSP显示图片的代码怎么写?

用的是MySQL8和elipse,
想在连接数据库的基础上,
把数据库里img这个里面存的图片路径运用到JSP的标签上,
目前img里存的是image/malatang.jpg ,
image是当前项目的图片夹,
完全小白自学中,希望大家能给出详细的修改的代码,谢谢大家!

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ page import="com.mysql.jdbc.Driver" %> 

<%@ page import="java.sql.*" %> 

<html>
<head>
<title>通过JSP打开数据表</title>
</head>
<body>
<% 
Class.forName("com.mysql.cj.jdbc.Driver");
    System.out.println("驱动程序加载成功...");
String url = "jdbc:mysql://localhost:3306/test1?useSSL=false&serverTimezone=Asia/Shanghai";
String user = "root";
String password = "1122";
String tableName="test1";
Connection conn = DriverManager.getConnection(url, user, password);
out.print("数据库连接成功!");  
out.print("<br />");            

 String imgpath = "SELECT img FROM foodstest;"; 
 request.getContextPath();

  Statement stmt = null;  
   stmt = conn.createStatement();  

    ResultSet rs = stmt.executeQuery(imgpath);    
     out.print("查询结果:");  

    while (rs.next()) {  

        out.println(rs.getString("img")); //将查询结果输出  

    }  
   %>

   <br/>


<img src="<%=?>" alt="images"/>







2个回答

<img alt="图片加载失败" src="${pageContext.request.contextPath}/image/malatang.jpg" width="150px" height="100px">

在head内添加如下

<% 
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

图片

<img src="<%=basePath%>image/malatang.jpg" alt="images"/>

while (rs.next()) {  
                $('img').attr('src','<%=basePath%>' + rs.getString("img"))
        out.println('<%=basePath%>' + rs.getString("img")); //将查询结果输出  
    }  

此处仅针对一张图片

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
MySQL获取图片路径在JSP显示图片问题
从数据库获取的图片路径放到jsp中,当访问页面时却没有图片,只有![图片说明](https://img-ask.csdn.net/upload/201512/24/1450963770_735454.png)这么个东西,实在不知道怎么解决,求大神指点! jsp代码如下: <%@page import="com.gxy.bean.GxyProduct"%> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'products.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <h3>商品列表如下:</h3> <br> <% if (request.getAttribute("products") != null) { List<GxyProduct> products = (List) request .getAttribute("products"); for (GxyProduct product : products) { String picpath = product.getImg().replaceAll("\\\\", "/"); %> <div> <dl> <dt>Hello</dt> <dd> <img width="100" height="100" src="<%=basePath + picpath%>" /> </dd> </dl> </div> <% }//foreach end }//if end %> </body> </html>
arm-linux-gcc编译报错:libc.so format not recognized.
小弟新手,之前没接触过arm开发,这两天做毕设碰到了难题,请大家帮忙看下, 先行谢过! 我的开发板是一个实验室网关(HBE-UBI-box2),用来收集传感器传来的信息的。将写好的C文件通过arm-linux-gcc编译器编译成cgi文件(编译命令:arm-linux-gcc -o info.cgi info.c)info.c是我写的文件。编译好了之后传到网关里面,然后访问网关就可以看到编程实现的结果了。 可是,前几天导师说网关不能同时支持大量的访问,要我把网关收集的传感器数据传到实验室的服务器上,然后写个网站来访问服务器上的数据。。。好吧,我也不敢反抗,默默的在服务器上建好了MySQL数据库,写了几个jsp来访问数据库,都弄好了。 可是把数据从网关传到服务器时确碰到难题了。我刚开始以为很简单,直接把之前 没有连接mysql数据库的代码加了这段代码: int connmysql(){ MYSQL mysql, *sock; mysql_init(&mysql); if (!(sock = mysql_real_connect(&mysql, "XXX", "XXX", "XXX", "XXX", 0, NULL, 0))) { printf("Cannot connect to database:%s\n",mysql_error(sock)); return 0; } char sqlbuf[200] = "INSERT INTO sensordata VALUES('0','sstatus.id','sstatus.illumi','sstatus.temp','sstatus.humid','sstatus.battery');"; if (mysql_query(sock, sqlbuf)) { printf("Query Failed:%s", mysql_error(sock)); return 0; } mysql_close(sock); return 0; } 其中那个连接数据库语句中的IP地址和用户名密码数据库名都是正确的,我用XXX代替了~。。。 代码也写好了,可是我在用arm-linux-gcc -o 编译的时候却报错了,百度了下,发现自己想的太简单了。按照别人的指导,在虚拟机Ubuntu上又装了mysql的客户机和服务器。 1. sudo apt-get install mysql-server 2. apt-get install mysql-client 3. sudo apt-get install libmysqlclient-dev 编译的命令也找了许多,大致就是要加上编译时用到的库的路径,最后采用的命令如下:arm-linux-gcc -I'/usr/include/mysql' -L'/usr/lib/i386-linux-gnu' -lmysqlclient -lpthread -lz -lm -lrt -ldl -o info.cgi mysql-info.c 这个时候噩梦开始了,一开始报了好多错,我只好一个个排查解决,其中辛酸暂且不表,但是最后还是有一个无法解决: ![图片说明](https://img-ask.csdn.net/upload/201506/03/1433335703_64402.png) 报的错说是:libc.so 的文件格式不被认可和解析错误。找了好久没找到适合arm编程的libc.so文件,只能上这求救了,各位大神如有解决办法,或者对于这个项目的思路有什么新的思路(即不用通过arm连接mysql也可以实现相同功能)烦请指点一二,感激不尽~
springmvc视图解析器的prefix一定要配成全路径才能找到是为什么?
最近刚刚在尝试idea写代码,然后找了个配置尝试自己写,在进行jsp页面跳转的时候发现路径出了问题。 找了半天然后发现是视图解析器里面的prefix问题。 正确代码如下: ``` <!-- 配置视图解析器 显示ViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/src/main/webapp/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> ``` 错误代码如下: ``` <!-- 配置视图解析器 显示ViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> ``` 当我的prefix的路径写全的时候我才能进行页面跳转,而我按照错误代码写的时候就不能进行跳转页面报错404. 但是我在网上看了许多都是这样写的。。。然后搜了半天也没搜到和我类似的问题的。所以就在这里请教下各位大佬 pom.xml的配置如下 ``` <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.liulin</groupId> <artifactId>test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>test Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <!-- 设置项目编码 --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <!-- spring版本号 --> <spring.version>4.3.5.RELEASE</spring.version> <!-- mybatis版本号 --> <mybatis.version>3.4.1</mybatis.version> <!-- log4j日志文件管理包版本 --> <slf4j.version>1.7.7</slf4j.version> <log4j.version>1.2.17</log4j.version> <!-- jackson包版本 --> <jackson.version>2.5.0</jackson.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!--添加java ee依赖--> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> </dependency> <!-- 实现slf4j接口并整合 --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.2</version> </dependency> <!-- 添加JSON依赖 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.7</version> </dependency> <!-- 添加mysql驱动依赖 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.41</version> <scope>runtime</scope> </dependency> <!-- 添加数据库连接池 --> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> <!-- 添加MyBatis依赖 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <!-- 添加mybatis/spring整合包依赖 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.1</version> </dependency> <!-- 添加Spring核心依赖 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <!--添加servlet依赖--> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> <!-- 添加JSTL标签类依赖 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- 添加日志相关jar包 --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> <build> <finalName>test</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> </plugins> </pluginManagement> </build> </project> ``` 配置详细图: 1. ![图片说明](https://img-ask.csdn.net/upload/201907/16/1563262460_481220.png) 2. ![图片说明](https://img-ask.csdn.net/upload/201907/16/1563262471_776644.png) 3. ![图片说明](https://img-ask.csdn.net/upload/201907/16/1563262488_239707.png)
echarts获取mysql中的数据可视化,legend怎么才能跟柱状图的颜色对应起来?
``` <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'echart.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript" src="http://echarts.baidu.com/build/dist/echarts.js"></script> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> // 路径配置 require.config({ paths : { echarts : 'http://echarts.baidu.com/build/dist' } }); // 使用 require([ 'echarts', 'echarts/chart/bar' ,'echarts/chart/line'// 使用柱状图就加载bar模块,按需加载 ], drewEcharts ); function drewEcharts(ec) { // 基于准备好的dom,初始化echarts图表 var myChart = ec.init(document.getElementById('main')); var option = { color: ['#008b00', '#ffff00', '#ff7f00', '#cd0000','#0000cd'],//绿色,黄色,橙色,红色,蓝色 title:{ text: 'DECG', subtext: '物理量待定' }, //提示样式 tooltip : { show : true, trigger: 'axis', axisPointer: { //坐标轴指示器 crossStyle: { color: '#999' } } }, legend : { data: [{name: 'Good',textStyle:{color: '#008b00'}}, {name:'Watch',textStyle:{color: '#ffff00'}}, {name: 'Warning',textStyle:{color:'#ff7f00'}}, {name:'Abnormal value',textStyle:{color:'#cd0000'}}, {name:'Baseline',textStyle:{color:'#0000cd'}} ], orient: 'horizontal', x: 'center', y: 'bottom', padding: 0, itemWidth: 10, textStyle: { fontWeight: 'bold', fontSize:14 } }, grid: { left: '3%', right: '2%', top: '8%', bottom: '2%', containLable: true }, toolbox: { show : true, feature : { dataView : {show: true, readOnly: false}, magicType : {show: true, type: ['line', 'bar']}, restore : {show: true}, saveAsImage : {show: true} } }, calculable : true, xAxis : [ { type : 'category', //设置轴线属性 axisLine:{ lineStyle:{ color: '#4d4d4d' } }, axisLabel: { //x轴字体样式 interval:0, rotate:70, margin:2, textstyle: { color:"#222", fontSize: '16' }}, data :(function(){ var arr=[]; $.ajax({ type : "post", async : false, //同步执行 url : "bar.do", //web.xl中注册的Servlet的url-pattern data : {}, dataType : "json", //返回数据形式为json success : function(result) { if (result) { for(var i=0;i<result.length;i++){ console.log(result[i].name); arr.push(result[i].name); } } }, error : function(errorMsg) { alert("图表请求数据失败!"); myChart.hideLoading(); } }) return arr; })() }], yAxis : [ { type : 'value', name: 'F/N', nameTextStyle:{//坐标轴标签设置 fontWeight: 'bold', fontiSize: '28' }, interval: 10, fontSize: '20', axisLine: { lineStyle:{ color: '#4d4d4d' } }, axisLabel: {//y轴字体样式 formatter: '{value}', textStyle: { color:"#222", fontSize: '16' } } }], series : [{ name : 'Good', type : 'bar', barGap: '1%', barCategoryGap: '10%', itemStyle:{ normal:{ color: function(params){ var index_num = params.data; //alert(param.value); if (index_num < 30){ return '#008b00'; //绿色 }else if (index_num>=30 && index_num<50){ return '#ffff00'; //黄色 }else if (index_num>=50 && index_num<60){ return '#ff7f00'; //橙色 }else{ return '#cd0000'; //红色 } } }, }, //barWidth: 10, data :(function(){ var arr=[]; $.ajax({ type : "post", async : false, //同步执行 url : "bar.do", data : {}, dataType : "json", //返回数据形式为json success : function(result) { if (result) { for(var i=0;i<result.length;i++){ console.log(result[i].num); arr.push(result[i].num); } } }, error : function(errorMsg) { alert("不好意思,大爷,图表请求数据失败啦!"); myChart.hideLoading(); } }) return arr; })() } , { name : 'Watch', type : 'bar', barGap: '1%', barCategoryGap: '10%', itemStyle:{ normal:{ color: function(params){ var index_num = params.data; //alert(param.value); if (index_num>=30 && index_num<50){ return '#ffff00'; //绿色 }else if (index_num < 30){ return '#008b00'; //黄色 }else if (index_num>=50 && index_num<60){ return '#ff7f00'; //橙色 }else{ return '#cd0000'; //红色 } } }, }, //barWidth: 10, data :(function(){ var arr=[]; $.ajax({ type : "post", async : false, //同步执行 url : "bar.do", data : {}, dataType : "json", //返回数据形式为json success : function(result) { if (result) { for(var i=0;i<result.length;i++){ console.log(result[i].num); arr.push(result[i].num); } } }, error : function(errorMsg) { alert("不好意思,大爷,图表请求数据失败啦!"); myChart.hideLoading(); } }) return arr; })() }, { name : 'Warning', type : 'bar', barGap: '1%', barCategoryGap: '10%', itemStyle:{ normal:{ color: function(params){ var index_num = params.data; //alert(param.value); if (index_num < 30){ return '#008b00'; //绿色 }else if (index_num>=30 && index_num<50){ return '#ffff00'; //黄色 }else if (index_num>=50 && index_num<60){ return '#ff7f00'; //橙色 }else{ return '#cd0000'; //红色 } } }, }, //barWidth: 10, data :(function(){ var arr=[]; $.ajax({ type : "post", async : false, //同步执行 url : "bar.do", data : {}, dataType : "json", //返回数据形式为json success : function(result) { if (result) { for(var i=0;i<result.length;i++){ console.log(result[i].num); arr.push(result[i].num); } } }, error : function(errorMsg) { alert("不好意思,大爷,图表请求数据失败啦!"); myChart.hideLoading(); } }) return arr; })() }, { name : 'Abnormal value', type : 'bar', barGap: '1%', barCategoryGap: '10%', itemStyle:{ normal:{ color: function(params){ var index_num = params.data; //alert(param.value); if (index_num < 30){ return '#008b00'; //绿色 }else if (index_num>=30 && index_num<50){ return '#ffff00'; //黄色 }else if (index_num>=50 && index_num<60){ return '#ff7f00'; //橙色 }else{ return '#cd0000'; //红色 } } }, }, //barWidth: 10, data :(function(){ var arr=[]; $.ajax({ type : "post", async : false, //同步执行 url : "bar.do", data : {}, dataType : "json", //返回数据形式为json success : function(result) { if (result) { for(var i=0;i<result.length;i++){ console.log(result[i].num); arr.push(result[i].num); } } }, error : function(errorMsg) { alert("不好意思,大爷,图表请求数据失败啦!"); myChart.hideLoading(); } }) return arr; })() }, { name: 'Baseline', type: 'line', smooth:true, yAxisIndex: 0, symbolSize:0, //拐点圆的大小 itemStyle:{ normal:{ color: '#0000cd', } }, data: [53,30,29,40,18,30,9,17,64,30,48,12,30,38,20,31,38,53,38,51,9,17] } ], //控制每次只显示固定柱子数目 dataZoom:[{ type:'inside',//inside,slider此处只列举inside start:0, end:9,//dataZoom-inside.start 和 dataZoom-inside.end 共同用 百分比 的形式定义了数据窗口范围。 xAxisIndex:0,//不指定时,当 dataZoom-inside.orient 为 'horizontal'时,默认控制和 dataZoom 平行的第一个 xAxis。但是不建议使用默认值,建议显式指定。 filterMode:'none',//dataZoom 的运行原理是通过 数据过滤 来达到 数据窗口缩放 的效果。数据过滤模式的设置不同,效果也不同。('filter','weakfilter','empty','none')http://echarts.baidu.com/option.html#dataZoom-inside zoomLock:true,//只能拖动不可缩放,若无需禁止缩放设置为false或者去除即可 }] }; myChart.setOption(option); // 为echarts对象加载数据 myChart.setOption(option); } sideBarChart.resize();//修改echarts容器大小 </script> </head> <body> <div id="main" style="height: 550px; width: 1100px"></div> </body> </html> ``` 在mysql中取出数据后,按照数值范围对数据进行分类,不同类别的数据显示不同颜色的柱子。 实现结果: ![图片说明](https://img-ask.csdn.net/upload/201907/16/1563266320_869864.png) 求教大神 怎么修改代码,让legend显示与柱子对应的颜色?
Spring MVC views下面的JSP文件无法进入controller
这是controller的代码,点击JSP的链接时控制台没有输出,找了一天的原因了也没弄好 ``` @RequestMapping("/helloworld") public String helloworld(){ System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); return "error"; } ``` 这是页面的链接,路径什么的都是直接复制的,试了好多遍了 ``` <a href="helloworld">hello world</a> ``` 这是springMVC.xml的配置文件,网上参考的,有点乱,不知道有没有大神能够提供标准一点的配置文件 ``` <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" 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-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 配置自动扫描的包 --> <context:component-scan base-package="com.lyy.controller"></context:component-scan> <!--配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.gjt.mm.mysql.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/lyytext?useUnicode=true&amp;characterEncoding=UTF-8" /> <property name="username" value="root" /> <property name="password" value="123" /> <!-- 连接池启动时的初始值 <property name="initialSize" value="3" /> --> <!-- 连接池的最大值 --> <property name="maxActive" value="30" /> <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 --> <property name="maxIdle" value="3" /> <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 --> <property name="minIdle" value="2" /> </bean> <!-- 配置视图解析器 如何把handler 方法返回值解析为实际的物理视图 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"></property> <property name="suffix" value=".jsp"></property> </bean> <mvc:annotation-driven/> <mvc:resources mapping="/views/**" location="/WEB-INF/views/"/> <mvc:default-servlet-handler/> <!-- 配置业务bean:PersonServiceBean --> <bean id="UserDaoImpl" class="com.lyy.dao.impl.UserDaoImpl"> <!-- 向属性dataSource注入数据源 --> <property name="dataSource" ref="dataSource"></property> </bean> </beans> ``` 最后这是web.xml文件: ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <!-- 配置DispatchcerServlet --> <servlet> <servlet-name>mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置Spring mvc下的配置文件的位置和名称 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:SpringConfig.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.css</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.gif</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.jpg</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>mvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- springMvc处理post提交中文乱码 --> <filter> <filter-name>characterEncoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <!-- 指明定编码规则 --> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> ``` 这是报错信息: ``` type Status report message /WorkPlan/controller/helloworld description The requested resource is not available. ``` 我实在不知道是为啥了。。。求大神~~~
jsp页面调用Servlet后进入Servlet页面空白不跳转了
各位大大,小弟正在用java做毕业设计,遇到一个问题,就是想实现获取页面的学生姓名sname和学号sno,然后到数据库中执行查询,将这个学生的成绩从数据库中输出到新的页面。可是,问题来了:在查询页面点击提交按钮后,页面跳转到ChengjiServlet2页面,web浏览器就一片空白,在ChengjiServlet2页面的sendRedirect也没了作用。。。希望各位大大们看在我操心做毕业设计的份儿上帮帮我吧,说白了就是一个查询输出,望大大们指点!跪谢!! //查询页面,jsp。放在一个文件夹里。路径没出错 不支持直接使用html标签,所以我改了一下 《body》 《form id="form1" name="chengjiFrom" method="post" action="../ChengjiServlet2"》《h1 align="center"》成绩查询页面《/h1》 《p>姓名: 《input name="sname" type="text" id="sname" /> 《/p> 《p>学号: 《input name="sno" type="text" id="sno" /> 《/p> 《p> 《input type="submit" name="Submit" value="查询成绩" /> 《/p> 《/form> 《/body> >//这是我编写的ChengjiServlet2类 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List chengji = new ArrayList(); //获取chengjichaxun.jsp页面的各个控件属性 String Sname = request.getParameter("sname"); String Sno = request.getParameter("sno"); String SelectScore = request.getParameter("select"); ChengjiSQLUtil chengjiSql = new ChengjiSQLUtil(); Connection conn =null; Statement stmt=null; ResultSet rs = null; conn = chengjiSql.getConn_Bendi(); try { if(SelectScore.equals("score_1")) { //创建Statement实例,并执行sql语句 String sql = "SELECT * FROM 'renwu'.'score_da1' where sno='"+Sno+"' and sname='"+Sname+"'"; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while(rs.next()) { String sno = rs.getString("sno"); String sname = rs.getString("sname"); String ke1_a = rs.getString("ke1_a"); String ke1_b = rs.getString("ke1_b"); String ke1_c = rs.getString("ke1_c"); String ke1_d = rs.getString("ke1_d"); String ke1_e = rs.getString("ke1_e"); String ke1_f = rs.getString("ke1_f"); chengji.add(sno); chengji.add(sname); chengji.add(ke1_a); chengji.add(ke1_b); chengji.add(ke1_c); chengji.add(ke1_d); chengji.add(ke1_e); chengji.add(ke1_f); } HttpSession session = request.getSession(); session.setAttribute("score", chengji); response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp"); } else if(SelectScore.equals("score_2")) { String sql = "SELECT * FROM 'renwu'.'score_da2' where sno='"+Sno+"' and sname='"+Sname+"'"; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while(rs.next()) { String sno = rs.getString("sno"); String sname = rs.getString("sname"); String ke2_a = rs.getString("ke2_a"); String ke2_b = rs.getString("ke2_b"); String ke2_c = rs.getString("ke2_c"); String ke2_d = rs.getString("ke2_d"); String ke2_e = rs.getString("ke2_e"); String ke2_f = rs.getString("ke2_f"); chengji.add(sno); chengji.add(sname); chengji.add(ke2_a); chengji.add(ke2_b); chengji.add(ke2_c); chengji.add(ke2_d); chengji.add(ke2_e); chengji.add(ke2_f); } HttpSession session = request.getSession(); session.setAttribute("score", chengji); response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp"); } else if(SelectScore.equals("score_3")) { String sql = "SELECT * FROM 'renwu'.'score_da3' where sno='"+Sno+"' and sname='"+Sname+"'"; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while(rs.next()) { String sno = rs.getString("sno"); String sname = rs.getString("sname"); String ke3_a = rs.getString("ke3_a"); String ke3_b = rs.getString("ke3_b"); String ke3_c = rs.getString("ke3_c"); String ke3_d = rs.getString("ke3_d"); String ke3_e = rs.getString("ke3_e"); String ke3_f = rs.getString("ke3_f"); chengji.add(sno); chengji.add(sname); chengji.add(ke3_a); chengji.add(ke3_b); chengji.add(ke3_c); chengji.add(ke3_d); chengji.add(ke3_e); chengji.add(ke3_f); } HttpSession session = request.getSession(); session.setAttribute("score", chengji); response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp"); } else if(SelectScore.equals("score_4")) { String sql = "SELECT * FROM 'renwu'.'score_da4' where sno='"+Sno+"' and sname='"+Sname+"'"; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while(rs.next()) { String sno = rs.getString("sno"); String sname = rs.getString("sname"); String ke4_a = rs.getString("ke4_a"); String ke4_b = rs.getString("ke4_b"); String ke4_c = rs.getString("ke4_c"); String ke4_d = rs.getString("ke4_d"); String ke4_e = rs.getString("ke4_e"); String ke4_f = rs.getString("ke4_f"); chengji.add(sno); chengji.add(sname); chengji.add(ke4_a); chengji.add(ke4_b); chengji.add(ke4_c); chengji.add(ke4_d); chengji.add(ke4_e); chengji.add(ke4_f); } HttpSession session = request.getSession(); session.setAttribute("score", chengji); response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp"); } }catch(Exception e) { e.printStackTrace(); }finally { chengjiSql.releaseResources(conn, stmt, rs); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } > //这块是web.xml的相关信息 <servlet> <servlet-name>chengjiServlet2</servlet-name> <servlet-class>org.afan.course.servlet.ChengjiServlet2</servlet-class> </servlet> <servlet-mapping> <servlet-name>chengjiServlet2</servlet-name> <url-pattern>/chengjiServlet2</url-pattern> </servlet-mapping> //这块是查询成功后要跳转的页面代码,目前还没能走到这个页面。我用list将数据输出,因为不会其他的将java类查询结果输出到jsp页面的方法。。 《body><P>成绩情况</P> 《table> <% List list = (List)session.getAttribute("score"); for(int i=0;i<list.size();i++) { out.print("成绩:" + list.get(i) + "<br/>"); } %> 《/table> 《/body>
springBoot使用注解注入失败
**useMapper的xml文件** ``` <mapper namespace="com.auto.dao.UserMapper"> <select id="findByName" parameterType="String" resultType="User"> select * from t_user where username=#{username} </select> </mapper> ``` **mapper接口代码** ``` public interface UserMapper { public User findByName(String username); } ``` **springboot启动类的代码** ``` @SpringBootApplication @MapperScan("com.auto.dao") public class App { public static void main(String[] args) { SpringApplication.run(App.class,args); } } ``` **pom.xml文件配置** ``` <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> </parent> <groupId>com.auto</groupId> <artifactId>MavenDay01</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <!-- spirngBoot启动器 --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <!-- jstl --> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> ``` **user的实体类** ``` @Repository public class User { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "User [username=" + username + ", password=" + password + "]"; } } ``` **这是properties的配置文件** ``` spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/mysql spring.datasource.username=root spring.datasource.password=123456 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource mybatis.type-aliases-package=com.auto.entity 实体类和mapper.xml文件都在这包里面 server.port=9090 spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp ``` **我写了个service接口,然后写了个实现类重写findByName方法返回userMapper中方法,在实现类中注入了userMapper接口,这里无法使用@Autowired注入** ``` @Service @Transactional public class UserServiceImpl implements UserService{ @Resource UserMapper userMapper; @Override public User findByName(String username) { return userMapper.findByName(username); } } ``` **报错** ``` org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.auto.dao.UserMapper.findByName ``` 总是报找不到接口,加上注解标记也没用,换成在接口上用@mapper注解也不行,是什么问题,我在网上看说有什么依赖包冲突问题,但我换了几个版本也不行; **问题已经解决:** 问题出在没有在properties文件中添加mapper.xml文件的扫描路径 解决办法:在properties文件中加上 mybatis.mapper-locations=com/.../.../*.xml 这里是mapper.xml文件的路径
激活账号的servlet运行报错500,代码是对的,为什么会报错?
报错 ![图片说明](https://img-ask.csdn.net/upload/201904/24/1556071273_272031.png) servlet代码 ``` package servlets; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import bean.Check; import bean.DB; import bean.Tools; import java.sql.*; public class RegAdminServlet extends HttpServlet { /** * Constructor of the object. */ public RegAdminServlet() { super(); } /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //用以建立数据库连接的必要信息 String url="jdbc:mysql://localhost:3306/database"; String user="root"; String password="123456"; String adminid = Tools.codeToChinese(request.getParameter("adminid")); String adminpass = request.getParameter("adminpass"); String adminname = Tools.codeToChinese(request.getParameter("adminname")); String admintele = request.getParameter("admintele"); //省略号表示要输入具体的sql语句 String sql="select * from administrator adminID='"+adminid+"'"; //创建各个对象 Connection conn=null; //建立数据库连接的对象 Statement stmt=null; //创建用于执行SQL语句的Statement对象 ResultSet rs=null; //创建结果集对象 HttpSession session = request.getSession(); try{ //建立连接并执行语句 conn=DriverManager.getConnection(url, user, password); stmt=conn.createStatement(); rs=stmt.executeQuery(sql); //其它操作 if(rs.next()) { Check check = new Check(); boolean ck=check.check(adminid, adminpass, adminname, admintele); if(ck) { DB db = new DB(); StringBuffer newsql = new StringBuffer(); newsql.append("UPDATE administrator SET adminActivated='1' WHERE adminID='"+adminid+"'"); boolean a = db.executeUpdate(newsql.toString()); if(a){ session.setAttribute("message","激活成功!"); response.sendRedirect("regCheckSuccess.jsp"); } else{ session.setAttribute("message","激活失败,请重新激活!"); response.sendRedirect("regCheckFailure.jsp"); } } else { session.setAttribute("message", "激活失败!用户信息输入错误,请重新输入!"); response.sendRedirect("regCheckFailure.jsp"); } } else { session.setAttribute("message", "账号不存在,请重新输入!"); response.sendRedirect("regMsgAdmin.jsp"); } }catch(SQLException se){ throw new ServletException(se); }finally{ try{rs.close();}catch(SQLException se){} try{stmt.close();}catch(SQLException se){} try{conn.close();}catch(SQLException se){} } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<form method=post action=PotalServlet>"); out.println("<table><tr>"); out.println("<td>请输入用户名</td>"); out.println("<td><input type=text name=username /></td>"); out.println("</tr><tr>"); out.println("<td>请输入密码</td>"); out.println("<td><input type=password name=userpass /></td>"); out.println("</tr><tr>"); out.println("<td><input type=reset value=重填 /></td>"); out.println("<td><input type=submit value=登录 /></td>"); out.println("</tr>"); out.println("</table>"); out.println("</form>"); //out.close()不能调用,否则portal中后面的输出语句将不输出 /*out .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close();*/ } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { String classname="com.mysql.jdbc.Driver"; try{ Class.forName(classname); }catch(ClassNotFoundException ce){ throw new ServletException("加载数据库驱动失败"); } } } ``` Check包代码 ``` package bean; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Check { public static boolean check(String adminid,String adminpass,String adminname,String admintele) { DB db = new DB(); Connection conn=db.createConn(); String sql = "select * from administrator where adminID='"+adminid+"'"; /*Statement stmt = null; ResultSet rs = null;*/ try{ Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery(sql); while(rs.next()) { String adminID = rs.getString("adminID"); String adminPass = rs.getString("adminPass"); String adminName = rs.getString("adminName"); String adminTele = rs.getString("adminTele"); if(adminID.equals(adminid)&&adminPass.equals(adminpass)&&adminName.equals(adminname)&&adminTele.equals(admintele)) { return true; } else { return false; } } }catch(SQLException se){ return false; }finally{ //try{rs.close();}catch(SQLException se){} //try{stmt.close();}catch(SQLException se){} //try{conn.close();}catch(SQLException se){} } return false; } } ``` DB包代码 ``` package bean; //导入创建应用数据要用到的类 import java.sql.DriverManager; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DB { private String classname="com.mysql.jdbc.Driver"; //数据库驱动类路径 private String url="jdbc:mysql://localhost:3306/database"; //数据库URL private String user="root"; //登录数据库的用户名 private String pwd="123456"; //登录数据库的密码 private Connection conn=null; //申明一个Connection对象 private Statement stmt=null; //声明一个Statement对象 private ResultSet rs=null; /*通过构造方法加载数据库驱动*/ public DB(){ //DB类的构造方法 try{ //必须使用try catch语句捕获加载数据库驱动时可能发生的异常 Class.forName(classname).newInstance(); //加载数据库驱动 }catch (Exception e){ e.printStackTrace(); //输出异常信息 System.out.println("加载数据库驱动失败!!"); } } /*创建数据库连接*/ public Connection createConn(){ try{ conn=DriverManager.getConnection(url, user, pwd); }catch(SQLException e){ e.printStackTrace(); System.out.println("获取数据库连接失败!!"); } return conn; } /*获取Statement对象*/ public void getStmt(){ createConn(); try{ //调用Connection类实例的createStatement()方法创建一个Statement类对象 stmt=conn.createStatement(); }catch(SQLException e){ e.printStackTrace(); System.out.println("创建Statement对象失败!!"); } } /*创建对数据库进行操作的增加、删除和修改的executeUpdate()方法*/ public boolean executeUpdate(String sql){ boolean mark=false; try{ getStmt(); //创建一个Statement对象 int iCount=stmt.executeUpdate(sql); //执行操作,并获取所影响的记录数 if(iCount>0) //更新数据库成功 mark=true; else //更新失败 mark=false; }catch(SQLException e){ e.printStackTrace(); } return mark; } /*查询数据库*/ public ResultSet executeQuery(String sql){ try{ getStmt(); try{ rs=stmt.executeQuery(sql); }catch(Exception e){ e.printStackTrace(); System.out.println("查询数据库失败!!"); } }catch(Exception e){ e.printStackTrace(); } return rs; } public void close(){ try{if(rs!=null)rs.close();}catch(Exception e){} try {stmt.close();}catch(Exception e){} try {conn.close();}catch(Exception e){} } } ``` jsp代码 ``` <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'regAdmin.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script language="javascript"> function isNull(str) { if (str.length==0) return true; else return false; } function isValidate(form) { adminid=form.adminid.value; adminpass=form.adminpass.value; adminname=form.adminname.value; admintele=form.admintele.value; if(isNull(adminid)) { alert("请输入账号!"); return false; } if(isNull(adminpass)) { alert("请输入密码!"); return false; } if(isNull(adminname)) { alert("请输入姓名!"); return false; } if(isNull(admintele)) { alert("请输入联系方式!"); return false; } return true; } </script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form name="form" action="RegAdminServlet" method="post" onSubmit="return isValidate(form)"><br> <h1 align="center"> 管理员账号激活</h1><hr><p><br> <table width="300" border="0" align="center"> <tr><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td></tr><tr> <td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td>账 号 :</td> <td><input type="text" name="adminid" /></td> </tr> <tr> <td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td>密 码 :</td> <td><input type="password" name="adminpass"/></td> </tr> <tr> <td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td>姓 名 :</td> <td><input type="text" name="adminname"/></td> </tr> <tr> <td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td>联 系<br>方 式 :</td> <td><input type="text" name="admintele"/></td> </tr> </table><br> <div align="center"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="激活"/> &nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="清空"/><br><br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="loginAdmin.jsp">【返回】</a> </div> <p> </form> </body> </html> ``` 数据库 ![图片说明](https://img-ask.csdn.net/upload/201904/24/1556071645_465453.png)
spring mvc项目,请求一直报404错误
# 1.web.xml配置 <!-- 从类路径下加载spring配置文件,classpath关键字特指从类路径下加载 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml </param-value> </context-param> <!-- 配置web容器监听器,该监听器启动时自动运行,他会根据上面的spring配置文件里面的参数启动spring容器 --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> # 2.applicationContext.xml配置 <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 --> <context:component-scan base-package="com.cn.zjf.dom" /> <!-- 扫描serviec包 --> <context:component-scan base-package="com.cn.zif.service"/> <!-- 扫描web包 --> <context:component-scan base-package="com.cn.zif.web"/> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" > <property name="order" value="0" /> </bean> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <!-- DBCP开源数据源实现方式定义了一个数据源,里面包含数据源信息 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/app_server"/> <property name="username" value="root"/> <property name="password" value="zjf"/> </bean> <!-- 将配置的数据源注入到jdbcTemplate,这样我就得jdbc样板就知道连接哪一个数据源 --> <!-- 此处的这个jdbc连接样板会通过@Autowired自动注入到Dao的bean中 --> <!-- spring可以将注解和xml很好的关联在一起 --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" p:dataSource-ref="dataSource" /> <!--定义一个基于数据源的事务管理器,该管理器负责声明事务的管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource"/> <!-- 通过aop和以及tx命名空间的语法,以aop方式为service包下的所有类的所有方法进行事务增强 --> <bean id="defaulViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/webpage"/> <property name="suffix" value=".jsp"/> </bean> # 3.控制器代码 package com.cn.zjf.web; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.cn.zjf.domain.Log; import com.cn.zjf.domain.User; import com.cn.zjf.service.UserService; @Controller @RequestMapping(value="/con") public class LoginController { @Autowired private UserService userService; @RequestMapping(value = "/login.do") public String loginPage(){ return "login"; } @RequestMapping(value = "/loginCheck.html") public ModelAndView loginCheck(HttpServletRequest request,LoginCommand loginCommand){ boolean flag = userService.checkUser(loginCommand.getUserName(), loginCommand.getPassword()); if(!flag){ return new ModelAndView("login","error","用户名或密码错误"); }else{ User user = userService.selectUser(loginCommand.getUserName()); String ip = request.getRemoteAddr(); userService.loginLog(user,ip); request.getSession().setAttribute("user", user); return new ModelAndView(); } } } # 4 访问路径 http://localhost:8089/chapter/con/login.do chapter为项目名称 哪位大侠帮忙看一下,是哪里配置错误吗
关于excel文件导入到mysql数据没有读取到文件问题
<p>  我最近在做一个oa项目,其中有一个excel文件导入到数据中去,用poi做的。我现在在后台能够得到文件的完整路径,但是HSSFWorkbook并没有创建一个工作簿。在网上找了很多资料,并没有找到解决方案,本人是只菜鸟,望各位大侠指路,帮忙看看。谢谢!</p> <p>前台import.jsp代码:</p> <div class="quote_title">写道</div> <div class="quote_div">&lt;%@ page contentType="text/html;charset=GBK"%&gt; <br>&lt;%@ page session="true" %&gt; <br>&lt;%@ page isThreadSafe="true" %&gt; <br>&lt;head&gt; <br><br>&lt;style type="text/css"&gt; <br>&lt;!-- <br>body,td,th { <br>font-size: 12px; <br>} <br>--&gt; <br>&lt;/style&gt; <br>&lt;title&gt;&lt;/title&gt; <br>&lt;/head&gt; <br>&lt;body &gt; <br><br>&lt;script language="javascript"&gt; <br>function add(){ <br>var filePath = document.myform.Urlexcel.value; <br>alert(filePath); <br>myform.action="saveExcel.jsp?filePath="+filePath ; <br>myform.submit(); <br>} <br><br>&lt;/script&gt; <br>&lt;form action="saveExcel.jsp" enctype="multipart/form-data" name="myform" method="post" onSubmit="return check(this)"&gt; <br><br>&lt;p&gt; &lt;/p&gt; <br>&lt;p&gt; &lt;/p&gt; <br>&lt;p&gt; &lt;/p&gt; <br>&lt;table width="80%" border="0" align="center" cellpadding="0" cellspacing="0"&gt; <br>&lt;tr&gt; <br>&lt;td height="50" align="center" valign="middle"&gt; &lt;/td&gt; <br>&lt;td height="50" align="left" valign="middle"&gt; Excel文件: <br>&lt;input name="Urlexcel" type="file" id="Urlexcel" size="41" /&gt;&lt;/td&gt; <br>&lt;td&gt; &lt;/td&gt; <br>&lt;/tr&gt; <br>&lt;tr&gt; <br><br>&lt;td height="50" align="center" valign="middle" colspan="2"&gt; <br>&lt;input type="button" onClick="add();" name="Submit1" value="确认提交" /&gt; <br>         <br>&lt;input type="submit" name="Submit2" value="取消重置" /&gt; <br>&lt;/td&gt; <br>&lt;td&gt; &lt;/td&gt; <br>&lt;/tr&gt; <br>&lt;/table&gt; <br>&lt;/form&gt; <br><br>&lt;/body&gt; <br>&lt;/html&gt;</div> <p> </p> <p>后台saveExcel.jsp代码:</p> <pre name="code" class="java">&lt;%@ page language="java"%&gt; &lt;%@ page session="true"%&gt; &lt;%@ page isThreadSafe="true"%&gt; &lt;%@ page contentType="text/html;charset=GBK"%&gt; &lt;%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%&gt; &lt;%@page import="java.io.FileInputStream"%&gt; &lt;%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%&gt; &lt;%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%&gt; &lt;%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%&gt; &lt;%@page import="java.io.FileNotFoundException"%&gt; &lt;%@page import="java.io.IOException"%&gt; &lt;%@page import="org.apache.poi.poifs.filesystem.POIFSFileSystem"%&gt; &lt;% String filePath = request.getParameter("filePath"); out.println(filePath); try { // 创建对Excel工作簿文件的引用 FileInputStream fis = new FileInputStream(filePath); POIFSFileSystem fs = new POIFSFileSystem(fis); HSSFWorkbook wookbook = new HSSFWorkbook(fs); out.println(wookbook);//此处并没有打印出能容 HSSFSheet sheet = wookbook.getSheet("Sheet1"); // 获取到Excel文件中的所有行数 int rows = sheet.getPhysicalNumberOfRows(); out.println(rows); // 遍历行 for (int i = 0; i &lt; rows; i++) { // 读取左上端单元格? HSSFRow row = sheet.getRow(i); // 行不为空 if (row != null) { // 获取到Excel文件中的所有的列 int cells = row.getPhysicalNumberOfCells(); String value = ""; // 遍历列 for (short j = 0; j &lt; cells; j++) { // 获取到列的值 HSSFCell cell = row.getCell(j); if (cell != null) { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: break; case HSSFCell.CELL_TYPE_NUMERIC: value += cell.getNumericCellValue() + ","; break; case HSSFCell.CELL_TYPE_STRING: value += cell.getStringCellValue() + ","; break; default: value += "0"; break; } } } // 将数据插入到mysql数据库中 String[] val = value.split(","); Nsxxb1 entity = new Nsxxb1() ; entity.setGLM(val[0]); entity.setQYMC(val[1]); entity.setXSE1(Double.parseDouble(val[2])); entity.setZZS1(Double.parseDouble(val[3])); entity.setYYS1(Double.parseDouble(val[4])); entity.setXFS1(Double.parseDouble(val[5])); entity.setQYSDS1(Double.parseDouble(val[6])); entity.setGRSDS1(Double.parseDouble(val[7])); entity.setYHS1(Double.parseDouble(val[8])); entity.setTDZZS1(Double.parseDouble(val[9])); entity.setCJS1(Double.parseDouble(val[10])); Nsxxb1Service.insert(entity); } } catch (FileNotFoundException e) { out.println("导入失败"); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } %&gt; </pre> <p> </p>
SSH搭建好了之后开始测试Struts的Action 转到自己写的404页面
按照李刚的struts讲义写的action 功能是输入用户名密码之后跳转到另外的jsp页面.但是每次都出来404页面.请问是哪边配置有问题? 如果另外ssh框架也没建好还请指正.以下是代码[code="web.xml"]<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Archetype Created Web Application</display-name> <!-- 以下3项参数与log4j的配置相关 --> <listener> <listener-class> org.springframework.web.util.Log4jConfigListener </listener-class> </listener> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>60000</param-value> </context-param> <!-- 默认情况下,会加载WEB-INF/applicationContext.xml这个文件,我们可以通过配置 contextConfigLocation参数改变配置文件的路径 --> <!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔 此参数用于后面的Spring-Context loader --> <!-- 使容器启动时,自动加载applicationContext配置,因为它实现了ServletContextListener这个接口,容器启动时会自动执行它实现的方法。 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:*/ApplicationContext.xml,*/action-Servlet.xml</param-value> </context-param> <!-- 加载spring容器 --> <!-- 整合struts 加入中心拦截器 --> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> <init-param> <param-name>struts.action.extendion</param-name> <param-value>action</param-value> </init-param> </filter> <!-- <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>--> <!-- Struts --> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts.xml</param-value></init-param> <load-on-startup>2</load-on-startup> </servlet> <!-- session超时定义,单位为分钟 --> <session-config> <session-timeout>120</session-timeout> </session-config> <!-- 默认首页定义 --> <welcome-file-list> <welcome-file>login2.jsp</welcome-file> </welcome-file-list> <!-- Error Page定义 --> <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/commons/error.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/commons/error.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/commons/404.jsp</location> </error-page> <error-page> <error-code>403</error-code> <location>/commons/403.jsp</location> </error-page> </web-app> [/code] [code="strut.xml"]<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true"/> <constant name="struts.objectFactory" value="spring" ></constant> <package name="calvin" extends="struts-default"> <action name="login" class="/loginAction"> <result name="error">index.jsp</result> <result name="success">/pages/index.jsp</result> </action> </package> </struts>[/code] [code="ApplicationContext.xml"]<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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-3.0.xsd"> <!-- Spring容器配置文件 --> <!-- 告诉spring hibernate文件的位置 然后加载 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/policemanagement?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8"/> <property name="username" value="root"/> <property name="password" value="rooot"/> <property name="maxActive" value="100"/> <property name="maxIdle" value="30"/> <property name="maxWait" value="1000"/> <property name="defaultAutoCommit" value="true"/> <property name="removeAbandoned" value="true"/> <property name="removeAbandonedTimeout" value="60"/> <property name="logAbandoned" value="true"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mappingResources" > <list> <value>calvin/po/pojo/hbm/arrestedPerson.hbm.xml</value> <value>calvin/po/pojo/hbm/caseRegisted.hbm.xml</value> <value>calvin/po/pojo/hbm/caseThread.hbm.xml</value> <value>calvin/po/pojo/hbm/caseVictim.hbm.xml</value> <value>calvin/po/pojo/hbm/policeOfficer.hbm.xml</value> <value>calvin/po/pojo/hbm/victimOffice.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hbm2ddl.auto">create</prop> </props> </property> </bean> <!-- 为hibernte配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- daoContext 配置原因 所以放在这边 --> <bean id="dao" class="calvin.dao.imp.BaseDAOHibernate"> <property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="policeOfficerDAO" class="calvin.dao.imp.PoliceOfficerImp"> <property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="arrestedPersonDAO" class="calvin.dao.imp.ArrestedPersonImp"> <property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="caseRegisteredDAO" class="calvin.dao.imp.CaseRegisteredImp"> <property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="caseThreadDAO" class="calvin.dao.imp.CaseThreadImp"> <property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="caseVictimDAO" class="calvin.dao.imp.CaseVictimImp"> <property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="victimOfficeDAO" class="calvin.dao.imp.VictimOfficeImp"> <property name="sessionFactory" ref="sessionFactory" /></bean> <!-- ENd --> <!-- IOC 注入机制 --> <!-- 定义事务模板类 --> <bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <!-- 注入事务管理器 --> <property name="transactionManager" ref="transactionManager"/> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property></bean> <!-- 配置具体业务逻辑层组件的事物代理 --> <bean id="manager" parent="txProxyTemplate"> <property name="target"> <bean class="calvin.service.BaseManager"> <property name="dao" ref="dao"/> </bean> </property> </bean> <!-- 配置具体的业务逻辑组件额事务代理 --> <!-- 配置业务逻辑组件的事务代理,使用了bean 的继承 --> <!-- 配置所需要的dao组件!!!即这里用的是dao的名字 --> <bean id="facadeManager" parent="txProxyTemplate"> <!-- 配置事务代理时,指定代理的目标,此处的目标是嵌套bean--> <property name="target"> <!-- 嵌套bean无须使用 id属性--> <bean class="calvin.service.imp.FacadeManagerImp"> <!-- 为业务逻辑组件注入DAO组件 --> <property name="victimOfficeDAO" ref="victimOfficeDAO"/> <property name="policeOfficerDAO" ref="policeOfficerDAO"/> <property name="caseVictimDAO" ref="caseVictimDAO"/> <property name="caseThreadDAO" ref="caseThreadDAO"/> <property name="caseRegisteredDAO" ref="caseRegisteredDAO"/> <property name="arrestedPersonDAO" ref="arrestedPersonDAO"/> </bean></property> </bean> <!-- action --> <bean id="myService" class="calvin.action.test.MyServiceImp"/> <bean name="/loginAction" class="calvin.action.LoginAction" scope="prototype"> <property name="ms" ref="myService"/> </bean> </beans>[/code] [code="LoginAction"]package calvin.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.junit.Test; import calvin.action.baseAction.BaseAction; import calvin.action.test.MyService; import calvin.po.pojo.PoliceOfficer; public class LoginAction extends BaseAction{ private String username; private String password; private MyService ms; public MyService getMs() { return ms; } public void setMs(MyService ms) { this.ms = ms; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String execute() throws Exception{ System.out.println("AAA"); if(ms.valid(getUsername(),getPassword())){ return new String("success"); }else{ return "error";} } } [/code] [code="MyServiceImp"]package calvin.action.test; public class MyServiceImp implements MyService{ public boolean valid(String username,String pass){ return true; } } [/code] 首页配置就是一个很简单的登陆页面.
请教:Spring + Hibernate 无法将数据写入数据库?
Spring + Hibernate 无法将数据写入数据 **请教: 通过Junit单元测试Service可以将数据写入数据库;但部署访问却无法向数据库写入数据。** 1 环境: Spring 3.1.2 Hibernate 4.1.4 Jdk1.6 2 配置: 2.1 Web.xml <!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔 此参数用于后面的Spring Context Loader --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--Dispathcer Servlet --> <servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Spring MVC Servlet 拦截.do结尾的请求--> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- Filter 定义 --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--openSessionInView--> <filter> <filter-name>openSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>sessionFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>openSessionInView</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 2.2 applicationContext.xml <!--扫描并自动装配 --> <context:annotation-config /> <context:component-scan base-package="com.sp" /> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath:application.properties</value> </property> </bean> <!-- 数据源配置 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- Connection Info --> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!-- Connection Pooling Info --> <property name="maxActive" value="${dbcp.maxActive}" /> <property name="maxIdle" value="${dbcp.maxIdle}" /> <property name="defaultAutoCommit" value="false" /> <!-- 连接Idle一个小时后超时 --> <property name="timeBetweenEvictionRunsMillis" value="3600000" /> <property name="minEvictableIdleTimeMillis" value="3600000" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.connection.autocommit">true</prop> <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> <property name="packagesToScan"> <list> <value>com.sp.dao</value> <value>com.sp.entity.dict</value> </list> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" abstract="false" lazy-init="default" autowire="default"> <property name="sessionFactory"><ref bean="sessionFactory" /></property> </bean> <!-- 事务管理配置 --> <!--<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>--> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" read-only="false" propagation="REQUIRED" /> <tx:method name="get*" read-only="false" propagation="REQUIRED" /> <tx:method name="add*" read-only="false" propagation="REQUIRED" /> <tx:method name="update*" read-only="false" propagation="REQUIRED" /> <tx:method name="delete*" read-only="false" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <aop:config> <aop:advisor pointcut="execution(* com.sp.service.*.*(..))" advice-ref="txAdvice"/> </aop:config> </beans> 2.3 spring-mvc.xml <!-- 启动注解驱动的SpringMVC功能,注册请求URL和注解POJO类方法的映射 --> <mvc:annotation-driven /> <!-- 自动扫描且只扫描@Controller --> <context:component-scan base-package="com.sp.web" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <context:component-scan base-package="com.sp.dao.impl"></context:component-scan> <context:component-scan base-package="com.sp.service.impl"></context:component-scan> <mvc:default-servlet-handler /> <!-- 对模型视图名称的解析,在请求时模型视图名称添加后缀。定义JSP --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 支持上传文件 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /> 2.4 hibernate.cfg.xml <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/test</property> <property name="connection.username">root</property> <property name="connection.password">password</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect <property name="dialect">org.hibernate.dialect.MySQLDialect</property> --> <!-- Enable Hibernate's automatic session context management --> <!-- <property name="current_session_context_class">thread</property> --> <!-- Disable the second-level cache --> <!-- <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>--> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <property name="format_sql">true</property> <!-- Drop and re-create the database schema on startup--> <property name="hbm2ddl.auto">update</property> <property name="javax.persistence.validation.mode">none</property> 3 代码: 3.1 Service层: @Component("userService") public class UserServiceImpl implements UserService{ @Autowired private UserDao userDao; @Autowired private FormValidator validator; @Override public String userLogin(UserModel user) { String password = userDao.userLogin(user); if(password.equals(user.getPassword())){ return "sucess"; }else{ return "false"; } } @Override public List<ProjectType> getAllProjectTypes(){ List<ProjectType> projectType = userDao.getAllProjectTypes(); return projectType; } @Override public String addProjectType(@ModelAttribute("newProjectType")ProjectType projectType,BindingResult result,SessionStatus status){ validator.validate(projectType, result); if(result.hasErrors()){ return "newProjectType"; } userDao.save(projectType); //status.setComplete(); return "redirect:showProjectTypes.do"; } //添加《项目类型》 @Override public String addProjectType(ProjectType projectType) { userDao.save(projectType); return "redirect:showProjectTypes.do"; } } 3.2 Control层 @Controller @RequestMapping(value = "/user") public class UserController { @Autowired private UserService userService; @Autowired private FormValidator validator; @RequestMapping(value = "/login",method=RequestMethod.POST) protected String handle(UserModel user,BindingResult result, Model model){ String flag = userService.userLogin(user); System.out.println("flag:" + flag); if ("sucess".equals(flag)){ return "sucess"; } return "test1"; } @RequestMapping(value = "/showProjectTypes") protected ModelAndView getAllProjectTypes(){ ModelAndView mav = new ModelAndView("showProjectTypes"); List<ProjectType> projectTypes = userService.getAllProjectTypes(); mav.addObject("SEARCH_PROJECTTYPE_RESULTS_KEY", projectTypes); return mav; } @RequestMapping(value = "/addProjectType",method=RequestMethod.GET) protected ModelAndView newProjectTypeForm(){ ModelAndView mav = new ModelAndView("newProjectType"); ProjectType projectType = new ProjectType(); mav.getModelMap().put("newProjectType", projectType); return mav; } @RequestMapping(value = "/saveProjectType",method=RequestMethod.POST) protected String addProjectType(@ModelAttribute("newProjectType")ProjectType projectType,BindingResult result,SessionStatus status){ //return userService.addProjectType(projectType, result, status); return userService.addProjectType(projectType); } } 3.3 DAO层 @Component("userDao") public class UserDaoImpl implements UserDao{ @Autowired private SessionFactory sessionFactory; public ProjectType getById(int id) { return (ProjectType) sessionFactory.getCurrentSession().get(ProjectType.class, id); } @Override public String userLogin(UserModel user) { return "123456"; } //获取数据 @Override @SuppressWarnings("unchecked") public List<ProjectType> getAllProjectTypes() { Criteria ceriteria = sessionFactory.getCurrentSession().createCriteria(ProjectType.class); return ceriteria.list(); } //新增数据; @Override // @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public int save(ProjectType projectType) { System.out.println("save:---"); System.out.println(projectType.getIndex()); System.out.println(projectType.getProjectType()); System.out.println(projectType.getProjectTypeAbbr()); return (Integer) sessionFactory.getCurrentSession().save(projectType); } }
springMVC注入失败的问题
运行项目后报错,请问我配置哪里写错了? ``` ERROR [localhost-startStop-1] - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'categoryController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.how2java.service.CategoryService com.how2java.controller.CategoryController.categoryService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'categoryService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.how2java.mapper.CategoryMapper com.how2java.service.impl.CategoryServiceImpl.categoryMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.how2java.mapper.CategoryMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} ina.core.StandardWrapper.initServlet(StandardWrapper.java:1227) ``` web.xml ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <!-- spring的配置文件--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- spring mvc核心:分发servlet --> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- spring mvc的配置文件 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springMVC.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> ``` springMVC.xml ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <context:annotation-config/> <context:component-scan base-package="com.how2java.controller" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <mvc:annotation-driven /> <mvc:default-servlet-handler /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans> ``` applicationContext.xml ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>123456</value> </property> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="commonSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:elecDBConfiguration.xml" /> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="warehouse" expression="execution (* com.how2java.service.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="warehouse" /> </aop:config> </beans> ``` elecDBConfiguration.xml ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <typeAliases> <typeAlias alias="Category" type="com.how2java.pojo.Category" /> </typeAliases> <mappers> <mapper resource="com/how2java/mapper/Category.xml"/> </mappers> </configuration> ``` java代码 ``` package com.how2java.pojo; public class Category { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "Category [id=" + id + ", name=" + name + "]"; } } ``` ``` package com.how2java.service; import java.util.List; import com.how2java.pojo.Category; public interface CategoryService { List<Category> list(); } ``` ``` package com.how2java.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.how2java.mapper.CategoryMapper; import com.how2java.pojo.Category; import com.how2java.service.CategoryService; @Service("categoryService") public class CategoryServiceImpl implements CategoryService{ @Autowired CategoryMapper categoryMapper; public List<Category> list(){ return categoryMapper.list(); }; } ``` ``` package com.how2java.controller; 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.servlet.ModelAndView; import com.how2java.pojo.Category; import com.how2java.service.CategoryService; // 告诉spring mvc这是一个控制器类 @Controller @RequestMapping("") public class CategoryController { @Autowired CategoryService categoryService; @RequestMapping("listCategory") public ModelAndView listCategory(){ ModelAndView mav = new ModelAndView(); List<Category> cs= categoryService.list(); // 放入转发参数 mav.addObject("cs", cs); // 放入jsp路径 mav.setViewName("listCategory"); return mav; } } ```
There is no Action mapped for namespace
使用的是J2EE+SHH框架, 具体代码如下: --- **struts.xml** ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.custom.i18n.resources" value="message" /> <constant name="struts.i18n.encoding" value="UTF-8" /> <!-- 指定Struts 2默认的ObjectFactory Bean - 交给Spring管理 --> <constant name="struts.objectFactory" value="spring" /> <!-- 开发者模式 --> <!-- <constant name="struts.devMode" value="true" /> --> <!-- 指定每次配置文件更改后,自动重新加载 --> <constant name="struts.configuration.xml.reload" value="false" /> </struts> ``` --- **applicationContext.xml** ``` **<?xml version="1.0" encoding="UTF-8"?> <!-- context是自动扫描和使用注解的上下文前缀;aop,tx是事物管理的前缀 -->** <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd" default-autowire="byName"> <!-- 采用自动扫描的方式查找bean(DAO,Service等等),多个用逗号隔开 --> <context:component-scan base-package="com.cheer.bookshop" /> <!-- 定时器任务 --> <task:annotation-driven /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <description>配置数据源</description> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/bookstore?useUnicode=true&amp;characterEncoding=UTF-8"></property> <property name="username" value="root"></property> <property name="password" value="123456"></property> <!-- 初始化连接数量 --> <property name="initialSize" value="1"/> <!-- 最大活动连接数量,一般等于数据库的最大并发数 --> <property name="maxActive" value="100"/> <!-- 最大空闲(等待)连接数量 --> <property name="maxIdle" value="-1"/> <!-- 最小空闲(等待)连接数量 --> <property name="minIdle" value="0"/> <!-- 获取连接时等待时间,超出将抛异常,单位毫秒 --> <property name="maxWait" value="10000"/> </bean> <!-- 配置hibernate session工厂 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <description>将数据源注入到sessionFactory,使用注解方式</description> <property name="dataSource" ref="dataSource"></property> <!-- 配置hibernate的一些属性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.connection.release_mode">after_transaction</prop><!-- 释放session --> </props> </property> <!-- 自动扫描注解方式配置的hibernate映射文件(实体类) --> <property name="packagesToScan"> <list> <value>com.cheer.bookshop.Model</value> </list> </property> </bean> <!-- 定义事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <description> 增加事务管理</description> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 拦截器方式配置事务特性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <!-- 给business配置事务管理 --> <aop:config proxy-target-class="true"> <aop:pointcut id="allManagerMethod" expression="execution (* com.cheer.bookshop.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" /> </aop:config> </beans> ``` --- **JSP页面登陆Form表单** ``` <s:form action="userlogin.action" method="post"> <p><font color="red">&nbsp;&nbsp;&nbsp;${msg}</font></p> <div class="form_row"> <label class="contact"><strong>Username:</strong></label> <input type="text" class="contact_input" name="user.username" value="${user.username}"/> </div> <div class="form_row"> <label class="contact"><strong>Password:</strong></label> <input type="password" class="contact_input" name="user.password" value="${user.password}"/> </div> <div class="form_row"> <div class="terms"> <input type="checkbox" name="terms" /> Remember me </div> </div> <div class="form_row"> <input type="submit" class="register" value="login" /> </div> </s:form> ``` --- **Action类** ``` package com.cheer.bookshop.action; import java.io.IOException; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.Result; import com.cheer.bookshop.Model.User; import com.cheer.bookshop.service.impl.UserServiceImpl; import com.opensymphony.xwork2.ActionSupport; @Namespace("/") public class UserAction extends ActionSupport { @Resource private UserServiceImpl userServiceImpl; private User user; private String msg; //用户登录 @Action(value = "userlogin", results = {@Result(name = "success", location = "/index.jsp"), @Result(name = "input", location = "/jsp/user/myaccount.jsp", type = "redirect") }) public String login(){ User userdb = userServiceImpl.login(user.getUsername()); if(userdb != null){ String password = user.getPassword(); if(password.equals(userdb.getPassword())){ user=userdb; return SUCCESS; }else{ msg="密码错误,请重新输入!"; return INPUT; } }else{ msg="用户名不存在,请注册!"; return INPUT; } } //用户注册 @Action(value = "userregister", results = {@Result(name = "success", location = "/jsp/user/myaccount.jsp", type = "redirect") }) public String register(){ userServiceImpl.register(user); return SUCCESS; } //验证用户名是否已经被使用 @Action(value = "validateUsername") public String validateUsername() throws IOException{ HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=UTF-8"); String username = request.getParameter("username"); boolean flag = userServiceImpl.validateUsername(username); if(flag){ response.getWriter().println("<p><font color='red'>用户名已经存在</font></p>"); }else{ response.getWriter().println("<p><font color='green'>用户名可以使用</font></p>"); } return NONE; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } } ``` --- 如上,Action有配置userlogin,登陆页form表单提交路径也是一样,单就是无法调整至aciton里,eclipse也没有报错,该如何解决? There is no Action mapped for namespace / and action name userlogin.
有关Tomcat出错信息,求帮忙,看看是哪里的问题
十月 27, 2017 11:01:01 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin 警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:LostFound' did not find a matching property. 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server version: Apache Tomcat/9.0.0.M26 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server built: Aug 2 2017 20:29:05 UTC 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server number: 9.0.0.0 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Name: Windows 10 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS Version: 10.0 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Architecture: amd64 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Java Home: C:\Program Files\Java\jdk1.8.0_73\jre 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Version: 1.8.0_73-b02 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM Vendor: Oracle Corporation 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_BASE: D:\eclipse see\.metadata\.plugins\org.eclipse.wst.server.core\tmp1 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_HOME: D:\apache-tomcat-9.0.0.M26 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.base=D:\eclipse see\.metadata\.plugins\org.eclipse.wst.server.core\tmp1 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dcatalina.home=D:\apache-tomcat-9.0.0.M26 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dwtp.deploy=D:\eclipse see\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Djava.endorsed.dirs=D:\apache-tomcat-9.0.0.M26\endorsed 十月 27, 2017 11:01:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Command line argument: -Dfile.encoding=UTF-8 十月 27, 2017 11:01:01 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_73\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;D:/java/bin/server;D:/java/bin;D:/java/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_73\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\mysql\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\sqlserver\100\Tools\Binn\;D:\sqlserver\100\DTS\Binn\;D:\sqlserver\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users\Administrator\Desktop;;.] 十月 27, 2017 11:01:02 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-nio-8080"] 十月 27, 2017 11:01:02 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 信息: Using a shared selector for servlet write/read 十月 27, 2017 11:01:02 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["ajp-nio-8009"] 十月 27, 2017 11:01:02 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 信息: Using a shared selector for servlet write/read 十月 27, 2017 11:01:02 下午 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 4243 ms 十月 27, 2017 11:01:02 下午 org.apache.catalina.core.StandardService startInternal 信息: Starting service [Catalina] 十月 27, 2017 11:01:02 下午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/9.0.0.M26 十月 27, 2017 11:01:03 下午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom 警告: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [186] milliseconds. 十月 27, 2017 11:01:04 下午 org.apache.jasper.servlet.TldScanner scanJars 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. 十月 27, 2017 11:01:05 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-nio-8080"] 十月 27, 2017 11:01:06 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-nio-8009"] 十月 27, 2017 11:01:06 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 3497 ms 没有提示代码出错,看信息意思是没有匹配到属性,还有路径找不到什么的,应该怎么解决
Spring + Hibernate4 无法将数据写入数据【请教】
<div class="iteye-blog-content-contain" style="font-size: 14px;"> <p class="MsoNormal" style="text-align: center;" align="center"> </p> <p class="MsoNormal"><span lang="EN-US"> 问题:</span></p> <p class="MsoNormal"><span lang="EN-US">通过Junit单元测试Service可以将数据写入数据库;但部署却无法向数据库写入数据。</span></p> <h1> <strong><span lang="EN-US">1、</span></strong><span lang="EN-US"><strong>环境</strong>:</span> </h1> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><span lang="EN-US">Spring 3.1.2</span></p> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><span lang="EN-US">Hibernate 4.1.4</span></p> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><span lang="EN-US">Jdk1.6</span></p> <h1>2、配置:</h1> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">1<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">2<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <h2> <span lang="EN-US">2.1、</span><span lang="EN-US">Web.xml</span> </h2> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;?</span><span lang="EN-US">xml</span><span lang="EN-US"> <span lang="EN-US">version</span>=<em><span lang="EN-US">"1.0"</span></em> <span lang="EN-US">encoding</span>=<em><span lang="EN-US">"UTF-8"</span></em><span lang="EN-US">?&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;</span><span lang="EN-US">web-app</span><span lang="EN-US"> <span lang="EN-US">xmlns:xsi</span>=<em><span lang="EN-US">"http://www.w3.org/2001/XMLSchema-instance"</span></em> <span lang="EN-US">xmlns</span>=<em><span lang="EN-US">"http://java.sun.com/xml/ns/javaee"</span></em> <span lang="EN-US">xmlns:web</span>=<em><span lang="EN-US">"http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"</span></em> <span lang="EN-US">xsi:schemaLocation</span>=<em><span lang="EN-US">"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"</span></em> <span lang="EN-US">id</span>=<em><span lang="EN-US">"WebApp_ID"</span></em> <span lang="EN-US">version</span>=<em><span lang="EN-US">"2.5"</span></em><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;</span><span lang="EN-US">display-name</span><span lang="EN-US">&gt;</span><span style="text-decoration: underline;"><span lang="EN-US">springmvc</span></span><span lang="EN-US">&lt;/</span><span lang="EN-US">display-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;</span><span lang="EN-US">welcome-file-list</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span><span lang="EN-US">index.html</span><span lang="EN-US">&lt;/</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span><span lang="EN-US">index.htm</span><span lang="EN-US">&lt;/</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span><span lang="EN-US">index.jsp</span><span lang="EN-US">&lt;/</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;/</span><span lang="EN-US">welcome-file-list</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;!-- Spring ApplicationContext</span><span lang="EN-US">配置文件的路径</span><span lang="EN-US">,</span><span lang="EN-US">可使用通配符</span><span lang="EN-US">,</span><span lang="EN-US">多个路径用</span><span lang="EN-US">,</span><span lang="EN-US">号分隔</span><span lang="EN-US">此参数用于后面的</span><span lang="EN-US">Spring Context Loader --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;</span><span lang="EN-US">context-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">contextConfigLocation</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span style="text-decoration: underline;"><span lang="EN-US">classpath</span></span><span lang="EN-US">*:/applicationContext.xml</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;/</span><span lang="EN-US">context-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">listener</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">listener-class</span><span lang="EN-US">&gt;</span><span lang="EN-US">org.springframework.web.context.ContextLoaderListener</span><span lang="EN-US">&lt;/</span><span lang="EN-US">listener-class</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">listener</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!--<span style="text-decoration: underline;">Dispathcer</span> <span style="text-decoration: underline;">Servlet</span> --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">spring-<span style="text-decoration: underline;">mvc</span></span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet-class</span><span lang="EN-US">&gt;</span><span lang="EN-US">org.springframework.web.servlet.DispatcherServlet</span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet-class</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">contextConfigLocation</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span lang="EN-US">/WEB-INF/spring-mvc.xml</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;/</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">load-on-startup</span><span lang="EN-US">&gt;</span><span lang="EN-US">1</span><span lang="EN-US">&lt;/</span><span lang="EN-US">load-on-startup</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Spring MVC <span style="text-decoration: underline;">Servlet</span> </span><span lang="EN-US">拦截</span><span lang="EN-US">.do</span><span lang="EN-US">结尾的请求</span><span lang="EN-US">--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">spring-<span style="text-decoration: underline;">mvc</span></span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span><span lang="EN-US">*.do</span><span lang="EN-US">&lt;/</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Filter </span><span lang="EN-US">定义</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">encodingFilter</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-class</span><span lang="EN-US">&gt;</span><span lang="EN-US">org.springframework.web.filter.CharacterEncodingFilter</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-class</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">encoding</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span lang="EN-US">UTF-8</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;/</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">forceEncoding</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span lang="EN-US">true</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;/</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">encodingFilter</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span><span lang="EN-US">/*</span><span lang="EN-US">&lt;/</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">   </span><span lang="EN-US">&lt;!--openSessionInView--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">   </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">openSessionInView</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-class</span><span lang="EN-US">&gt;</span><span lang="EN-US">org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-class</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">sessionFactoryBeanName</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span lang="EN-US">sessionFactory</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;/</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">openSessionInView</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span><span lang="EN-US">/*</span><span lang="EN-US">&lt;/</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><span lang="EN-US">&lt;/</span><span lang="EN-US">web-app</span><span lang="EN-US">&gt;</span></p> <h2> <span lang="EN-US">2.2<span lang="EN-US">     </span></span><span lang="EN-US">applicationContext.xml</span> </h2> <p class="MsoNormal"><span lang="EN-US">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">          &lt;!--</span><span lang="EN-US">扫描并自动装配</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:annotation-config /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:component-scan base-package="com.sp" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">   &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="locations"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;value&gt;classpath:application.properties&lt;/value&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;/property&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">   &lt;!-- </span><span lang="EN-US">数据源配置</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">    &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;!-- Connection Info --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="driverClassName" value="${jdbc.driver}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="url" value="${jdbc.url}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="username" value="${jdbc.username}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="password" value="${jdbc.password}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;!-- Connection Pooling Info --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="maxActive" value="${dbcp.maxActive}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="maxIdle" value="${dbcp.maxIdle}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="defaultAutoCommit" value="false" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        </span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;!-- </span><span lang="EN-US">连接</span><span lang="EN-US">Idle</span><span lang="EN-US">一个小时后超时</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="timeBetweenEvictionRunsMillis" value="3600000" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="minEvictableIdleTimeMillis" value="3600000" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">    &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;              </span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="hibernateProperties"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;props&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.connection.autocommit"&gt;true&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.current_session_context_class"&gt;org.springframework.orm.hibernate4.SpringSessionContext&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;/props&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;/property&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   </span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="packagesToScan"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;list&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;value&gt;com.sp.dao&lt;/value&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;value&gt;com.sp.entity.dict&lt;/value&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;/list&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;/property&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" abstract="false" lazy-init="default" autowire="default"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="sessionFactory"&gt;&lt;ref bean="sessionFactory" /&gt;&lt;/property&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">事务管理配置</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!--&lt;tx:annotation-driven transaction-manager="transactionManager"&gt;&lt;/tx:annotation-driven&gt;--&gt; </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;tx:attributes&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;tx:method name="insert*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;tx:method name="get*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">            &lt;tx:method name="add*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">            &lt;tx:method name="update*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">            &lt;tx:method name="delete*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;/tx:attributes&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/tx:advice&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;aop:config&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;aop:advisor pointcut="execution(* com.sp.service.*.*(..))"  advice-ref="txAdvice"/&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/aop:config&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;/beans&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <h2> <span lang="EN-US">2.3<span lang="EN-US"> </span></span><span lang="EN-US">spring-mvc.xml</span> </h2> <p class="MsoNormal"><span lang="EN-US">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</span></p> <p class="MsoNormal"><span lang="EN-US">         xmlns:context="http://www.springframework.org/schema/context"</span></p> <p class="MsoNormal"><span lang="EN-US">         xmlns:mvc="http://www.springframework.org/schema/mvc"</span></p> <p class="MsoNormal"><span lang="EN-US">         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd</span></p> <p class="MsoNormal"><span lang="EN-US">                   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd</span></p> <p class="MsoNormal"><span lang="EN-US">        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">启动注解驱动的</span><span lang="EN-US">SpringMVC</span><span lang="EN-US">功能,注册请求</span><span lang="EN-US">URL</span><span lang="EN-US">和注解</span><span lang="EN-US">POJO</span><span lang="EN-US">类方法的映射</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;mvc:annotation-driven /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">自动扫描且只扫描</span><span lang="EN-US">@Controller --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:component-scan base-package="com.sp.web" use-default-filters="false"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/context:component-scan&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:component-scan base-package="com.sp.dao.impl"&gt;&lt;/context:component-scan&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:component-scan base-package="com.sp.service.impl"&gt;&lt;/context:component-scan&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;mvc:default-servlet-handler /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">对模型视图名称的解析,在请求时模型视图名称添加后缀。定义</span><span lang="EN-US">JSP --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="prefix" value="/WEB-INF/views/" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="suffix" value=".jsp" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">支持上传文件</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;/beans&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <h2> <span lang="EN-US">2.4<span lang="EN-US">  </span></span><span lang="EN-US">hibernate.cfg.xml</span> </h2> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;?</span><span lang="EN-US">xml</span><span lang="EN-US"> <span lang="EN-US">version</span>=<em><span lang="EN-US">'1.0'</span></em> <span lang="EN-US">encoding</span>=<em><span lang="EN-US">'utf-8'</span></em><span lang="EN-US">?&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;!</span><span lang="EN-US">DOCTYPE</span><span lang="EN-US"> <span lang="EN-US">hibernate-configuration</span> <span lang="EN-US">PUBLIC</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     <span lang="EN-US">"-//Hibernate/Hibernate Configuration DTD 3.0//EN"</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     <span lang="EN-US">"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;</span><span lang="EN-US">hibernate-configuration</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">  </span><span lang="EN-US">&lt;</span><span lang="EN-US">session-factory</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Database connection settings--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.driver_class"</span></em><span lang="EN-US">&gt;</span>com.mysql.jdbc.Driver<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.url"</span></em><span lang="EN-US">&gt;</span>jdbc:mysql://<span style="text-decoration: underline;">localhost</span>:3306/test<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.username"</span></em><span lang="EN-US">&gt;</span>root<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.password"</span></em><span lang="EN-US">&gt;</span>password<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- JDBC connection pool (use the built-in) --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.pool_size"</span></em><span lang="EN-US">&gt;</span>1<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- SQL dialect </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Enable Hibernate's automatic session context management --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt; --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Disable the second-level cache  --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Echo all executed SQL to <span style="text-decoration: underline;">stdout</span> --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"show_sql"</span></em><span lang="EN-US">&gt;</span>true<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"format_sql"</span></em><span lang="EN-US">&gt;</span>true<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Drop and re-create the database schema on startup--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"hbm2ddl.auto"</span></em><span lang="EN-US">&gt;</span>update<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"javax.persistence.validation.mode"</span></em><span lang="EN-US">&gt;</span>none<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">  </span><span lang="EN-US">&lt;/</span><span lang="EN-US">session-factory</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;/</span><span lang="EN-US">hibernate-configuration</span><span lang="EN-US">&gt;</span></p> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><strong><span lang="EN-US"> </span></strong></p> <h1> <span lang="EN-US">3<span lang="EN-US">         </span></span><span lang="EN-US">代码:</span> </h1> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">1<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">2<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">3<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <h2> <span lang="EN-US">3.1<span lang="EN-US">  </span></span><span lang="EN-US">Service</span><span lang="EN-US">层:</span> </h2> <p class="MsoNormal" align="left"><span lang="EN-US">@Component</span><span lang="EN-US">(</span><span lang="EN-US">"userService"</span><span lang="EN-US">)</span></p> <p class="MsoNormal" align="left"><strong><span lang="EN-US">public</span></strong><strong><span lang="EN-US">class</span></strong><span lang="EN-US"> UserServiceImpl </span><strong><span lang="EN-US">implements</span></strong><span lang="EN-US"> UserService{</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@<span lang="EN-US">Autowired</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">private</span></strong><span lang="EN-US"> UserDao </span><span lang="EN-US">userDao</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@<span lang="EN-US">Autowired</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">private</span></strong><span lang="EN-US"> FormValidator </span><span lang="EN-US">validator</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@Override</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">public</span></strong><span lang="EN-US"> String userLogin(UserModel user) {</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       String password = </span><span lang="EN-US">userDao</span><span lang="EN-US">.userLogin(user);</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">if</span></strong><span lang="EN-US">(password.equals(user.getPassword())){</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"sucess"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       }</span><strong><span lang="EN-US">else</span></strong><span lang="EN-US">{</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"false"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@Override</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">public</span></strong><span lang="EN-US"> List&lt;ProjectType&gt; getAllProjectTypes(){</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       List&lt;ProjectType&gt; projectType = </span><span lang="EN-US">userDao</span><span lang="EN-US">.getAllProjectTypes();</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US"> projectType;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">//</span><span lang="EN-US">添加《项目类型》</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@Override</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">public</span></strong><span lang="EN-US"> String addProjectType(</span><span lang="EN-US">@ModelAttribute</span><span lang="EN-US">(</span><span lang="EN-US">"newProjectType"</span><span lang="EN-US">)ProjectType projectType,BindingResult result,SessionStatus status){</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">validator</span><span lang="EN-US">.validate(projectType, result);</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">if</span></strong><span lang="EN-US">(result.hasErrors()){</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"newProjectType"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">userDao</span><span lang="EN-US">.save(projectType);</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">//status.setComplete();</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"redirect:showProjectTypes.do"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">//</span><span lang="EN-US">添加《项目类型》</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@Override</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">public</span></strong><span lang="EN-US"> String addProjectType(ProjectType projectType) {</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">userDao</span><span lang="EN-US">.save(projectType);</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"redirect:showProjectTypes.do"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    }</span></p> <p class="MsoNormal"><span lang="EN-US">}</span></p> <h2> <span lang="EN-US">3.2<span lang="EN-US">   </span></span><span lang="EN-US">Control</span><span lang="EN-US">层</span> </h2> <p class="MsoNormal"><span lang="EN-US">@Controller</span></p> <p class="MsoNormal"><span lang="EN-US">@RequestMapping(value = "/user")</span></p> <p class="MsoNormal"><span lang="EN-US">public class UserController {</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         @Autowired</span></p> <p class="MsoNormal"><span lang="EN-US">         private UserService userService;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">    @Autowired</span></p> <p class="MsoNormal"><span lang="EN-US">    private FormValidator validator;</span></p> <p class="MsoNormal"><span lang="EN-US">    </span></p> <p class="MsoNormal"><span lang="EN-US">         @RequestMapping(value = "/login",method=RequestMethod.POST)</span></p> <p class="MsoNormal"><span lang="EN-US">         protected String handle(UserModel user,BindingResult result, Model model){</span></p> <p class="MsoNormal"><span lang="EN-US">                   String flag = userService.userLogin(user);</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println("flag:" + flag);</span></p> <p class="MsoNormal"><span lang="EN-US">                   if ("sucess".equals(flag)){</span></p> <p class="MsoNormal"><span lang="EN-US">                            return "sucess";</span></p> <p class="MsoNormal"><span lang="EN-US">                   }</span></p> <p class="MsoNormal"><span lang="EN-US">                   return "test1";</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         @RequestMapping(value = "/showProjectTypes")</span></p> <p class="MsoNormal"><span lang="EN-US">         protected ModelAndView getAllProjectTypes(){</span></p> <p class="MsoNormal"><span lang="EN-US">                   ModelAndView mav = new ModelAndView("showProjectTypes");</span></p> <p class="MsoNormal"><span lang="EN-US">                   List&lt;ProjectType&gt; projectTypes = userService.getAllProjectTypes();</span></p> <p class="MsoNormal"><span lang="EN-US">                   mav.addObject("SEARCH_PROJECTTYPE_RESULTS_KEY", projectTypes);</span></p> <p class="MsoNormal"><span lang="EN-US">                   return mav;</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         @RequestMapping(value = "/addProjectType",method=RequestMethod.GET)</span></p> <p class="MsoNormal"><span lang="EN-US">         protected ModelAndView newProjectTypeForm(){</span></p> <p class="MsoNormal"><span lang="EN-US">                   ModelAndView mav = new ModelAndView("newProjectType");</span></p> <p class="MsoNormal"><span lang="EN-US">                   ProjectType projectType = new ProjectType();</span></p> <p class="MsoNormal"><span lang="EN-US">                   mav.getModelMap().put("newProjectType", projectType);</span></p> <p class="MsoNormal"><span lang="EN-US">                   return mav;</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         @RequestMapping(value = "/saveProjectType",method=RequestMethod.POST)</span></p> <p class="MsoNormal"><span lang="EN-US">         protected String addProjectType(@ModelAttribute("newProjectType")ProjectType projectType,BindingResult result,SessionStatus status){</span></p> <p class="MsoNormal"><span lang="EN-US">                   //return userService.addProjectType(projectType, result, status);</span></p> <p class="MsoNormal"><span lang="EN-US">                   return userService.addProjectType(projectType);</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US">}</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <h2> <span lang="EN-US">3.3<span lang="EN-US">    </span></span><span lang="EN-US">DAO</span><span lang="EN-US">@Component("userDao")</span> </h2> <p class="MsoNormal"><span lang="EN-US">public class UserDaoImpl implements UserDao{</span></p> <p class="MsoNormal"><span lang="EN-US">         @Autowired</span></p> <p class="MsoNormal"><span lang="EN-US">         private SessionFactory sessionFactory;</span></p> <p class="MsoNormal"><span lang="EN-US">    </span></p> <p class="MsoNormal"><span lang="EN-US">    public ProjectType getById(int id)</span></p> <p class="MsoNormal"><span lang="EN-US">    {</span></p> <p class="MsoNormal"><span lang="EN-US">        return (ProjectType) sessionFactory.getCurrentSession().get(ProjectType.class, id);</span></p> <p class="MsoNormal"><span lang="EN-US">    }</span></p> <p class="MsoNormal"><span lang="EN-US">    </span></p> <p class="MsoNormal"><span lang="EN-US">         @Override</span></p> <p class="MsoNormal"><span lang="EN-US">         public String userLogin(UserModel user) {</span></p> <p class="MsoNormal"><span lang="EN-US">                   return "123456";</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         //</span><span lang="EN-US">获取数据</span></p> <p class="MsoNormal"><span lang="EN-US">         @Override</span></p> <p class="MsoNormal"><span lang="EN-US">         @SuppressWarnings("unchecked")</span></p> <p class="MsoNormal"><span lang="EN-US">         public List&lt;ProjectType&gt; getAllProjectTypes() {</span></p> <p class="MsoNormal"><span lang="EN-US">                   Criteria ceriteria = sessionFactory.getCurrentSession().createCriteria(ProjectType.class);</span></p> <p class="MsoNormal"><span lang="EN-US">                   return ceriteria.list();</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         //</span><span lang="EN-US">新增数据;</span></p> <p class="MsoNormal"><span lang="EN-US">         @Override</span></p> <p class="MsoNormal"><span lang="EN-US">//      @Transactional(readOnly = true, propagation = Propagation.REQUIRED)</span></p> <p class="MsoNormal"><span lang="EN-US">         public int save(ProjectType projectType) {</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println("save:---");</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println(projectType.getIndex());</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println(projectType.getProjectType());</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println(projectType.getProjectTypeAbbr());</span></p> <p class="MsoNormal"><span lang="EN-US">                   </span></p> <p class="MsoNormal"><span lang="EN-US">                   return (Integer) sessionFactory.getCurrentSession().save(projectType);</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p> </p> <p class="MsoNormal"><span lang="EN-US">}</span></p> </div>
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、PDF搜索网站推荐 对于大部
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
Vue + Spring Boot 项目实战(十四):用户认证方案与完善的访问拦截
本篇文章主要讲解 token、session 等用户认证方案的区别并分析常见误区,以及如何通过前后端的配合实现完善的访问拦截,为下一步权限控制的实现打下基础。
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入  假设现有4个人
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 目录一、杨辉三角的介绍二、杨辉三角的算法思想三、代码实现1.第一种写法2.第二种写法 一、杨辉三角的介绍 百度
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
SQL-小白最佳入门sql查询一
一 说明 如果是初学者,建议去网上寻找安装Mysql的文章安装,以及使用navicat连接数据库,以后的示例基本是使用mysql数据库管理系统; 二 准备前提 需要建立一张学生表,列分别是id,名称,年龄,学生信息;本示例中文章篇幅原因SQL注释略; 建表语句: CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // dosho
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,
程序员:我终于知道post和get的区别
IT界知名的程序员曾说:对于那些月薪三万以下,自称IT工程师的码农们,其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居,但只是他们一厢情愿罢了。 此话一出,不知激起了多少(码农)程序员的愤怒,却又无可奈何,于是码农问程序员。 码农:你知道get和post请求到底有什么区别? 程序员:你看这篇就知道了。 码农:你月薪三万了? 程序员:嗯。 码农:你是怎么做到的? 程序员:
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
      11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员
Android 9.0系统新特性,对刘海屏设备进行适配
其实Android 9.0系统已经是去年推出的“老”系统了,这个系统中新增了一个比较重要的特性,就是对刘海屏设备进行了支持。一直以来我也都有打算针对这个新特性好好地写一篇文章,但是为什么直到拖到了Android 10.0系统都发布了才开始写这篇文章呢?当然,一是因为我这段时间确实比较忙,今年几乎绝大部分的业余时间都放到写新书上了。但是最主要的原因并不是这个,而是因为刘海屏设备的适配存在一定的特殊性
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI 算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC
【技巧总结】位运算装逼指南
位算法的效率有多快我就不说,不信你可以去用 10 亿个数据模拟一下,今天给大家讲一讲位运算的一些经典例子。不过,最重要的不是看懂了这些例子就好,而是要在以后多去运用位运算这些技巧,当然,采用位运算,也是可以装逼的,不信,你往下看。我会从最简单的讲起,一道比一道难度递增,不过居然是讲技巧,那么也不会太难,相信你分分钟看懂。 判断奇偶数 判断一个数是基于还是偶数,相信很多人都做过,一般的做法的代码如下
日均350000亿接入量,腾讯TubeMQ性能超过Kafka
整理 | 夕颜出品 | AI科技大本营(ID:rgznai100) 【导读】近日,腾讯开源动作不断,相继开源了分布式消息中间件TubeMQ,基于最主流的 OpenJDK8开发的
8年经验面试官详解 Java 面试秘诀
    作者 | 胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车? 某胡同口的煎饼摊一年能卖出多少个煎饼? 深圳有多少个产品经理? 一辆公交车里能装下多少个乒乓球? 一
碎片化的时代,如何学习
今天周末,和大家聊聊学习这件事情。 在如今这个社会,我们的时间被各类 APP 撕的粉碎。 刷知乎、刷微博、刷朋友圈; 看论坛、看博客、看公号; 等等形形色色的信息和知识获取方式一个都不错过。 貌似学了很多,但是却感觉没什么用。 要解决上面这些问题,首先要分清楚一点,什么是信息,什么是知识。 那什么是信息呢? 你一切听到的、看到的,都是信息,比如微博上的明星出轨、微信中的表情大战、抖音上的...
so easy! 10行代码写个"狗屁不通"文章生成器
前几天,GitHub 有个开源项目特别火,只要输入标题就可以生成一篇长长的文章。背后实现代码一定很复杂吧,里面一定有很多高深莫测的机器学习等复杂算法不过,当我看了源代码之后这程序不到50
知乎高赞:中国有什么拿得出手的开源软件产品?(整理自本人原创回答)
知乎高赞:中国有什么拿得出手的开源软件产品? 在知乎上,有个问题问“中国有什么拿得出手的开源软件产品(在 GitHub 等社区受欢迎度较好的)?” 事实上,还不少呢~ 本人于2019.7.6进行了较为全面的 回答 - Bravo Yeung,获得该问题下回答中得最高赞(236赞和1枚专业勋章),对这些受欢迎的 Github 开源项目分类整理如下: 分布式计算、云平台相关工具类 1.SkyWalk
相关热词 c# 图片上传 c# gdi 占用内存 c#中遍历字典 c#控制台模拟dos c# 斜率 最小二乘法 c#进程延迟 c# mysql完整项目 c# grid 总行数 c# web浏览器插件 c# xml 生成xsd
立即提问