关于jdbcTemplate的查询方法

String sql="xxxxxxxxx";
jdbcTemplate.query(sql,new Object[]{id},new RowCallbackHandler(){
public void processRow(ResultSet rs) throws SQLException {
//操作内容
system.out.println("XXXXXX");
}
});
如果sql语句正确,但查询不出结果,那么会打印XXXXXX吗

2个回答

使用JdbcTemplate进行查询时,可以使用queryForXXX()等方法
 
1   jdbcTemplate.queryForInt()
和 jdbcTemplate.queryForLong()
 
例如下面使用queryForInt()方法传回user表中的记录数:
 
jdbcTemplate.queryForIn......
答案就在这里:JdbcTemplate 查询方法
----------------------Hi,地球人,我是问答机器人小S,上面的内容就是我狂拽酷炫叼炸天的答案,除了赞同,你还有别的选择吗?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
spring jdbcTemplate 的 queryForRowSet方法
在Dao层用jdbcTemplate执行单表查询,数据库表暂时是空的,进行查询,本地用时100MS左右,而发布到服务器上却长达6000ms。用queryForList没事儿。之前也用过queryForRowSet未发现这类问题。用pl/sql执行sql语句依然很快。求同行是否发现过此类问题。谢谢
请教各位大牛,jdbcTemplate空指针异常
Dao层里面有两个方法,查询方法中的jdbcTemplate是可以正常运行的,在增加方法中的jdbcTemplate一直报空指针异常。
spring jdbcTemplate怎么得到新插入数据的主键(varchar2类型)
在网上看到用KeyHelper 可以得到数字类型的主键,但是表的主键guid是varchar类型的,用Spring的jdbcTemplate有什么方法可以得到新插入数据的主键? 用的是Hibernate 数据库是Oracle 求大神帮忙了啊! 不用先插入了,再查询的方法怎么破?
JdbcTemplate查询中的问题
<p>1、数据库表机构如下:</p> <pre name="code" class="sql">/*==============================================================*/ /* Table: function */ /*==============================================================*/ CREATE TABLE `itams`.`function` ( `function_id` VARCHAR(32) NOT NULL, `function_name` VARCHAR(50) NOT NULL, `parent_function_id` VARCHAR(32) NOT NULL, `function_order` INTEGER UNSIGNED, `function_level` INTEGER UNSIGNED, `function_url` VARCHAR(200), `function_remark` TEXT, PRIMARY KEY (`function_id`) ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; </pre> <p><br><br>2、有一个Function.java如下:</p> <pre name="code" class="java">package com.zb.itams.domain; import java.io.Serializable; public class Function implements Serializable { private String functionId; private String functionName; private String parentFunctionId; private int functionOrder; private int functionLevel; private String functionUrl; private String functionRemark; /* JavaBeans Properties */ // 省略setter和getter方法 } </pre> <p><br><br>3、FunctionDaoImpl中的基于Id查询的方法如下:</p> <pre name="code" class="java">public Function getFunction(String functionId) throws DataAccessException { Iterator&lt;Function&gt; iteFunction = jdbcTemplate.queryForList("select * from function where function_id='"+functionId+"'").iterator(); if (iteFunction.hasNext()) { return iteFunction.next(); } else { return null; } } </pre> <p><br>4、打印显示方法中的iteFunction.next()</p> <pre name="code" class="java">{ function_id=8abc8098269d0fd32949d11490e0000, function_name=ss, parent_function_id=8abc8098269c7b4a2949c7b4a010000, function_order=0, function_level=3, function_url=, function_remark=ss } </pre> <p><br>无法强制转换成Function:return (Function)iteFunction.next(); <br>报异常:java.lang.ClassCastException: java.util.LinkedHashMap</p> <p> </p> <p>上网搜了半天,没找到原因和解决方法</p> <p> </p>
spring jdbctemplate 设计的问题
simplespringtemplate 提供了对jdbc的包装,并提供了一些方便的方法,但是在进行选择的时候还是感觉不方便。 <br /> <br />假设有数据表:user ,包含属性 Long id,String name ,int salary,如果我要查询工资为234的用户,设想生成的语句为: <br /><pre name="code" class="java">select * from user where age=234</pre> <br />如果使用jdbctemplate则需要使用如下代码: <br /> <br /><pre name="code" class="java">simplejdbctemplate.queryForObject("select * from user where age =?",new UserMapper(),salary);</pre> <br /> <br />执行的SQL语句为: <br /> <br /><pre name="code" class="java">select * from user where age='234'</pre> <br />这并不是我想生成的sql语句,如果要生成需要的sql语句采用simplejdbctemplate就没有办法实现了,应为没有提供设置preparedstatement设置的方法,在jdbctemplate中也没有针对单独选择一条记录并采用preparedstatement作为参数的方法,感觉用起来不方便,不知道各位有没有好的解决方法? <br /> <br /> <br /><br /><strong>问题补充:</strong><br />一楼提供的方法可以,但是如果有多个参数呢? <br />比如 <br />select * from user where age =? and name=?,应该如何处理,貌似不接受指定多个不同的参数类型:(
java线程中使用mysql连接查询数据库
在一个一直运行的类中,由于匹配到特定的任务就需要做特定的事,这个步骤我打算直接在当前类中创建一个线程new Thread().start();做操作,然后通过线程的构造函数把数据库连接对象jdbcTemplate传过去直接查数据库对结果做处理,这样做符号规范吗,或者有没有什么更好的方法
spring JdbcTemplate批量插入 怎么获得数据库自动增长的id
如下,插入一条记录的时候可以这样返回id(一下代码只是说明事例): [code="java"] //保存一个test对象,并返回该对象 public Test save(Test test){ KeyHolder keyHolder = new GeneratedKeyHolder(); getJdbcTemplate().update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement( Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement("insert into tb_test (name,sex) values (?,?)", Statement.RETURN_GENERATED_KEYS); ps.setString(1, test.getName()); ps.setString(2, test.getSex()); return ps; } }, keyHolder); //这里可以获得数据库id test.setId(Integer.valueOf(keyHolder.getKeyList().get(0) .toString())); return test; } // 批量插入, public List<Test> saveOrUpdateAll(final List<Test> list) { getJdbcTemplate().batchUpdate( "insert into tb_test (name,sex) values (?,?)", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setString(1, list.get(i).getName()); ps.setString(2, list.get(i).getSex()); } @Override public int getBatchSize() { return list.size(); } }); //哪个方法可以获得list中每个test对象的id?我不想重新进行查询 return list; } [/code]
将一个简单的数据库查询部署到Tomcat时java.lang.NoClassDefFoundError: Could not initialize class
在完成一个数据库查询操作部署到Tomcat时报错java.lang.NoClassDefFoundError: Could not initialize class. 在没有使用服务器时,查询功能可以正常运行. 在启动服务器查询时报错 Servlet代码如下: ``` package com.lxl.web.servlet; import com.lxl.smis.dao.impl.IStudentDAO; import com.lxl.smis.dao.impl.StudentDAOImpl; import com.lxl.smis.domain.Student; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; @WebServlet("/student/list") public class ListStudentServlet extends HttpServlet { private IStudentDAO dao; public void init() throws ServletException { dao = new StudentDAOImpl(); } @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //1.接受请求参数,封装对象 //2.调用业务方法处理请求 System.out.println("hello"); List<Student> stus= dao.listAll(); for (Student stu : stus) { System.out.println(stu); } //3.控制界面跳转 } } ``` 错误提示: ![图片说明](https://img-ask.csdn.net/upload/201911/16/1573886138_700745.png) ```16-Nov-2019 15:29:27.029 严重 [http-nio-8080-exec-3] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [com.lxl.web.servlet.ListStudentServlet] in context with path [] threw exception [Servlet execution threw an exception] with root cause java.lang.NoClassDefFoundError: Could not initialize class com.lxl.smis.util.JDBCUtil at com.lxl.smis.util.JDBCTemplate.query(JDBCTemplate.java:73) at com.lxl.smis.dao.impl.StudentDAOImpl.listAll(StudentDAOImpl.java:41) at com.lxl.web.servlet.ListStudentServlet.service(ListStudentServlet.java:28) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) ``` 使用DeBug运行 感觉是这里出现问题,但并不知道到是什么意思 ![图片说明](https://img-ask.csdn.net/upload/201911/16/1573886445_32104.png) 查找网上解决方法 说这个报错的问题原因就是static变量的初始化失败导致 但我如果不用Servlet运行这个查找功能,直接在本地实现这个方法,是可以正常运行的. 请教一下各位大佬,是什么原因? 我是初学JAVA的小白,各位大佬见笑了.
ora-01000 超出打开游标的最大数
这是一个老问题,网上也有很多关于这个问题的原因和解决方法,一般都是说在循环里面使用PrepareStatement或ResultSet后没有及时关闭引起的。 我现在的问题是,我使用的是Sptring的Jdbctemplate来执行查询操作(我也看了Jdbctemplate的代码,甚至将源代码复制出来自己再添加输出信息,确定PerpareStatement确实是有关闭,奇怪的是似乎执行关闭的次数要少于实际执行查询的次数),所以我不能自己调用方法关闭PrepareStatement或ResultSet,那问题应该怎么解决呢? 附功能需求: 查询某些数据点(最大300个左右),在某个时间范围内(最大1年左右),哪一天没有数据。例如:查询300个点,在2013-04-10至2013-04-17日这10天之中,有多少是没有数据的,如果没有任何数据,则返回300*10=3000条数据,且这3000条数据必须有时间,如第1条的内容是“点A在2013-04-10没有数据”,第2条的内容是“点B在2013-04-10没有数据”...第XX条是“点A在2013-04-11没有数据”,以此类推。 上面这需求,除了将具体的时间赋值到SQL语句的查询条件中之外,没有想出其他方法。如果查询1年的时间范围,那就要执行360+条SQL语句,就会出现上面提到的错误。
HibernateTemplate.get获取不到实体对象
1.项目使用的是springmvc+hibernate3注解的方式进行框架搭建的,在applicationContext.xml中配置了sessionFactory: <bean id="jdbcTemplate" class="common.jdbc.JdbcTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> 其中JdbcTemplate是自己写的一个类,继承了HibernateTemplate类,添加使用sql查询的方法。 public class JdbcTemplate extends HibernateTemplate { //查询返回一条数据 public Map queryData(String sql) { Map map = new HashMap(); Session session = this.getSessionFactory().openSession(); List<Map> list = session.createSQLQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list(); if (list.size() > 0) { map = list.get(0); } session.close(); return map; } } 在一个dao中遇到这样的问题 YysXkFjlbEntity fj = new YysXkFjlbEntity(); fj = jdbcTemplate.get(YysXkFjlbEntity.class, yysXkFjlbEntity.getId()); 使用get获取不到对象了,id测试是有值的。 大婶们,指点下
从数据库里读取数据封装到list集合里部分字段显示为null
1.查询语句 ![图片说明](https://img-ask.csdn.net/upload/201701/06/1483666480_521637.png) 2.单元测试及查询结果 ![图片说明](https://img-ask.csdn.net/upload/201701/06/1483666701_422899.png) ![图片说明](https://img-ask.csdn.net/upload/201701/06/1483666714_283698.png) 3.使用SqlServer2008+springboot+JdbcTemplate,数据库中所有字段均有值,但查询结果只有name字段有值,其余均为null,实体类里包含getter、setter、toString方法,想问为什么会出现这种情况,又该如何解决?
使用Spring对Service层进行测试,无法查询到刚刚插入的记录?
如题,本人使用Spring提供的:AbstractTransactionalDataSourceSpringContextTests类对Service层进行测试。测试的方法是向数据库中插入一条用户记录,然后再重新检索出来。代码如下: 【1】DAO层代码: [code="java"] public User saveUser(User newUser) { getHibernateTemplate().save(newUser); //getHibernateTemplate().flush(); return (User) getHibernateTemplate().get(User.class, newUser.getUserId()); } [/code] 【2】Service层代码: [code="java"]public User saveUser(User newUser) throws NewsletterException { try { return userDao.saveUser(newUser); } catch (HibernateObjectRetrievalFailureException he) { throw new ServiceException(systemMessage.getMessage(SERVICE_FAILED) + ": saveUser"); } catch (Exception e) { throw new NewsletterException(e.getMessage()); } }[/code] [code="java"]public User getUserByName(String userName) throws NewsletterException { try { return userDao.getUserByName(userName); } catch (HibernateObjectRetrievalFailureException he) { throw new ServiceException(systemMessage.getMessage(SERVICE_FAILED) + ": userName"); } catch (Exception e) { throw new NewsletterException(e.getMessage()); } }[/code] 【3】测试代码: [code="java"]public void testSaveUser() { User newUser = createUser(); try { userService.saveUser(newUser); assertTrue(true); String sql = "Select USERNAME from NEWSLETTER_USER where UPPER(USERNAME)= ?"; String userName = (String) jdbcTemplate.queryForObject(sql, new Object[] { "PAUL" }, java.lang.String.class); assertNotNull(userName); assertEquals(userName, newUser.getUserName()); } catch (NewsletterException ne) { fail(ne.getMessage()); [/code] } } 【4】Spring配置文件: [code="xml"] <!-- User Service Definition --> <bean id="userServiceTarget" class="com.newsletter.service.impl.UserServiceImpl"> <property name="userDao"> <ref local="userDao" /> </property> <property name="systemMessage"> <ref local="systemMessage" /> </property> </bean> <!-- Transactional proxy for the User Service --> <bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref local="transactionManager" /> </property> <property name="target"> <ref local="userServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> [/code] 【5】测试问题: [color=red]1. 使用上面的测试代码,发现jdbcTemplate.queryForObject方法获取到的结果为空,测试失败。 2. 在testSaveUser方法末尾,即便加上setComplete()方法,发现数据已经插入,但query方法同样返回NULL 3. 假如我使用上面Service层的userService.getUserByName方法进行测试,测试通过 4. 假如我在DAO层的saveUser方法里面加上getHibernateTemplate().flush();测试也通过[/color] [b]请问为什么即便我在测试方法中加上setComplete(),而且数据库中查到了记录,但每次都是返回NULL是什么原因?[/b] [b]问题补充:[/b] 谢谢llade,假如我调用了setComplete()方法,Spring确实是提交了事务的,因为我在数据库中已经查询到相应的记录。 我测试过3种情况的setComplete(),第一种是在saveUser调用之后,第二种是在queryForObject之后,第三种是分别在saveUser和queryForObject之后。 但每次都是同样的结果。
框架新手在整合spring和mvc的tomcat报Injection of autowired dependencies failed;
eclipse版本4.9.0     tomact版本7.0   jdk版本1.8 刚学完spring和springmvc想要整合一下简单的连一下数据库查询一些数据实验一下。tomac运行的时候直接后台报错。具体错误如下: ``` 严重: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helpKeywordController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.service.UserService com.tz.crm.controller.HelpKeywordController.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.dao.UserDao com.tz.crm.service.UserService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:381) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5077) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5591) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.service.UserService com.tz.crm.controller.HelpKeywordController.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.dao.UserDao com.tz.crm.service.UserService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) ... 22 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.dao.UserDao com.tz.crm.service.UserService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1014) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ... 24 more Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.dao.UserDao com.tz.crm.service.UserService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) ... 35 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1014) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ... 37 more Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) ... 48 more Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:967) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ... 50 more 三月 18, 2019 10:22:52 上午 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helpKeywordController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.service.UserService com.tz.crm.controller.HelpKeywordController.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.dao.UserDao com.tz.crm.service.UserService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:381) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5077) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5591) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.service.UserService com.tz.crm.controller.HelpKeywordController.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.dao.UserDao com.tz.crm.service.UserService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) ... 22 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.dao.UserDao com.tz.crm.service.UserService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1014) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ... 24 more Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.tz.crm.dao.UserDao com.tz.crm.service.UserService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) ... 35 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1014) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ... 37 more Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.tz.crm.dao.UserDao.template; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) ... 48 more Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] is defined: expected single matching bean but found 2: org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.JdbcTemplate#1 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:967) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ... 50 more 三月 18, 2019 10:22:52 上午 org.apache.catalina.core.StandardContext startInternal 严重: One or more listeners failed to start. Full details will be found in the appropriate container log file 三月 18, 2019 10:22:52 上午 org.apache.catalina.core.StandardContext startInternal 严重: Context [/ssmvc] startup failed due to previous errors 三月 18, 2019 10:22:52 上午 org.apache.catalina.core.ApplicationContext log 信息: Closing Spring root WebApplicationContext 三月 18, 2019 10:22:52 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-bio-8080"] 三月 18, 2019 10:22:52 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-bio-8009"] 三月 18, 2019 10:22:52 上午 org.apache.catalina.startup.Catalina start 信息: Server startup in 3053 ms ``` 搜索了很多帖子,试了各种方法,但是一直没有解决实际问题。 dao层 ``` import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; import com.tz.crm.bean.HelpKeyword; @Repository public class UserDao { @Autowired private JdbcTemplate template; public List<HelpKeyword> getList() { String sql="select help_keyword_id id,name from help_keyword"; RowMapper<HelpKeyword> rowMapper=new BeanPropertyRowMapper<HelpKeyword>(HelpKeyword.class); List<HelpKeyword> list = template.query(sql, rowMapper); return list; } } ``` service层 ``` package com.tz.crm.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.tz.crm.bean.HelpKeyword; import com.tz.crm.dao.UserDao; @Service public class UserService { @Autowired private UserDao dao; @Transactional(readOnly=true) public List<HelpKeyword> getList() { return dao.getList(); } } ``` controller层 ``` package com.tz.crm.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.bind.annotation.ResponseBody; import com.tz.crm.bean.HelpKeyword; import com.tz.crm.service.UserService; @Controller @RequestMapping("/keyword") public class HelpKeywordController { @Autowired private UserService userService; @RequestMapping("/list") @ResponseBody public List<HelpKeyword> getList() { return userService.getList(); } } ``` spring配置文件 ``` <context:component-scan base-package="com.tz.crm.*"></context:component-scan> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 配置数据源 --> <bean id="comboPooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClass}"/> <property name="jdbcUrl" value="${jdbc.jdbcUrl}"/> <property name="user" value="${jdbc.userName}"/> <property name="password" value="${jdbc.password}"/> </bean> <bean class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="comboPooledDataSource"></property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="comboPooledDataSource"></property> </bean> <!-- 开启基于注解的事务支持 --> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- 配置JdbcTemplate --> <bean class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="comboPooledDataSource"></property> </bean> ``` mvc配置文件 ``` <context:component-scan base-package="com.tz.crm.*"></context:component-scan> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"></property> <property name="suffix" value=".jsp"></property> </bean> <mvc:default-servlet-handler/> <mvc:annotation-driven></mvc:annotation-driven> ``` 连接的数据库是mysql自带的mysql数据库中的help_keyword表 现在手足无措不知道怎么往下进行,希望各位大佬出手相助。 万分感谢!
javaEE连接mysql数据库,然后通过映射把数据显示到网页上,可是没报错却网页没有内容。
```<h2>我教的课</h2> <div> <ul> <li th:each="subject:${subjects}"> <span th:text="${subject.kc_name}"></span> <span th:text="${subject.kc_teach}"></span> <span th:text="${subject.begin_sj}"></span> </li> </ul> </div> //这个是要显示的网页 ```//显示所有学生信息的请求 @RequestMapping("/query_subject") public String querySubject(Model model){ List<Subject> subjects = null; LSubject subject = new LSubject(); String sqlTxt = "select * from subject_info"; try { subjects = subject.querySubject(sqlTxt); } catch (Exception ex){ ex.printStackTrace(); } model.addAttribute("subjects", subjects); return "subject_info"; }//这个是请求; ``` //向数据库查询教师课程数据,并返回list格式类型的数据。 public List<Subject> querySubject(String sqlTxt) throws ClassNotFoundException { List<Subject> subjects = new ArrayList<Subject>(); JdbcTemplate jdbcTemplate = new JdbcTemplate(); DbManage db = new DbManage(); jdbcTemplate.setDataSource(db.getDataSource()); List<Map<String, Object>> list = jdbcTemplate.queryForList(sqlTxt); for(Map<String, Object> map : list){ Subject subject = new Subject(); subject.setKc_name(map.get("kc_name").toString()); subject.setKc_teach(map.get("kc_teach").toString()); subject.setBegin_sj(map.get("begin_sj").toString()); } return subjects; }//这个处理器,负责处理 ``` //这个是类似超链接一样的,点击“我教的课”就处理请求 <li><a href="/query_subject"><i class="icon-briefcase"></i>我教的课</a></li> //这个是要显示的网页 <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8" /> <title>Insert title here</title> </head> <body> <h2>我教的课</h2> <div> <ul> <li th:each="subject:${subjects}"> <span th:text="${subject.kc_name}"></span> <span th:text="${subject.kc_teach}"></span> <span th:text="${subject.begin_sj}"></span> </li> </ul> </div> </body> </html>``` //还有Subject这个文件没有打出来,大致是 package student.stusys.entity; public class Subject { private String kc_name; private String kc_teach; private String begin_sj; public String getKc_name() { return kc_name; } public void setKc_name(String kc_name) { this.kc_name = kc_name; } public Subject(String kc_name, String kc_teach,String begin_sj) { this.kc_name = kc_name; this.kc_teach = kc_teach; this.begin_sj = begin_sj; } public Subject() { } public String getKc_teach() { return kc_teach; } public void setKc_teach(String kc_teach) { this.kc_teach = kc_teach; } public String getBegin_sj() { return begin_sj; } public void setBegin_sj(String begin_sj) { this.begin_sj = begin_sj; } } 运行以后发现网页上只显示了subject_info.html上面的“我教的课”四个字,其他都没显示出来,还有数据库里面有subject_info这个表,包括kc_name,kc_teach,begin_sj三个字段,希望有会的朋友告诉我解决的方法,谢谢! 用的软件是IDEA。
spring3MVC +spring security3 关于扩展UserDetailsService 无法注入service的疑问.
问题描述: 我想用的spring3MVC+spring security3 实现登录权限的扩展.即扩展UserDetailsService 以达到从持久层上控制登录信息. 但是现在的问题是我启动服务器后,登录时在UserDetailsService 中 service层的方法无法注入. 如下图 [img]http://dl.iteye.com/upload/attachment/441866/0e084199-5973-3d55-a691-b8e1de9559ff.png[/img] 注意图中红线的地方. accountService为null.表示注入失败. 所以我想请教下大家:为什么会出现accountService为null 的问题. 我把主要的代码贴出来并在最后提供例子的下载. 首先是项目文件结构. [img]http://dl.iteye.com/upload/attachment/441868/e7f16960-ef9f-3f2a-9491-9602bac6bfbe.png[/img] [b]下面这段是继承UserDetailsService以实现持久层关联登录.[/b] [code="java"] @Transactional(readOnly = true) public class UserDetailsServiceImpl implements UserDetailsService { private static final Logger logger = LoggerFactory .getLogger(UserDetailsServiceImpl.class); @Resource(name = "accountService") private IAccountService accountService; public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { logger.info("username:" + username); User user = accountService.getUserInfo(username); if (user == null) { throw new UsernameNotFoundException("用户" + username + "不存在!"); } Set<GrantedAuthority> grantedAuths = obtainGrantedAuthorities(user); boolean enabled = true; boolean accountNonExpired = true; boolean credentialsNonExpired = true; boolean accountNonLocked = true; UserDetails userDetails = new org.springframework.security.core.userdetails.User( username, user.getPassword(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, grantedAuths); return userDetails; } private Set<GrantedAuthority> obtainGrantedAuthorities(User user) { Set<GrantedAuthority> authSet = Sets.newHashSet(); for (Role role : user.getRoleList()) { for (Authority authority : role.getAuthorityList()) { logger.info("authority is :" + authority.getPrefixedName()); authSet.add(new GrantedAuthorityImpl(authority .getPrefixedName())); } } return authSet; } }[/code] [b]service接口[/b] [code="java"]public interface IAccountService { /** * 根据用户登录名获得对应的权限信息. */ public User getUserInfo(String userName); }[/code] [b] 实现IAccountService的类[/b] [code="java"] @Service("accountService") @Transactional public class AccountService implements IAccountService { @Resource(name="accountDao") private IAccountDao dao; private static final Logger logger = LoggerFactory .getLogger(AccountService.class); public User getUserInfo(String userName) { // 根据登录名(userName)获得对应的信息 User user = dao.getUserByloginName(userName); // 根据登录名获得对应的角色名.如 用户admin拥有"用户","管理员"这两个角色 List<Role> roleList = dao.getRoleByUserName(userName); for (int i = 0; i < roleList.size(); i++) { // 根据角色的ID查询出每个角色对应的权限. List<Authority> authorityList = dao.getAuthorityByRoleId(roleList .get(i).getId()); Role role = new Role(); // 将查询出来的权限信息放入Role中的authorityList. role.setAuthorityList(authorityList); // 对象role放入集合中 roleList.add(role); } // 将查询出来的角色信息(包含各个角色信息对应的权限信息)装入User里的roleList中. user.setRoleList(roleList); return user; } }[/code] [b]IAccountDao接口[/b] [code="java"] public interface IAccountDao { /** * 根据loginName获得对应用户信息 * * @return */ public User getUserByloginName(String loginName); /** * 根据登录名获得对应的角色. * * @param userName * @return */ public List<Role> getRoleByUserName(String userName); /** * 根据角色ID获得对应的权限ID * * @param roleId * @return */ public List<Authority> getAuthorityByRoleId(int roleId); }[/code] [b]实现IAccountDao接口的类 [/b] [code="java"] @Repository("accountDao") public class AccountDao implements IAccountDao { private static final Logger logger = LoggerFactory.getLogger(AccountDao.class); private SimpleJdbcTemplate jdbcTemplate; @Resource(name = "dataSource") public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); } public User getUserByloginName(String loginName) { String sql = "SELECT id,email,login_name,name,password FROM acct_user WHERE login_name = ?"; return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), new Object[] { loginName }); } public List<Role> getRoleByUserName(String userName) { String sql = "SELECT acct_role.id,acct_role.name FROM acct_user LEFT JOIN acct_user_role ON acct_user_role.user_id=acct_user.id LEFT JOIN acct_role ON acct_role.id=acct_user_role.role_id WHERE acct_user.login_name = ?"; return jdbcTemplate.query(sql, new BeanPropertyRowMapper<Role>( Role.class), new Object[] { userName }); } public List<Authority> getAuthorityByRoleId(int roleId) { String sql = "SELECT acct_authority.id,acct_authority.name,acct_authority.url FROM acct_authority LEFT JOIN acct_role_authority ON acct_authority.id=acct_role_authority.authority_id LEFT JOIN acct_role ON acct_role.id=acct_role_authority.role_id WHERE acct_role.id= ?"; return jdbcTemplate.query(sql, new BeanPropertyRowMapper<Authority>( Authority.class), new Object[] { roleId }); }[/code] 然后是springsecurity3的配置文件 [code="java"] <?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:p="http://www.springframework.org/schema/p" xmlns:sec="http://www.springframework.org/schema/security" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd" default-lazy-init="true"> <sec:http auto-config="true" use-expressions="true" access-denied-page="/denied"> <sec:intercept-url pattern="/resources/**" filters="none" /> <sec:intercept-url pattern="/" access="isAuthenticated()" /> <sec:intercept-url pattern="/login" access="permitAll" /> <!-- <sec:intercept-url pattern="/" access="hasRole('ROLE_ADMIN')" /> --> <sec:form-login login-page="/login" authentication-failure-url="/login?error=1" default-target-url="/" /> <sec:logout invalidate-session="true" logout-success-url="/login" logout-url="/logout" /> </sec:http> <sec:authentication-manager> <sec:authentication-provider user-service-ref="customUserDetailsService"> <sec:password-encoder hash="plaintext" /> </sec:authentication-provider> </sec:authentication-manager> <bean id="customUserDetailsService" class="com.sjax.myapp.service.UserDetailsServiceImpl" /> </beans> [/code]
多数据源springmvc+hibernate 切换问题 在一次请求中多次切换不成功
最近写了一个多数据源的代码,结果在使用的过程中出现了在一个请求中(方法中)两个数据库交替使用的情况,最后情况是数据库切换不过来 并且在项目配置中有懒加载和OpenSessionInViewFilter 数据库一个为本地数据库一个为基金数据库 要做的事情就是在本地查询到基金代码接着再循环去基金库查询基金数据 中间报错为在本地数据库中查询不到某个表(其实是在基金库中) controller层 ``` @RequestMapping(value = "/fundsmatch") public String fundsMatch(HttpServletRequest request, HttpServletResponse response){ BtnHitsCount hits = olService.findByBtnNameAndPage("匹配理财方案", "我的页面"); hits.setHits(hits.getHits()+1); olService.saveHits(hits); if (getAttributeFromSession(Constant.SESSION_KEY_CURRENTUSERID) == null) { return "login"; } String openuid = "c8572f0f-dca3-4b63-aecd-2f32d5510ba3"; Integer userId = (Integer)getAttributeFromSession(Constant.SESSION_KEY_CURRENTUSERID); -------------------在本地库取数据-------------------- JoUser joUser = joUserService.find(userId); PortfolioMatch match = portfolioMatchService.findEntity(userId+""); List<FundsGroupBean> list = new ArrayList<FundsGroupBean>(); if(joUser.getRisklevel()!=null&&match!=null&&match.getPlanId()!=null){ ScoreStandard standard = scoreStandard.findEntity(match.getScoreId()+""); FundPortfolio fundPortfolio = match.getFundPortfolioId(); String[] fundcodes = fundPortfolio.getFundcodes().split(","); for (int i = 0; i < fundcodes.length; i++) { FundsGroupBean fgb = new FundsGroupBean(); try { --------------切换基金库取数据-------------- JSONObject json = JSONObject.fromObject(fundsNavService.findFundsInfo(fundcodes[i])); --------------切换基金库取数据-------------- } catch (Exception e) { e.printStackTrace();--------------在此报错-------------------- } fgb.setFundCode(fundcodes[i]); list.add(fgb); } request.setAttribute("list", list); request.setAttribute("rates", fundPortfolio.getMinIncomeRate()+"~"+fundPortfolio.getMaxIncomeRate()); request.setAttribute("risktest", 1); request.setAttribute("level", joUser.getRisklevel()+" "+standard.getName()); }else{ return "redirect:/questionnaire/plan_questionnaire"; } return "fundsmatch"; } ``` 基金server层内部代码 ``` @Service public class FundsNavServiceImpl implements FundsNavService { @Autowired FundsNavDao dao; public Map<String, Object> findNav(String fundcode, String day) { ContextHolder.setDbType(DBType.dataSource2); Map<String,Object> map = dao.findNav(fundcode, day); ContextHolder.clearDBType(); return map; } public Map<String, Object> findFundsInfo(String fundcode) { ContextHolder.setDbType(DBType.dataSource2); Map<String,Object> retMap = new HashMap<String,Object>(); retMap.put("fundinfo", dao.findFundsInfo(fundcode)); ContextHolder.clearDBType(); return retMap; } public Map<String, Object> searchFunds(String fundcode, String page, String rows) { ContextHolder.setDbType(DBType.dataSource2); Map<String,Object> retMap = new HashMap<String,Object>(); retMap.put("fundList", dao.searchFunds(fundcode, page, rows)); ContextHolder.clearDBType(); return retMap; } } ``` 数据源枚举类 ``` package com.chy.dangaowm.util.fund; public enum DBType { dataSource1, dataSource2 } ``` 继承的AbstractRoutingDataSource类并且在spring中配置 ``` package com.chy.dangaowm.util.fund; import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; public class DynamicDataSource extends AbstractRoutingDataSource { @Override protected Object determineCurrentLookupKey() { DBType dbType = ContextHolder.getDBType(); return dbType; } } ``` 基金库切换类 ``` package com.chy.dangaowm.util.fund; public class ContextHolder { private static final ThreadLocal<Object> holder = new ThreadLocal<Object>(); public static void setDbType(DBType dbType){ holder.set(dbType); } public static DBType getDBType(){ return (DBType)holder.get(); } public static void clearDBType(){ holder.remove(); } } ``` spring配置文件 ``` <!-- 配置dataSource1 进行save,update操作时连接这个数据库--> <bean id="dataSource1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.slave.url}" /> <property name="username" value="${jdbc.slave.username}" /> <property name="password" value="${jdbc.slave.password}" /> <property name="initialSize" value="${jdbc.initialSize}" /> <property name="maxActive" value="${jdbc.maxActive}" /> <property name="maxIdle" value="${jdbc.maxIdle}" /> <property name="minIdle" value="${jdbc.minIdle}" /> <property name="testOnBorrow" value="${jdbc.testOnBorrow}" /> <property name="testWhileIdle" value="${jdbc.testWhileIdle}" /> <property name="validationQuery" value="${jdbc.validationQuery}" /> <!-- <property name="validationQuery" value="select 1;" /> --> </bean> <!--配置dataSource1 进行select操作时连接这个数据库 --> <bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.master.url}" /> <property name="username" value="${jdbc.master.username}" /> <property name="password" value="${jdbc.master.password}" /> <property name="initialSize" value="${jdbc.initialSize}" /> <property name="maxActive" value="${jdbc.maxActive}" /> <property name="maxIdle" value="${jdbc.maxIdle}" /> <property name="minIdle" value="${jdbc.minIdle}" /> <property name="testOnBorrow" value="${jdbc.testOnBorrow}" /> <property name="testWhileIdle" value="${jdbc.testWhileIdle}" /> <property name="validationQuery" value="${jdbc.validationQuery}" /> <!-- <property name="validationQuery" value="select 1;" /> --> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" p:dataSource-ref="dataSource1" /> <!-- mysql 动态数据源设置--> <bean id="mysqlDynamicDataSource" class="com.chy.dangaowm.util.fund.DynamicDataSource"> <property name="targetDataSources"> <!-- 标识符类型 --> <map key-type="com.chy.dangaowm.util.fund.DBType"> <entry key="dataSource1" value-ref="dataSource1"/> <entry key="dataSource2" value-ref="dataSource2"/> </map> </property> <property name="defaultTargetDataSource" ref="dataSource1"/> </bean> <!-- 配置sessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="mysqlDynamicDataSource" /> <property name="namingStrategy"> <bean class="org.hibernate.cfg.ImprovedNamingStrategy" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> </props> </property> <property name="packagesToScan"> <array> <value>com.chy.dangaowm.domain</value> </array> </property> </bean> <!-- 配置事务管理 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> ```
编写测试单元遇到的问题
<pre name="code" class="java">public class TestDaoCase extends AbstractTransactionalDataSourceSpringContextTests { @Override protected String[] getConfigLocations() { return new String[] { "file:F:\\shenghuoNet\\WebRoot\\WEB-INF\\applicationContext.xml"}; } public TestDaoCase(){ super(); setAutowireMode(AUTOWIRE_BY_NAME); setDefaultRollback(true); this.setDependencyCheck(false); setPopulateProtectedVariables(true); jdbcTemplate=new JdbcTemplate((DataSource)getContext(getConfigLocations()).getBean("dataSource")); } private ApplicationContext applicationContext; public ApplicationContext getContext(String[] filePath) { return new ClassPathXmlApplicationContext(filePath); } public void testConfig() { assertNotNull("spring-mock context has bean init()",this.getConfigLocations()); } public static void main(String[] args) { TestRunner.run(TestDaoCase.class); } public void testFindById() { ShnMember shnMember = new ShnMember(); // shnMember.setPasswd("darksun"); // shnMember.setCreatetime(new Date()); // shnMember.setUsername("darksun"); ITestService is=(ITestService)getContext(getConfigLocations()).getBean("TestDAO"); try { shnMember=is.findById(1l); } catch (Exception e) { fail(e.getMessage()); } // String name = (String) jdbcTemplate.queryForObject("select username from shn_member where memberid=?", new Object[]{shnMember.getMemberid()}, Long.class); assertEquals(shnMember.getUsername(), "shenghuo"); } public void testSave() { ShnMember shnMember = new ShnMember(); shnMember.setPasswd("darksun"); shnMember.setCreatetime(new Date()); shnMember.setUsername("xingfu pig"); ShnRole role=new ShnRole(); role.setRoleid(1l); shnMember.setShnRole(role); ITestService is=(ITestService)getContext(getConfigLocations()).getBean("TestDAO"); try { is.save(shnMember); } catch (Exception e) { fail(e.getMessage()); } <span style="color: #ff0000;"> String name = (String) jdbcTemplate.queryForObject("select username from shn_member where memberid=?", new Object[]{shnMember.getMemberid()}, Long.class);</span> assertEquals(shnMember.getUsername(), name); } }</pre> <p><br />以上是我的测试代码<br /><br />There was 1 error:<br />1) testSave(TestUnit.TestDaoCase)org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0<br /> at org.springframework.dao.support.DataAccessUtils.requiredSingleResult(DataAccessUtils.java:71)<br /> at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:669)<br /> at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:679)<br /> at TestUnit.TestDaoCase.testSave(TestDaoCase.java:85)<br /> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br /> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br /> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br /> at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)<br /> at TestUnit.TestDaoCase.main(TestDaoCase.java:50)<br />这个是错误提示<br /><br />问题我也知道了 就是因为没提交 所以jdbc怎么也找不到数据 但问题是我不希望测试数据插进数据库 有什么方法能解决</p> <p> </p><br /><strong>问题补充:</strong><br />to:小疯子 <br />1. 我是没办法 因为如果不写 jdbcTemplate为空 我不知道是什么原因 <br /> <br />2. 那个是不自然 因为刚写的时候 怎么都读不到 改了几次 后来配好没有改 - -! <br /> <br />3.问题就是这个了 没有提交 jdbc就找不到数据 要找数据就要提交 所以才找人问<br /><strong>问题补充:</strong><br /><pre name="code" class="java"> public class TestDao2Case extends AbstractTransactionalDataSourceSpringContextTests { @Override protected String[] getConfigLocations() { return new String[] { "file:F:\\shenghuoNet\\WebRoot\\WEB-INF\\applicationContext.xml" }; } ITestService testDao; // 自己会注入的. // 需要写setter方法. public void setTestDAO(ITestService testService) { this.testDao = testService; } public void testSave() { ShnMember shnMember = new ShnMember(); shnMember.setPasswd("darksun"); shnMember.setCreatetime(new Date()); shnMember.setUsername("xingfus 54zhf1tou"); ShnRole role = new ShnRole(); role.setRoleid(1l); shnMember.setShnRole(role); try { testDao.save(shnMember); } catch (Exception e) { fail(e.getMessage()); } String name = (String) jdbcTemplate.queryForObject( "select username from shn_member where memberid=?", new Object[] { shnMember.getMemberid() }, String.class); assertEquals(shnMember.getUsername(), name); } public void testFindById() { ShnMember shnMember = new ShnMember(); try { shnMember = testDao.findById(1l); } catch (Exception e) { fail(e.getMessage()); } assertEquals(shnMember.getUsername(), "shenghuo"); } public static void main(String[] args) { TestRunner.run(TestDao2Case.class); } } </pre> <br /> <br />这个是修改过的 <br /> <br />错误提示: <br />org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0 <br /> at org.springframework.dao.support.DataAccessUtils.requiredSingleResult(DataAccessUtils.java:71) <br /> at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:669) <br /> at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:679) <br /> at TestUnit.TestDao2Case.testSave(TestDao2Case.java:44) <br /> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) <br /> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) <br /> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) <br /> at java.lang.reflect.Method.invoke(Unknown Source) <br /> at junit.framework.TestCase.runTest(TestCase.java:168) <br /> at junit.framework.TestCase.runBare(TestCase.java:134) <br /> at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69) <br /> at junit.framework.TestResult$1.protect(TestResult.java:110) <br /> at junit.framework.TestResult.runProtected(TestResult.java:128) <br /> at junit.framework.TestResult.run(TestResult.java:113) <br /> at junit.framework.TestCase.run(TestCase.java:124) <br /> at junit.framework.TestSuite.runTest(TestSuite.java:232) <br /> at junit.framework.TestSuite.run(TestSuite.java:227) <br /> at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76) <br /> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) <br /> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) <br /> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) <br /> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) <br /> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) <br /> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) <br /> <br /><br /><strong>问题补充:</strong><br />恩 谢谢两位大大 就是最后一个问题解决不了 <br /> <br />就是这个问题 <br />org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0 <br /> <br />jdbc找不到未提交的数据 <br /><strong>问题补充:</strong><br />to:logger <br /> 很感谢大哥这么热心 可是问题不是异常 出异常的原因是因为我在测试保存数据 <br /> 数据保存了 但是没提交 然后用jdbc去查询 希望获得这条数据 来确认保存成功 <br /> 恩 结果就出现这个异常了 如果我提交了 那么数据就插进数据库了 同时测试也能通过 <br /> 我试验过了 我希望测试的时候不会插脏数据进数据库 可是如果不提交 就会出现这个异常 <br /> <br />恩 再次感谢一下大大 <br /><strong>问题补充:</strong><br />恩 谢谢两位大大 问题我已经解决了 <br />首先 是applicationContext.xml 哪里要配置事务管理 我配置的时候少了save的方法 所以没有管理到 呵呵 <br />第二是要getHiberateTemplate().flush 要不然 也出同样的错误 <br />很感谢两位
spring的jdbctemplet的queryforObject()有异常,不知道原因
public String execute()throws Exception{ if("save".equals(actionStr)){ sql = "update DY_Topic_Group set TGName='"+tgname+"',"+ "TDetail='"+tdetail+"' where TGID="+tgid; if(dbu.update(sql)){ //更新课程资料 message = "课程资料保存成功<br>"; } else{ message = "未知错误,课程资料保存失败<br>"; } sql = "select 1 from DY_User where URole=1 and UName='"+uname+"'"; //查看该用户是否是老师 if(!dbu.isExist(sql)){ //如果该用户是老师 message += "为课程指定老师失败,因为该用户不是老师"; } else{ sql = "select TUID from DY_TU where TGID="+tgid+" and UID=(select UID from"+ " DY_User where UName='"+uname+"')"; //搜出该课程和老师ID的关系记录主键 System.out.println("1"); String tuid = dbu.getStringInfo(sql); System.out.println(tuid); sql = "update DY_TU set UID=(select UID from DY_User where UName='"+uname+ "') where TUID="+tuid; System.out.println("3"); if(dbu.update(sql)){ message += "修改课程老师资料修改成功"; } else{ message += "未知错误,老师信息修改失败"; } } } [color=red]上面是给一门课程指定一个老师,下面是dbutil里面的getstringinfo方法[/color]public class DBUtil{ private JdbcTemplate jt; //声明JdbcTemplate对象引用 private List rl = null; //声明List对象引用 private String sql = null; //声明SQL字符串引用 private DataSource ds; //声明DataSource引用 private DataSourceTransactionManager dtm; private DefaultTransactionDefinition dtd; [color=red]此处省略一些代码。。。。。。。[/color] public String getStringInfo(String sql){ String info = null; //声明返回字符串引用 try{ sql = new String(sql.getBytes(),"iso8859-1");//对SQL语句转码 System.out.println("p"); info = (String)jt.queryForObject(sql,String.class); //执行查询 System.out.println("o"); info = new String(info.getBytes("iso8859-1"),"gbk");//对查询的字符串转码 System.out.println("i"); } catch(Exception e){ info = null;//有异常发生则info置为null System.out.println("u"); } return info; //返回查询结果 } [color=red]下面是tomcat服务器上的输出[/color] =============拦截器=============2011-4-2 21:24:36 isExist select 1 from DY_User where URole=1 and UName='w' 1 p [color=red]u null[/color] 3 [color=red]通过输出u 和 null 说明有异常,但我不知道为什么会有异常[/color]
使用spring SimpleJdbcTemplate遇到的问题
首先我的承认我有些画蛇添足了.但是为了尝试封装DAO,为以后遥不可及的更换DAO层做准备我做了这个尝试,结果出现问题. 我先贴一段出错的提示吧: 信息: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase] [b]org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [update res_grade_table set gradeName=:gradeName where gradeId=:gradeId]; Invalid argument value: [/b]java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:107) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:602) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:786) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:842) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:850) at Org.Config.DaoBaseOperation.updateByBean(DaoBaseOperation.java:37) at res.grade.Action.gradeAction.execute(gradeAction.java:46) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at Org.Config.EncodingFilter.doFilter(EncodingFilter.java:66) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Unknown Source) [b]Caused by: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException[/b] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) 出错的重点部分我加粗了. 我把SimpleJdbcTemplate 中的一些日常操作写到了DaoBaseOperation<E>()类中内容如下,我在gradeAction 这个类中调用updateByBean这个方法结果出现上面的错误,后面我直接使用SimpleJdbcTemplate 中的update方法错误消失(见gradeAction中注释部分),我很奇怪这个异常,传递的参数能够打印出来,可是异常却提示无效的参数值。不知道自己错在哪里。请各位朋友赐教 [code="java"] package Org.Config; import java.util.List; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; public class DaoBaseOperation<E> { static SimpleJdbcTemplate simpleJdbcTemplate = new SimpleJdbcTemplate( DBConnectionPool.getDataSource()); //插入数据返回数据ID public int update(String sql,E Bean){ SqlParameterSource param = new BeanPropertySqlParameterSource(Bean); KeyHolder keyHolder = new GeneratedKeyHolder(); this.simpleJdbcTemplate.getNamedParameterJdbcOperations().update(sql, param, keyHolder); return keyHolder.getKey().intValue(); } //修改或删除数据 public void updateByObjectArray(String sql,Object[] args){ this.simpleJdbcTemplate.getJdbcOperations().update(sql, args); } //修改或删除数据 public void updateByBean(String sql,E Bean){ SqlParameterSource param = new BeanPropertySqlParameterSource(Bean); System.out.println(param.getValue("gradeId")); System.out.println(param.getValue("gradeName"));//参数传递正常 this.simpleJdbcTemplate.getJdbcOperations().update(sql, param); } //查询数据 public Object find(String sql,Object[] args,Class<?> clazz){ return this.simpleJdbcTemplate.getJdbcOperations().queryForObject(sql, args, new BeanPropertyRowMapper(clazz)); } //数据列表 public List list(String sql,Object[] args,Class clazz){ return this.simpleJdbcTemplate.getJdbcOperations().query(sql, args, new BeanPropertyRowMapper(clazz)); } public List list(String sql,Class clazz){ return this.simpleJdbcTemplate.getJdbcOperations().query(sql, new BeanPropertyRowMapper(clazz)); } public List list(String sql,Object... args){ return this.simpleJdbcTemplate.queryForList(sql,args); } } [/code] [code="java"]package res.grade.Action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import res.grade.Bean.gradeBean; import Admin.AdminInfo; import Admin.BO.AdminBO; import Org.Config.DBConnectionPool; import Org.Config.DaoBaseOperation; public class gradeAction extends Action { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub ActionMessages errors = new ActionMessages(); try { AdminBO adminBO = new AdminBO(); adminBO.validateAdminSession(request); adminBO.validateModuleSession(request, AdminInfo.AdminResourcesModuleId); gradeBean gradeBean = (gradeBean) form; /*System.out.println("GradeId:"+gradeBean.getGradeId()); System.out.println("GradeName:"+gradeBean.getGradeName());*/ DaoBaseOperation<gradeBean> daobase = new DaoBaseOperation<gradeBean>(); SimpleJdbcTemplate simpleJdbcTemplate = new SimpleJdbcTemplate( DBConnectionPool.getDataSource()); if (gradeBean.getGradeId()==0) { daobase.update("insert into res_grade_table (gradeName) values (:gradeName)", gradeBean); } else { /*String sql = "update res_grade_table set gradeName=:gradeName where gradeId=:gradeId "; simpleJdbcTemplate.update(sql, new BeanPropertySqlParameterSource(gradeBean));*/ daobase.updateByBean("update res_grade_table set gradeName=:gradeName where gradeId=:gradeId", gradeBean); } return mapping.findForward("success"); } catch (Throwable e) { e.printStackTrace(); ActionMessage error = new ActionMessage(e.getMessage()); errors.add(ActionMessages.GLOBAL_MESSAGE, error); } saveErrors(request, errors); return new ActionForward(mapping.getInput()); } } [/code]
在中国程序员是青春饭吗?
今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...
《MySQL 性能优化》之理解 MySQL 体系结构
本文介绍 MySQL 的体系结构,包括物理结构、逻辑结构以及插件式存储引擎。
【资源】一个C/C++开发工程师的学习路线(已经无路可退,唯有逆风飞翔)【内附资源页】
声明: 1)该文章整理自网上的大牛和专家无私奉献的资料,具体引用的资料请看参考文献。 2)本文仅供学术交流,非商用。所以每一部分具体的参考资料并没有详细对应。如果某部分不小心侵犯了大家的利益,还望海涵,并联系博主删除。 3)博主才疏学浅,文中如有不当之处,请各位指出,共同进步,谢谢。 4)此属于第一版本,若有错误,还需继续修正与增删。还望大家多多指点。大家都共享一点点,一起为祖国科研的推进...
程序员请照顾好自己,周末病魔差点一套带走我。
程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。
20道你必须要背会的微服务面试题,面试一定会被问到
写在前面: 在学习springcloud之前大家一定要先了解下,常见的面试题有那块,然后我们带着问题去学习这个微服务技术,那么就会更加理解springcloud技术。如果你已经学了springcloud,那么在准备面试的时候,一定要看看看这些面试题。 文章目录1、什么是微服务?2、微服务之间是如何通讯的?3、springcloud 与dubbo有哪些区别?4、请谈谈对SpringBoot 和S...
达摩院十大科技趋势发布:2020 非同小可!
【CSDN编者按】1月2日,阿里巴巴发布《达摩院2020十大科技趋势》,十大科技趋势分别是:人工智能从感知智能向认知智能演进;计算存储一体化突破AI算力瓶颈;工业互联网的超融合;机器间大规模协作成为可能;模块化降低芯片设计门槛;规模化生产级区块链应用将走入大众;量子计算进入攻坚期;新材料推动半导体器件革新;保护数据隐私的AI技术将加速落地;云成为IT技术创新的中心 。 新的画卷,正在徐徐展开。...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
python爬取百部电影数据,我分析出了一个残酷的真相
2019年就这么匆匆过去了,就在前几天国家电影局发布了2019年中国电影市场数据,数据显示去年总票房为642.66亿元,同比增长5.4%;国产电影总票房411.75亿元,同比增长8.65%,市场占比 64.07%;城市院线观影人次17.27亿,同比增长0.64%。 看上去似乎是一片大好对不对?不过作为一名严谨求实的数据分析师,我从官方数据中看出了一点端倪:国产票房增幅都已经高达8.65%了,为什...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试,面试官没想到一个ArrayList,我都能跟他扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
2020 年,大火的 Python 和 JavaScript 是否会被取而代之?
Python 和 JavaScript 是目前最火的两大编程语言,但是2020 年,什么编程语言将会取而代之呢? 作者 |Richard Kenneth Eng 译者 |明明如月,责编 | 郭芮 出品 | CSDN(ID:CSDNnews) 以下为译文: Python 和 JavaScript 是目前最火的两大编程语言。然而,他们不可能永远屹立不倒。最终,必将像其他编程语言一...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
AI 没让人类失业,搞 AI 的人先失业了
最近和几个 AI 领域的大佬闲聊 根据他们讲的消息和段子 改编出下面这个故事 如有雷同 都是巧合 1. 老王创业失败,被限制高消费 “这里写我跑路的消息实在太夸张了。” 王葱葱哼笑一下,把消息分享给群里。 阿杰也看了消息,笑了笑。在座几位也都笑了。 王葱葱是个有名的人物,21岁那年以全额奖学金进入 KMU 攻读人工智能博士,累计发表论文 40 余篇,个人技术博客更是成为深度学习领域内风向标。 ...
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆每天早上8:30推送 作者|Mr.K 编辑| Emma 来源|技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯...
神级宝库!GitHub 标星 1.2w+,Chrome 最天秀的插件都在这里啦!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个沉迷 Chrome 不能自拔的蒟蒻… 作为一个在远古时代用过什么 IE、360、猎豹等浏览器的资深器哥,当我第一次了解 Chrome 的时候,就被它的美貌给吸引住了… 就在我用了一段时间之后,我坚决的卸载了电脑上其它碍眼的浏览器,并觉得在之前的搬砖生涯中,我不配当哥,我只配是个沙雕… ...
作为一名大学生,如何在B站上快乐的学习?
B站是个宝,谁用谁知道???? 作为一名大学生,你必须掌握的一项能力就是自学能力,很多看起来很牛X的人,你可以了解下,人家私底下一定是花大量的时间自学的,你可能会说,我也想学习啊,可是嘞,该学习啥嘞,不怕告诉你,互联网时代,最不缺的就是学习资源,最宝贵的是啥? 你可能会说是时间,不,不是时间,而是你的注意力,懂了吧! 那么,你说学习资源多,我咋不知道,那今天我就告诉你一个你必须知道的学习的地方,人称...
那些年,我们信了课本里的那些鬼话
教材永远都是有错误的,从小学到大学,我们不断的学习了很多错误知识。 斑羚飞渡 在我们学习的很多小学课文里,有很多是错误文章,或者说是假课文。像《斑羚飞渡》: 随着镰刀头羊的那声吼叫,整个斑羚群迅速分成两拨,老年斑羚为一拨,年轻斑羚为一拨。 就在这时,我看见,从那拨老斑羚里走出一只公斑羚来。公斑羚朝那拨年轻斑羚示意性地咩了一声,一只半大的斑羚应声走了出来。一老一少走到伤心崖,后退了几步,突...
张朝阳回应迟到 1 分钟罚 500:资本家就得剥削员工
loonggg读完需要2分钟速读仅需 1 分钟大家我,我是你们的校长。前几天,搜狐的董事局主席兼 CEO 张朝阳和搜狐都上热搜了。原因很简单,就是搜狐出了“考勤新规”。一封搜狐对员工发布...
立即提问