Skip to content

Commit

Permalink
🎨开始重构
Browse files Browse the repository at this point in the history
  • Loading branch information
mewhz committed May 8, 2022
1 parent 172db1d commit 6493e67
Show file tree
Hide file tree
Showing 27 changed files with 391 additions and 543 deletions.
16 changes: 7 additions & 9 deletions pastecode-system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,21 @@
</dependency>

<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.17</version>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
<scope>runtime</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.8</version>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author mewhz
*/
@SpringBootApplication
public class PasteCodeApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mewhz.paste.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
* @author mewhz
*/
@Configuration
public class CorsConfig {

private static final long MAX_AGE = 26 * 60 * 60;

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

CorsConfiguration corsConfiguration = new CorsConfiguration();

corsConfiguration.addAllowedOriginPattern("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setMaxAge(MAX_AGE);

source.registerCorsConfiguration("/**", corsConfiguration);

return new CorsFilter(source);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mewhz.paste.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author mewhz
*/
@Configuration
@MapperScan("com.mewhz.paste.mapper")
public class MyBatisPlusConfig {

@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,40 @@
package com.mewhz.paste.controller;


import cn.hutool.db.Entity;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.mewhz.paste.utils.CodeSQL;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.mewhz.paste.model.Code;
import com.mewhz.paste.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author mewhz
*/
@RestController
@RequestMapping("/code")
public class CodeController {

@RequestMapping("/code")
public ModelAndView code(@RequestParam String id){
ModelAndView mav = new ModelAndView("/code.html");
return mav;
}

@RequestMapping("/selectCode")
public JSONObject selectCode(@RequestParam String id){
@Autowired
private CodeService codeService;

JSONObject json = JSONUtil.createObj();
String type = null;
String text = null;
String remark = null;

CodeSQL codesql = new CodeSQL();
List<Entity> list = codesql.findCode(id);
@GetMapping("/")
public List<Code> findAll(){
return codeService.list();
}

type = (String) list.get(0).get("type");
text = (String) list.get(0).get("text");
remark = (String) list.get(0).get("remark");
@PostMapping("/")
public Map<String, Object> save(@RequestBody Code code){
Map<String, Object> result = new HashMap<>();
codeService.save(code);

json.append("text", text);
json.append("type", type);
json.append("remark", remark);
System.out.println(code);

return json;
result.put("status", 200);
result.put("msg", "success");
result.put("codeId", code.getCodeId());
return result;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mewhz.paste.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mewhz.paste.model.Code;

/**
* @author mewhz
*/
public interface CodeMapper extends BaseMapper<Code> {
}
Loading

0 comments on commit 6493e67

Please sign in to comment.