ការទាញយកពត៌មានទិន្នន័យ ពីវេបផេក (Scraping Data) គឺជាការពន្លាទិន្នន័យមួយចំនួន ភាគច្រើន Text ដើម្បីច្រោះទិន្នន័យទាំងនោះចេញពី html អោយក្លាយជាទិន្នន័យមួយដែលយើងអាចប្រើប្រាស់បាន។ វីដេអូ ខាងក្រោម នេះនិងបង្ហាញពីការប្រើប្រាស់ភាសា PHP ជាមួយ Library សាមញ្ញមួយ មានតែពីរ វីដេអូប៉ុណ្ណោះ នឹងចេះហើយ។
៙តម្រូវការ
- Spring 3.2.8.RELEASE
- Spring Security 3.2.3.RELEASE
- JSTL 1.2
- JDK 1.7
- Tomcat 8.x
- STS 3.7.0
៙រចនាសម្ពន្ធ័ធ្វើរួចរាល់
៙pom.xml
<properties> <org.springframework-version>3.2.8.RELEASE</org.springframework-version> <spring.security.version>3.2.3.RELEASE</spring.security.version> <jstl.version>1.2</jstl.version> </properties>] <dependencies> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${org.springframework-version}</version> </dependency> <!-- Spring Security --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>${spring.security.version}</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>${spring.security.version}</version> </dependency> <!-- jstl for jsp page --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> </dependencies>
៙web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <!-- Creates the Spring Container shared by all Servlets and Filters --> <!-- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> --> <!-- ContextLoader no here in SecurityInit class was load --> <!-- Processes application requests --> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
៙SecurityConfig.java|package com.heng.config
package com.heng.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter{ @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().withUser("vary").password("123456").roles("USER"); auth.inMemoryAuthentication().withUser("admin").password("123456").roles("ADMIN"); auth.inMemoryAuthentication().withUser("dba").password("123456").roles("DBA"); } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_DBA')") .antMatchers("/dba/**").access("hasRole('ROLE_DBA')") .and().formLogin(); http.csrf().disable(); } }
@EnableWebSecurity
annotation និង extends ពីClassWebSecurityConfigurerAdapter
ជួយអោយយើង ទាមទារនូវការកំនត់សិទ្ធ។- Enable Http Basic និង Form login
- Spring Security និងផ្តល់នូវ URL login និង logout page free សម្រាប់អ្នក។
- URL (/admin/) អាចចូលបាន លុះត្រាតែមាន សិទ្ធជា ADMIN ឬ DBA។
៙SecurityInit.java|package com.heng.config
package com.heng.config; import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; public class SecurityInit extends AbstractSecurityWebApplicationInitializer{ public SecurityInit() { super(SecurityConfig.class); } //Load ContextLoaderListener && springSecurityFilterChain }
៙HomeController.java|package com.heng.samplesecurity.controller
package com.heng.samplesecurity.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; /** * @author Heng-Cyber */ @Controller public class HomeController { @RequestMapping(value = { "/", "/welcome**" }, method = RequestMethod.GET) public ModelAndView welcomePage() { ModelAndView model = new ModelAndView(); model.addObject("title", "Spring Security Hello World"); model.addObject("message", "This is welcome page!"); model.setViewName("home"); return model; } @RequestMapping(value = "/admin**", method = RequestMethod.GET) public ModelAndView adminPage() { ModelAndView model = new ModelAndView(); model.addObject("title", "Spring Security Hello World"); model.addObject("message", "This is protected page - Admin Page!"); model.setViewName("admin"); return model; } @RequestMapping(value = "/dba**", method = RequestMethod.GET) public ModelAndView dbaPage() { ModelAndView model = new ModelAndView(); model.addObject("title", "Spring Security Hello World"); model.addObject("message", "This is protected page - Database Page!"); model.setViewName("admin"); return model; } }
៙Screen Shot
ប្រភព៖ spring.io
ទាញយក Source Code:
ទីនេះ
Spring Security Access Role តាមរយៈ Annotation
11:01 PM
mydoc, spring-doc
៙ របៀបបង្កើត ភាសាដើម្បីដំណើរការ Function
[postgresql language plpgsql does not exist]
[postgresql language plpgsql does not exist]
+ PostgreSQL:
CREATE LANGUAGE plpgsql;
៙ របៀបបង្កើត ID random មិនជាន់គ្នា
[make unique random id in postgresql]
[make unique random id in postgresql]
+ PostgreSQL:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";យើងអាចប្រើវាបានដោយហៅ uuid_generate_v1() ហើយ field របស់យើងត្រូវមាន datatype ជា uuid
៙ របៀបបង្កើត Function ដែល insert ហើយ return record អំបាញ់មិញ
[insert into 2 differ table and return current record]
[insert into 2 differ table and return current record]
+ PostgreSQL:
CREATE OR REPLACE FUNCTION insert2tables(tcher_name VARCHAR,stu_name VARCHAR stu_program VARCHAR) RETURNS void AS $$ DECLARE last_id uuid; BEGIN --Return with data column[tcher_id] back by generate id by uuid_gernerate_v1() INSERT INTO tb_teacher VALUES(uuid_generate_v1(),$1) RETURNING tcher_id INTO last_id; --get that id then insert to other table INSERT INTO tb_program VALUES(uuid_generate_v1(),$2,$3,CAST(last_id AS UUID)); END; $$ LANGUAGE 'plpgsql'+ Source:ទីនេះ
៙ របៀបប្តូរ row ពី column
[how to convert row to columns in postgresql]
[how to convert row to columns in postgresql]
+ PostgreSQL:
ឧទា៖ ខ្ញុំមាន table ឈ្មោះ tb_fee_types ដែលមានទិន្នន័យ
ខ្ញុំចង់ប្តូរ row [TERM,SEM,YEAR] ទៅជា column
ឧទា៖ ខ្ញុំមាន table ឈ្មោះ tb_fee_types ដែលមានទិន្នន័យ
ខ្ញុំចង់ប្តូរ row [TERM,SEM,YEAR] ទៅជា column
SELECT DISTINCT(f.fee_type_id), tm.price_fee AS term, y.price_fee AS "year", sem.price_fee AS semester FROM tb_fee_types AS f, (SELECT * FROM tb_fee_types WHERE type_fee='TERM') AS tm, (SELECT * FROM tb_fee_types WHERE type_fee='YEAR') AS y, (SELECT * FROM tb_fee_types WHERE type_fee='SEMESTER') AS sem ORDER BY fee_type_id ASC;+ Source:ទីនេះ
ឯកសារស្រាវជ្រាវខ្លីៗអំពី SQL ភាគ១
9:58 PM
mydoc, postgresql-doc
Subscribe to:
Posts (Atom)