spring security中,如何把登陆页面的参数传递到UserDetailsService中

由于一个需求的问题,需要根据不同的登陆页面来调用不同的数据库来校验会员身份。不同的登陆页面使用EntryPoint就可以解决了,但是对用户校验的时候,我想根据登录表单的一个隐藏域的值,来区分不同的用户身份,进而在UserDetailsService中来调用不同额数据库进行校验,我看了可以在AuthenticationProcessingFilter 中的attemptAuthentication中可以获取到这个值,但是不知道怎么传递给UserDetailsService,想请教一下这个问题?

1个回答

这个需求应该扩展spring security。主要扩展以下类:
UsernamePasswordAuthenticationFilter类的attemptAuthentication方法,主要获取request传递的参数;
UsernamePasswordAuthenticationToken类,主要用于增加认证所用到的额外参数;
DaoAuthenticationProvider类的retrieveUser方法,主要把UsernamePasswordAuthenticationToken扩展类的额外参数传递给UserDetailsService;
UserDetailsService实现类的loadUserByUsername方法。主用使用额外参数及账号、密码等多个参数进行验证。

当然,扩展完成后,需要对spring security的配置文件进行修改。修改的主要目标就是替换掉原来的bean。如果我说的还不够明确,可参考本人博客专栏:
http://dead-knight.iteye.com/category/220917

Dead_Knight
Dead_Knight loadUserByUsername实际上是接口方法。涉及到多个参数,可以借助spring注入,然后在loadUserByUsername实现方法中获取就行了
7 年多之前 回复
huapu728
huapu728 UserDetailsService的loadUserByUsername只有一个参数,该如何扩展?
7 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
这是什么错怎么解决啊???!!!

Description: Field userDetailsService in com.dunan.zzjg.config.WebSecurityConfig required a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) The following candidates were found but could not be injected: - Bean method 'inMemoryUserDetailsManager' in 'UserDetailsServiceAutoConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.security.authentication.AuthenticationManager,org.springframework.security.authentication.AuthenticationProvider,org.springframework.security.core.userdetails.UserDetailsService; SearchStrategy: all) found beans of type 'org.springframework.security.authentication.AuthenticationManager' authenticationManager Action: Consider revisiting the entries above or defining a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' in your configuration. Process finished with exit code 1

spring+springmvc+mybatis 报错。求大神指教。

``` 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'index': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.yhq.service.biz.UserService com.yhq.controller.Index.userd; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.yhq.service.dao.UserMapper com.yhq.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.yhq.service.dao.UserMapper] 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)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5231) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5518) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.yhq.service.biz.UserService com.yhq.controller.Index.userd; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.yhq.service.dao.UserMapper com.yhq.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.yhq.service.dao.UserMapper] 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)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) ... 29 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.yhq.service.dao.UserMapper com.yhq.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.yhq.service.dao.UserMapper] 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)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:912) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489) ... 31 more Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.yhq.service.dao.UserMapper com.yhq.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.yhq.service.dao.UserMapper] 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)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) ... 42 more Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.yhq.service.dao.UserMapper] 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)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:988) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:858) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489) ... 44 more ```

关于Go创作者为何选择不将“ nil”视为“ false”的历史参考[关闭]

<div class="post-text" itemprop="text"> <p>Why did Go creators choose to not treat <code>nil</code> as <code>false</code>? What why did they think it is better to explicitly compare values to <code>nil</code>? Is there a reliable source that would explain why is that is Go? What was their opinion? What was the logic behind this decision?</p> <p>I'm looking for a historical reference.</p> <hr> <p>E.g.:</p> <pre><code>f, err := os.Open(name) if err != nil { return err } </code></pre> <p>Than to implicitly cast <code>nil</code>s to <code>false</code> like in many other languages:</p> <pre><code>f, err := os.Open(name) if err { return err } </code></pre> <p>As of now, the latter would give:</p> <pre><code>non-bool err (type error) used as if condition </code></pre> </div>

try with resource的用法

![图片说明](https://img-ask.csdn.net/upload/201812/23/1545552122_607063.png) 我想问下我使用try with resource 关闭资源为什么显示错误,我的版本也是1.8的啊 他这个不是1.7就可以了吗

具有隐私条件检查的查询中的mysql查询

<div class="post-text" itemprop="text"> <p>I have 3 tables.</p> <pre><code>myMembers ------------------------------------ id | username | privacy ------------------------------------ 1 | userA | 0 2 | userB | 1 3 | userC | 0 4 | userD | 1 following -------------------------------- id | user_id | follower_id -------------------------------- 1 | 2 | 1 posts ------------------------------------- id | userID | username | statusMsg -------------------------------------- 1 | 4 | userD | Issac Newton is genius 2 | 2 | userB | Newton Saw apple 3 | 3 | userC | Newtonian Physics 4 | 1 | userA | Calculus came from Sir Newton </code></pre> <p>There is a search field. When a logged in user searches for 'keyword' in table 'posts', I want to omit results from those users who has set his privacy to '1' and WHERE searcher is not following user B.</p> <p>The query should logically do this.</p> <pre><code>SELECT * from posts WHERE (match the keyword) AND ( if (poster's privacy (which is set in myMembers)==1){ if (seacher is following poster){ select this post } } else { select this post } ) LIMIT results to 5 rows </code></pre> <p>So for a keyword "Newton", if userA is searching, rows 2,3,4 from 'posts' should be returned. if userD is searching, only rows 1, 3 and 4 from 'posts' should be returned, </p> <p>based on privacy and following Edit: Tagging for future searches: IF condition within WHERE Clause in mySql</p> </div>

tomcat and eclipse

新手上路,不是很熟悉,在学习中遇到以下几个文为: 1.tomcat 打开 localhost:8080,没有问题,然后打开自己的程序时,显示:不存在资源。。。。。。 2.eclipse 导入一个已有的工程,但是在resource 和 WebRoot有红色的叉叉。。。 高手们帮忙!!!! [b]问题补充:[/b] 1.我用的就是myeclipse ..resource 的错误信息:invalid character userd in text string ,还有就是说<a>..</a>,一直说没有</a>不匹配,可是我程序中都是全的阿。。。这是为什么啊?

如何编写MYSQL查询!=在Codeigniter中的Active记录?

<div class="post-text" itemprop="text"> <p>I have the below query form using codeigniter active record function, </p> <pre><code>select * from user where user_id!=10 </code></pre> <p>I have tried the below code</p> <pre><code>$condition=array( 'userr_id!='=&gt;2, ); $this-&gt;db-get('userd',$condition); </code></pre> <p>its return database error. How to make query using active record function?</p> </div>

oracle 11g with as问题

with c as (select 1 from dual) select * from c 查询结果为空,为什么?![图片说明](https://img-ask.csdn.net/upload/201602/18/1455759396_356240.png)

maxActive is not used in DBCP2

十一月 02, 2015 2:31:39 下午 org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance 警告: Name = DataSource Property maxActive is not used in DBCP2, use maxTotal instead. maxTotal default value is 8. You have set value of "100" for "maxActive" property, which is being ignored. 十一月 02, 2015 2:31:39 下午 org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance 警告: Name = DataSource Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "10000" for "maxWait" property, which is being ignored. 十一月 02, 2015 2:31:39 下午 org.apache.jasper.servlet.TldScanner scanJars

weblogic环境下调用接口报错,急,在线等!org.w3c.dom.Node.setUserData

之前在测试环境中测试是可以的,后来部署到正式环境就挂掉了,tomcat下也是正常的。项目的weblogic.xml也配置了优先加载项目的jar包,还是不行。 ava.lang.LinkageError: loader constraint violation: when resolving interface method "org.w3c.dom.Node.setUserData(Ljava/lang/String;Ljava/lang/Object;Lorg/w3c/dom/UserDataHandler;)Ljava/lang/Object;" the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) of the current class, org/apache/cxf/staxutils/StaxUtils, and the class loader (instance of <bootloader>) for resolved class, org/w3c/dom/Node, have different Class objects for the type erDataHandler;)Ljava/lang/Object; used in the signature

如何为“你可能知道的人”构建查询[关闭]

<div class="post-text" itemprop="text"> <p>i need to show "people you may know" based on the current friends of a user and the friend suggestion should consider blocked users,if user A blocked user B,A should not see user B or vice versa in their friends Suggestions here is my table structure </p> <p>mnc_users</p> <pre><code>id | username | email | fullname --------------------------------------------------- 1 | userA | usera@in.in | User Alpha 2 | userB | userb@in.in | User Bravo 3 | userC | userc@im.in | user c 4 | userd | userd@am.in | user del </code></pre> <p>mnc_friends</p> <pre><code>uid | fid | time ------------------------- 1 | 3 | 1363859398 3 | 1 | 1363859398 4 | 1 | 1368854898 1 | 4 | 1368854898 3 | 2 | 1363846116 2 | 3 | 1363846116 2 | 4 | 1363846116 4 | 3 | 1363846116 </code></pre> <p>mnc_blocked</p> <pre><code>id | uid | bid -------------------- 1 | 1 | 2 </code></pre> <p>mnc_frnd_rqsts</p> <pre><code>uid | fid ----------- 5 | 1 </code></pre> <p>how can i display users suggestions in this case using php and mysql?</p> </div>

POST 422(不可处理的实体)Laravel - Ajax

<div class="post-text" itemprop="text"> <p>I am using Laravel 5.3 and i would also like to say that i am not that much experienced working on Laravel.</p> <p>I am just trying to build a Login Form with </p> <ul> <li>Laravel</li> <li>Angular JS 1.5</li> <li>Angular Material</li> </ul> <p>and getting an error while posting Ajax request as</p> <blockquote> <p>POST 422 (Unprocessable Entity) </p> </blockquote> <p>I have searched SO and google as well but not got any solution to this problem. Below are the files and code:</p> <p><strong>login.php</strong></p> <pre><code>&lt;?php echo Form::open(array('name'=&gt;'loginForm','autocomplete'=&gt;'off')); ?&gt; &lt;md-input-container class="md-block"&gt; &lt;?php echo Form::label('username', 'Username'); echo Form::text('username', '', array('required'=&gt;'required','ng-model'=&gt;'userD.user.username','md-no-asterisk')); ?&gt; &lt;div ng-messages="loginForm.username.$error" role="alert"&gt; &lt;div ng-message="required"&gt;Username is required&lt;/div&gt; &lt;/div&gt; &lt;/md-input-container&gt; &lt;md-input-container class="md-block"&gt; &lt;?php echo Form::label('password', 'Password'); echo Form::password('password', array('required'=&gt;'required','ng-model'=&gt;'userD.user.password','md-no-asterisk')); ?&gt; &lt;div ng-messages="loginForm.password.$error" role="alert"&gt; &lt;div ng-message="required"&gt;Password can not be blank&lt;/div&gt; &lt;/div&gt; &lt;/md-input-container&gt; &lt;md-button type="submit" class="md-primary md-raised" ng-disabled="!loginForm.$valid" ng-click="userD.login()"&gt;Login&lt;/md-button&gt; &lt;?php echo Form::close(); ?&gt; </code></pre> <p><strong>app.js</strong></p> <pre><code>function login() { $http.post('/admin/login', {user: userD.user}) .success(function (res) { $window.location.href = '/admin/dashboard'; }) .error(function(res) { console.log(res); userD.error = res; }); } </code></pre> <p><strong>LoginController</strong></p> <pre><code>use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Redirect; class LoginController extends Controller{ public function index(){ if(Auth::check() &amp;&amp; Auth::user()-&gt;UserRoles-&gt;role &gt;= 2){ return Redirect::to('/admin/dashboard'); } return View('admin.login.index'); } public function login(Request $request){ $data = $request['user']; $email = isset($data['username']) ? $data['username'] : null; $password = isset($data['password']) ? $data['password'] : null; //$remember = isset($data['remember']) ? $data['remember'] : null; if(Auth::attempt(['email' =&gt; $email, 'password' =&gt; $password]/*, $remember*/)) { if(Auth::user()-&gt;UserRoles-&gt;role &gt; 1) { return response()-&gt;json(["message" =&gt; "Welcome"]); } return response()-&gt;json(["The email or password you entered is not correct"], 422); } return response()-&gt;json(["2 : The email or password you entered is not correct"], 422); } } </code></pre> <p><a href="https://i.stack.imgur.com/CN3Rn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CN3Rn.png" alt="enter image description here"></a></p> <p><strong>Please do not mark this question as duplicate as i have tried many solutions from SO only</strong></p> </div>

Error building SqlSession。跟着黑马学mybatis跟着敲的代码,百度了很久也不知道哪里错了,求解答。

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in com.itheima.dao.IUserDao.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com.itheima.dao.IUserDao.xml at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64) at com.itheima.test.MybatisTest.main(MybatisTest.java:27) Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com.itheima.dao.IUserDao.xml at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78) ... 2 more Caused by: java.io.IOException: Could not find resource com.itheima.dao.IUserDao.xml at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114) at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100) at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:371) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119) ... 4 more Process finished with exit code 1 ``` ``` IUserDao.xml如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.itheima.dao.IUserDao"> <!--查询配置所有 --> <select id="findAll" resultType="com.itheima.domain.User"> select *from user ; </select> </mapper> ``` ``` SqlMapConfig.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"> <!--mybatis的主配置文件 --> <configuration> <!--配置环境--> <environments default="mysql"> <!--配置mysql的环境 --> <environment id="mysql"> <!--配置的事务类型 --> <transactionManager type="JDBC"></transactionManager> <!--配置数据源(连接池)--> <dataSource type="POOLED"> <!--配置连接数据库的4个基本信息 --> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/mybatisstudy"/> <property name="username" value="root"/> <property name="password" value="123"/> </dataSource> </environment> </environments> <!--指定映射配置文件的位置,映射配置文件指的是每个dao独立的配置文件 --> <mappers> <mapper resource="com.itheima.dao.IUserDao.xml"></mapper> </mappers> </configuration>

如何使用strpos搜索特定单词的数组

<div class="post-text" itemprop="text"> <pre><code>$data = " usera: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy. userb: eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam. userc:voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet."; preg_match_all("/(.*:)/", $data, $why1); array_walk_recursive($why1, function($value) use (&amp;$why2) { $why2[] = $value; }); $why3 = array_unique($why2); $why4 = array_values($why3); preg_match_all("/(.*.)/", $data, $info); array_walk_recursive($info, function($value) use (&amp;$shrink) { $shrink[] = $value; }); $brss = array_unique($array_flat); $arss = array_values($brss); for($i=0;$i &lt; count($brss); $i++){ $usera = "$why4[0]"; $userb = "$why4[1]"; $userc = "$why4[2]"; $userd = "$why4[3]"; if (strpos($brss[i], $usera) !== false) // How can I {echo "true";} // ? // I only get false else {echo "false";} } </code></pre> <p>How to get a true in searching my array by asking a specific word with strpos?</p> <p>How can I <code>echo "true";</code>?</p> </div>

Laravel手动验证 - 永远不会工作

<div class="post-text" itemprop="text"> <p>I am trying to make Auth for an API Rest manually, but the response for Auth::attempt is always false.</p> <p>Route</p> <pre><code>Route::group(["prefix"=&gt;"api"], function(){ Route::post('/login', [ 'as' =&gt; 'checkLogin', 'uses' =&gt; 'LoginCtrl@checkLogin' ]); }); </code></pre> <p>Controller</p> <pre><code>class LoginCtrl extends Controller { public function checkLogin(Request $request){ $input = $request-&gt;all(); if(Auth::attempt(['username' =&gt; $input['user'], 'password' =&gt; $input['password']])){ $data = ["response"=&gt;true,"access_token"=&gt;"test"]; }else{ $data = ["response"=&gt;false,"access_token"=&gt;"none"]; } return response()-&gt;json($data); } } </code></pre> <p>I have userd <code>Hash::make</code> to encrypt the password on the user creation.</p> <p>My model is:</p> <pre><code>namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { protected $table = "usuarios"; protected $username = 'username'; protected $fillable = [ 'name', 'username', 'password' ]; protected $hidden = [ //'password', 'remember_token', ]; public $timestamps = false; public function access_token(){ return $this-&gt;hasOne('App\AccessToken'); } } </code></pre> <p>What am I doing wrong?</p> <p><strong>EDIT</strong></p> <pre><code>$user = new User(); $user-&gt;username = "myFreshUsername"; $user-&gt;password = Hash::make('userPwd'); $user-&gt;save(); </code></pre> <p>Thats my user creation. If this helps I didn't launch `php artisan make:auth', may this order be necessary?</p> </div>

选择3个表的语句

<div class="post-text" itemprop="text"> <p>So i have a php program in which i should be able to print the variable</p> <p>table 1<br> dbo.FA_PC(table name)<br> FAID(PK)<br> PCID (FK)<br> UserID(FK) </p> <p>table 2<br> dbo.users(table name)<br> UserID(PK)<br> BranchID(FK)<br> Employeename </p> <p>table 3 dbo.Branch(table name)<br> BranchID(PK)<br> Branchname </p> <pre><code>&lt;?php $faid=$_POST['faid']; ini_set("display_errors","on"); $conn = new COM("ADODB.Connection"); try { $myServer = "WTCPHFILESRV\WTCPHINV"; $myUser = "sa"; $myPass = "P@ssw0rd"; $myDB = "wtcphitinventory"; $connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; $conn-&gt;open($connStr); if (! $conn) { throw new Exception("Could not connect!"); } } catch (Exception $e) { echo "Error (File:): ".$e-&gt;getMessage()."&lt;br&gt;"; } if (!$conn) {exit("Connection Failed: " . $conn);} echo "&lt;center&gt;"; echo "&lt;table border='0' width ='100%' style='margin-left:90px'&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;"; $sql_exp = "select * from dbo.users inner join dbo.FA_PC on dbo.userd.UserID = dbo.FA_PC.UseriD WHERE FAID = $faidf"; $rs = $conn-&gt;Execute($sql_exp); echo "&lt;tr&gt;&lt;td&gt;PC Number:".$rs-&gt;Fields("Employeename")."&lt;/td&gt;"; ?&gt; </code></pre> <p>what i want to do is when FAID is selected is could post the Branchname of the FAID selected</p> </div>

流明:IMAP库搜索日期不起作用

<div class="post-text" itemprop="text"> <p>I am using below library in my composer.json file </p> <pre><code>"php-imap/php-imap": "3.0.*", </code></pre> <p>My code is below,</p> <pre><code>$folder['shortpath']="Inbox"; new \PhpImap\Mailbox('{'.$mdata["server"].":993/imap/ssl}". $folder['shortpath'], $mdata["user"], $mdata["pass"], $dir); $mailsIds = $mailbox-&gt;searchMailbox($mailbox, 'SINCE "01 December 2018"'); echo"&lt;pre&gt;";print_r($mailsIds);die; </code></pre> <p>It gives me empty array instead of value of UIDs</p> <p>I have total 4 emails after 1st december</p> <p>If I am using below code,</p> <pre><code>$mailsIds = $mailbox-&gt;searchMailbox("ALL"); echo"&lt;pre&gt;";print_r($mailsIds);die; </code></pre> <p>then it gives me all emails till date in inbox</p> <p>but date wise seach is not working</p> <hr> <p>if I write below code then it gives error:</p> <pre><code> $mailsIds = $mailbox-&gt;searchMailbox('SINCE 01 December 2018'); </code></pre> <p>ERROR:</p> <pre><code>IMAP method imap_search() failed with error: Unknown search criterion: SINCE 2018-12-06 09:32:32← </code></pre> <hr> <p>I found my solution as below , it is working for me,</p> <p>I have userd </p> <pre><code>mailsIds = $mailbox-&gt;searchMailbox('SINCE "01 December 2018"'); </code></pre> <p>but while open connection pass one more argument for "US-ASCII" </p> <pre><code>new \PhpImap\Mailbox('{'.$mdata["server"].":993/imap/ssl}". $folder['shortpath'], $mdata["user"], $mdata["pass"], $dir, "US-ASCII"); </code></pre> <hr> <p>But my another question is it is gives me list of new messages based on given date, </p> <p>I required all update emails also like new mail, mark as unread, flagged , unflagged etc from given date. How to achive this??</p> <p>Means how to identify new emails and any activity on existing emails till given date</p> </div>

应用程序不适用于WAMP,但它适用于在线服务器

<div class="post-text" itemprop="text"> <p>I made a basic login app using online SQLite database(<a href="http://demo3534535.16mb.com" rel="nofollow">http://demo3534535.16mb.com</a>) It works fine on online server. Now i want to run on local server using WAMP in Gennymotion emulator.</p> <p>What change in code i have to do? My working online code is:</p> <p>dbconnect.php</p> <pre><code>&lt;?php define('HOST','mysql.hostinger.in'); define('USER','u756_userd'); define('PASS','pass345'); define('DB','u754113_demo'); $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect'); </code></pre> <p>MainActivity.java</p> <pre><code> public class MainActivity extends AppCompatActivity implements View.OnClickListener { private static final String REGISTER_URL = "http://192.168.1.102/User/Register.php"; public static final String KEY_USERNAME = "username"; public static final String KEY_PASSWORD = "password"; public static final String KEY_EMAIL = "email"; private EditText editTextUsername; private EditText editTextEmail; private EditText editTextPassword; private Button buttonRegister; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editTextUsername = (EditText) findViewById(R.id.editTextUsername); editTextPassword = (EditText) findViewById(R.id.editTextPassword); editTextEmail= (EditText) findViewById(R.id.editTextEmail); buttonRegister = (Button) findViewById(R.id.buttonRegister); buttonRegister.setOnClickListener(this); } private void registerUser(){ final String username = editTextUsername.getText().toString().trim(); final String password = editTextPassword.getText().toString().trim(); final String email = editTextEmail.getText().toString().trim(); StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL, new Response.Listener&lt;String&gt;() { @Override public void onResponse(String response) { Toast.makeText(MainActivity.this, response, Toast.LENGTH_LONG).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show(); } }){ @Override protected Map&lt;String,String&gt; getParams(){ Map&lt;String,String&gt; params = new HashMap&lt;String, String&gt;(); params.put(KEY_USERNAME,username); params.put(KEY_PASSWORD,password); params.put(KEY_EMAIL, email); return params; } }; RequestQueue requestQueue = Volley.newRequestQueue(this); requestQueue.add(stringRequest); } @Override public void onClick(View v) { if(v == buttonRegister){ registerUser(); } } } </code></pre> <p>db_connect.php</p> <pre><code>&lt;?php define('HOST','localhost'); define('USER',''); define('PASS',''); define('DB','db_demo'); $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect'); </code></pre> <p>Register.php</p> <pre><code>&lt;?php if($_SERVER['REQUEST_METHOD']=='POST'){ $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; require_once('dbConnect.php'); $sql = "INSERT INTO volley (username,password,email) VALUES ('$username','$email','$password')"; if(mysqli_query($con,$sql)){ echo "Successfully Registered"; }else{ echo "Could not register"; } }else{ echo 'error'; } </code></pre> <p>I am using internet via wifi </p> </div>

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

ArrayList源码分析(入门篇)

ArrayList源码分析 前言: 写这篇博客的主要原因是,在我上一次参加千牵科技Java实习生面试时,有被面试官问到ArrayList为什么查找的速度较快,插入和删除的速度较慢?当时我回答得不好,很大的一部分原因是因为我没有阅读过ArrayList源码,虽然最后收到Offer了,但我拒绝了,打算寒假学得再深入些再广泛些,下学期开学后再去投递其他更好的公司。为了更加深入理解ArrayList,也为

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

玩转springboot启动banner定义所得

最近接手了一个springboot项目,不是不熟悉这个框架,启动时打印的信息吸引了我。 这不是我熟悉的常用springboot的打印信息啊,我打开自己的项目: 还真是的,不用默认的感觉也挺高大上的。一时兴起,就去研究了一下源代码,还正是有些收获,稍后我会总结一下。正常情况下做为一个老程序员,是不会对这种小儿科感兴趣的,不就是一个控制台打印嘛。哈哈! 于是出于最初的好奇,研究了项目的源代码。看到

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

你打算用Java 8一辈子都不打算升级到Java 14,真香

我们程序员应该抱着尝鲜、猎奇的心态,否则就容易固步自封,技术停滞不前。

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

立即提问
相关内容推荐