pom.xml:
<!-- mybatisplus依赖--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.1</version> </dependency> <!-- mybatisplus依赖--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.2</version> </dependency> <!-- 注解小工具--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.16</version> </dependency>
PolicyController:
package com.paopao.controller; import com.paopao.domain.Policy; import com.paopao.domain.Text; import com.paopao.service.PolicyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.websocket.server.PathParam; import java.util.List; @RestController @RequestMapping("/policy") public class PolicyController { @Autowired private PolicyService policyService; @GetMapping public List<Policy> SelectAll(){ System.out.println("11111"); List<Policy> list=policyService.SelectAll(); return list; } @PostMapping public List<Policy> GetType(@RequestBody Policy policy){ List<Policy> list=policyService.GetType(policy); return list; } @GetMapping("/{name}") public String GetText(@PathVariable String name){ System.out.println(name+"1111111111111111111111"); String text= policyService.GetText(name); System.out.println(text); return text; } }
TextDao:
package com.paopao.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.paopao.domain.Text; import org.apache.ibatis.annotations.Mapper; @Mapper public interface TextDao extends BaseMapper<Text> { }
Policy:
package com.paopao.domain; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor @TableName("policy") public class Policy { private String name; private String organ; @TableField(value = "pubdata") private String date; private String type; }
Text:
package com.paopao.domain; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor @TableName("policy") public class Text { @TableField(value = "text") private String text; private String name; }
PolicyService:
package com.paopao.service; import com.baomidou.mybatisplus.extension.service.IService; import com.paopao.domain.Policy; import com.paopao.domain.Text; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Transactional public interface PolicyService extends IService<Policy> { List<Policy> SelectAll(); List<Policy> GetType(Policy policy); String GetText(String name); }
PolicyServiceImpl:
package com.paopao.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.paopao.dao.PolicyDao; import com.paopao.dao.TextDao; import com.paopao.domain.Policy; import com.paopao.domain.Text; import com.paopao.service.PolicyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; @Service public class PolicyServiceImpl extends ServiceImpl<PolicyDao,Policy> implements PolicyService { @Autowired private PolicyDao policyDao; @Autowired private TextDao textDao; @Override public List<Policy> SelectAll() { List<Policy> list=policyDao.selectList(null); return list; } @Override public List<Policy> GetType(Policy policy) { LambdaQueryWrapper<Policy> lam=new LambdaQueryWrapper<Policy>(); lam.eq(!policy.getName().equals(""),Policy::getName,policy.getName());//中间那个是数据库里面的name lam.like(!policy.getType().equals(""),Policy::getType,policy.getType()); lam.like(!policy.getOrgan().equals(""),Policy::getOrgan,policy.getOrgan()); List<Policy> list=policyDao.selectList(lam); return list; } @Override public String GetText(String name) { Text text=new Text(); // Policy policy=new Policy(); text.setName(name); LambdaQueryWrapper<Text> lam=new LambdaQueryWrapper<Text>(); lam.eq(Text::getName,text.getName()); text=textDao.selectOne(lam); return text.getText(); } }
main.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>科技政策管理系统</title> <script src="js/axios.min.js"></script> <script src="js/vue.js"></script> <!-- 引入样式 --> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> <!-- 引入组件库 --> <script src="https://unpkg.com/element-ui/lib/index.js"></script> </head> <style> /*<!-- 表单 -->*/ .el-table .warning-row { background: oldlace; } .el-table .success-row { background: #f0f9eb; } </style> <body> <div id="main"> <!-- 输入框--> <el-form :inline="true" :model="formInline" class="demo-form-inline"> <el-form-item label="政策名称"> <el-input v-model="formInline.name" placeholder="请输入政策名称"></el-input> </el-form-item> <el-form-item label="发文机构"> <el-input v-model="formInline.oragan" placeholder="请输入审批人"></el-input> </el-form-item> <el-form-item label="类型"> <el-input v-model="formInline.type" placeholder="请输入类型"></el-input> </el-form-item> <el-form-item> <el-button type="primary" @click="onSubmit">查询</el-button> </el-form-item> </el-form> <!--表单--> <template> <el-table :data="tableData" style="width: 100%" :row-class-name="tableRowClassName" > <el-table-column prop="name" label="政策名称" align:right> </el-table-column> <el-table-column prop="organ" label="发文机构" align:center> </el-table-column> <el-table-column prop="type" align:center label="政策类型"> </el-table-column> <el-table-column prop="date" align:center label="发文时间"> </el-table-column> <el-table-column align:center label="操作"> <template slot-scope="scope"> <el-button type="primary" round @click="SelectText(scope.row)">查询</el-button> </template> </el-table-column> </el-table> </template> </div> <script> new Vue({ el: "#main", methods: {//函数方法 tableRowClassName({row, rowIndex}) {//表单函数 if (rowIndex === 1) { return 'warning-row'; } else if (rowIndex === 3) { return 'success-row'; } return ''; }, SelectAll() { axios.get("/policy").then((res) => { this.tableData = res.data }) }, onSubmit() { // console.log(this.formInline) axios.post("/policy", this.formInline).then((res) => { this.tableData = res.data }) }, SelectText(row){ // alert(row.name) var name=row.name axios.get("/policy/"+name).then((res)=>{ this.text=res.data alert(this.text) this.$alert('<body>'+this.text+'</body>',name , { dangerouslyUseHTMLString: true }); }) }, }, created() { // this.SelectAll() }, data() {//数据源 return { tableData: [], formInline: { name: '', type: '', organ:'' }, text:'' } }, mounted() {//初始化 // alert("加载完成") this.SelectAll() } }) </script> </body> </html>
application.yml(这个是要把文件类型改成yml才可以使用的)
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/canteen?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: root password: 123456 type: com.alibaba.druid.pool.DruidDataSource #关闭日志 main: banner-mode: off logging: level: root: warn server: port: 80 # 去除启动时的日志 mybatis-plus: global-config: banner: false # 开启sql语句的日志 # configuration: # map-underscore-to-camel-case: true # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl mapper
标签:name,text,paopao,查询,科技,Springbood,policy,import,com From: https://www.cnblogs.com/1774323810com/p/16856524.html